Warning: this tutorial and library are out of date. Prefer the last version, more robust.
views/about.php
<h2> <?= $this->lang->line('who'); ?> </h2>
language/about_lang.xml
<text id="who"> <en>Who</en> <fr>Qui</fr> </text>
MY_Language.php and MyController.php in librariesurl_helper.php in helpersconfig/autoload.php: $autoload['libraries'] = array('MyController');config/config.php, make sure $config['base_url'] corresponds to your configuration.config/routes.php add:$route['^fr/(.+)$'] = "$1"; $route['^en/(.+)$'] = "$1"; $route['^fr$'] = $route['default_controller']; $route['^en$'] = $route['default_controller'];
controllers/about.php
<?php class About extends Controller { function index() { // load language file $this->lang->load('about'); $this->load->view('about'); } } ?>
language/about_lang.xml
<?xml version="1.0" encoding="UTF-8"?> <data> <text id="about_me"> <en>I'm just a man</en> <fr>Je ne suis qu'un homme</fr> </text> </data>
views/about.php
<p><?= $this->lang->line('about_me'); ?></p>
Check it's working:
If it's not, try this: CodeIgniter 1.6.1 + i18n library (You may need to set RewriteBase in the .htaccess to make the URL rewriting work).
routes.php: ignore language in URL when looking for the controllerMyController.php: check language in URLcontrollers/about.php: load localized strings for current languageviews/about.php: display localized string
Note: if your root URL / is requested:
default_controller using language from visitor's browser.default_controller using language from previous visit (from visitor's cookie).
Note: anchor(“about”, “test”) generates a link to /en/about (if the current language is English).
Example: German (de)
config/routes.php add:$route['^de/(.+)$'] = "$1"; $route['^de$'] = $route['default_controller'];
MY_Language.php add to $supportedLanguages:"de" => "de", "de-at" => "de", "de-ch" => "de", "de-de" => "de"
<text id="who"> <en>Who</en> <fr>Qui</fr> <de>Wer</de> </text>
That's it!
Editing long XML files is not fun. To help you, I've written XMLLocalizationEditor for Mac OS X (source included).
Example:
XML code generated: