method for multi language without session your opinion |
[eluser]axmed[/eluser]
i wanted to make multi language site that could cache the pages in the language selected, using session would only save one copy of that page in the last language selected(cause one controller for all languages), i did not want to lose caching, so i read about using routes and using a controller for every language thanks to n0xie, since i will be needing to write all urls in the config/routes.php i choose to do it instead in the language files.here is the example code tell me if this is a good way to do this, will it cause problems if its done in this way. i used the Template Library from williamsconcepts so here goes the English controllers will be Quote:http://test/homeand the Arabic Quote: http://test/arabic/home Code: <?php now the Gui_model its job is to load the region into the master template and to parse the data according to the language selected. Code: <?php here is an example of a language files this one is the Arabic the English one is the same but the uri_* dont have "arabic/" to them and the text is in English ![]() Code: $lang['host'] = "اختبار"; now for the view files i used the tags for the languages ex: {home} and for regions i used <?= $content ?> the regions are placed in the master template.the anchors on the view pages i used <?=base_url()."{uri_home}";?> here is an example of a region i used for the main bar. the browser will not show the code below so here is representation X1: <?=base_url()."{uri_home}";?> X2: <?=base_url()."{uri_games}";?> X3: <?=base_url()."{uri_movies}";?> X4: <?=base_url()."{uri_forum}";?> Code: <div id="top_menu"> the controllers are named the same for Arabic i use home.php and is placed in controllers/arabic/ and the English home.php in controllers/ . so to keep track of the current pages and when the page is translated the selected controller will load in the selected language i used for the language anchors this code its placed in the header region.its 2 images representing the lang.thanks to theprodigy. the browser will not show the code below so here is representation x1:<?= base_url().'arabic/'.$this->router->class; ?> x2:<?= base_url().$this->router->class; ?> Code: <div id="lang"> now i can cache the pages in the languages the user has selected i keep the uri's in the language files instead of the route and have a controller for every language. what do you think is this a good way to do this,now i dont have to worry about user cookies enabled and cashing helps speed the pages with less cpu utilization, i dont know about search engine indexing. but is this a good way to do it. i hope you can make since of it all regards |
Welcome Guest, Not a member yet? Register Sign In |