How to organize views for different languages


how should i organize my views for many languages?




I want to load the views dynamically, dependend on the language. Could it be a problem if i have 2 files with the same name (only in different folders). Perhaps there is a better way to do that?

Either would work and I guess it comes down to preference. No it wouldn't be a problem to have the same file name in different folders.

$lang = 'es'; //I imagine you have a similar variable defined somewhere
$this->load->view($lang .'/my_view');//load the view for this controller from it's language dir

$lang = 'es_';
$this->load->view($lang . 'my_view');

If every single page on your whole site will have this language convention, it might be better to extend the Loader class (MY_Loader) and override the view method with your own to automatically append your language to the beginning of the filename (or directory) so you don't have to manually set it everywhere. Or create an additional method specifically for loading language views so you can still use the original, if needed.

I'd probably DEFINE the language somewhere. Then in the loader, check to see if it's defined. If not, you can use some default language. If it is it will just use it.

Hi CroNiX,

thank you for your great help. I'm relative new to CI. Modifying the view-method is a really good tip. i didn't use it until now.

Sure thing. I modified my response a bit to mention possibly creating an additional method instead of overriding the original, just in case you need the original.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.