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

Dear all,

I am developing multi language website with using PHP and Codeigiter framework.
I just know that controller will have a list of variables from language key. Then these $variables will use in the specified view of specified controller. is it a proper way? as I need to check what $variables needed in view.
If I just set them in the view, then I does not need to assign $variables in controller.
Is it OK??
Reply
#2

I would suggest you set the language in a cookie and read the cookie in the controller to specify the language file to use.
Reply
#3

Actually,

For every php page, there are different variables.
$data["Home"] = $this->lang->line("Home");

Is below code possible when put in php code file??
<a href=""><?php $this->lang->line("Home"); ?> </a>
Reply
#4

Yes, I believe it is but you would have to echo it in the view file.

Not sure what you mean by php code file but you can load langugage keys from language files in the controller so I presume you can do it in the view too.

http://www.codeigniter.com/user_guide/li...guage.html

Or more specifically:

http://www.codeigniter.com/user_guide/li...ne-of-text

Hope that helps,

Best wishes,

Paul.
Reply
#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




Theme © iAndrew 2016 - Forum software by © MyBB