Welcome Guest, Not a member yet? Register   Sign In
multi language practice
#5

The main thing to remember if you don't want to have to pass the current language to every call to load a language file is to set the language before you load any language files:

PHP Code:
$this->config->set_item('language'$current_language); 

Then you can get the individual language lines in your controller and pass them to your view, or echo them directly from your view:

PHP Code:
// Controller:
$data['line1'] = $this->lang->line('lang_line_1');
$this->load->view('home'$data);

// View:
?><a href=''><?php echo $line1?></a> 

PHP Code:
<a href=''><?php echo $this->lang->line('lang_line_1'); ?></a> 

Or you can load the language helper and use the lang() function:
PHP Code:
<a href=''><?php echo lang('lang_line_1'); ?></a> 

I often use the lang() function from the language helper in my views when I am feeling too lazy to setup variables to pass the language lines from my controller to my view, or when the view might be shared by multiple controllers and I don't want to create a method in my base controller (or a library) to get all of the language lines and pass them through.
Reply


Messages In This Thread
multi language practice - by rchiu5hk - 09-15-2015, 03:51 AM
RE: multi language practice - by PaulD - 09-15-2015, 03:05 PM
RE: multi language practice - by rchiu5hk - 09-15-2015, 10:33 PM
RE: multi language practice - by PaulD - 09-16-2015, 07:26 AM
RE: multi language practice - by mwhitney - 09-16-2015, 10:09 AM



Theme © iAndrew 2016 - Forum software by © MyBB