Welcome Guest, Not a member yet? Register   Sign In
Web site with 2 Languages
#1

[eluser]invision[/eluser]
Hi,

I've followed this brilliant Wiki guide on using Multiple Languages with CodeIgniter and can now visit www.site.com/en/ and www.site.com/es/ and get the same page loading. Brilliant Smile

However, I now have some questions which I'd loooove to get an answer for.

1) How do I load a different navigation bar (a simple <div></div>) based on the current language (en/es/etc...) ? So it would load different language nav bar depending on the language the user chooses.

and

2) How do I retrieve different data (different columns) from my database based on the current language?
Would this require just loading a different set of methods from my Model/Controller?


Many thanks for any guidance with this.
#2

[eluser]umefarooq[/eluser]
you have to check which one is active language user has selected then you have to get data from database according to that language. database which i have design for one of my project is like this

Code:
database columns
name_en
name_es
desc_en
desc_es

a little tweak in MY_lang trough which can check which one is active lang in your controllers

Code:
before cunstractor

public $active_lang;

after line number 38 put this

$this->active_lang = $lang_abbr;

in controllers or models you can check active lang

$lang = $this->lang->active_lang

  $name = 'name_'.$lang;
  $desc = 'desc_'.$lang;

$rows = $this->db->get("table_name")->result();
foreach($rows as $row){
echo  $row->$name;
echo  $row->$desc;
}
#3

[eluser]invision[/eluser]
Wow. Thanks for the detailed reply.

I'm away from my computer right now but will try this as soon as I get home.

Stay tuned Smile
#4

[eluser]invision[/eluser]
Ignore the previous message here Smile

When I put the following into my Controller:
Code:
$lang = $this->lang->active_lang;
and then output $lang in the View it gives $lang the same value as my Controller name. So if my Controller is called 'Football', $lang becomes football.

I'm guessing that's not right.


Do I have to declare a particular 'segment' to choose from as it's currently choosing the controller name.


Here's a snippet of MY_language for reference just in case I've made a mistake.
Code:
...
class MY_Language extends CI_Language
{                    

public $active_lang;

    function MY_Language() {
        
        global $RTR;
        
        $index_page    = $RTR->config->item('index_page');
        $lang_uri_abbr = $RTR->config->item('lang_uri_abbr');
        
        /* get the lang_abbr from uri segments */
        $lang_abbr = current($RTR->uri->segments);
        $this->active_lang = $lang_abbr;
...


Many thanks for your help.
#5

[eluser]umefarooq[/eluser]
which version of CI you are using i have tried this library with CI2.0 i have face one problem with this library that your segment 1 should be en or es but it always getting controller name. if you are using

Code:
$this->uri->segment(1);

you are using this library with CI 1.7 let me try in that let see.
#6

[eluser]invision[/eluser]
Many thanks for the speedy reply.

I'm a bit stupid. I actually commented out the language part of my config file which meant it wouldn't pick up the 'en' part. D'oh Big Grin


Thanks again for all your help. I'll be back if I need any more Smile
#7

[eluser]mariuskmc[/eluser]
I have a problem with implementation of Multiple Languages with CodeIgniter
I followed all the instructions and modifications, and I'm stuck

I have the following situation

In config
Code:
$config['language'] = 'romana';

//default language abbreviation
$config['language_abbr'] = 'ro';

//set available language abbreviations
$config['lang_uri_abbr'] = array('en' => 'english', 'ro' => 'romana');

//ignore this language abbreviation
$config['lang_ignore'] = 'xx';  

//language descriptions
$config['lang_desc']=array('ro'=>'Versiune Romana',
                           'en' => 'English version');  

//language use images
$config['lang_useimg'] = TRUE; //or false to use only text

In route
Code:
//route example: http://domain.tld/en/controller => http://domain.tld/controller
$route['(\w{2})/(.*)'] = '$2';
$route['(\w{2})'] = $route['default_controller'];

if i set $config['lang_ignore'] = 'xx' to $config['lang_ignore'] = 'ro'

i will have only English link with this link
http://localhost/site/encontroller

if I let $config['lang_ignore'] = 'xx'

i will have both links but with this link
http://localhost/site/roro/contreller/function
http://localhost/site/enro/contreller/function


where I'm wrong?

Thanks

And another question
How much affect my urisegments, because now I have
http://localhost/site/controller/function/variable
and will be transformed like
http://localhost/site/en/controller/function/variable

Thanks again Smile
#8

[eluser]mariuskmc[/eluser]
I found the solution by changing AUTO to PATH_INFO in $config['uri_protocol']

I still have problems with pagination... because don't work

how can I make it work?




Theme © iAndrew 2016 - Forum software by © MyBB