To localize your frontend app you have to follow the steps below:

  1. Prepare you frontend editing the configurations vars in frontend-app/config/frontend.ini.php file
    • $config['frontendLang'] with the default language (i.e. 'eng')
      $config['frontendLang'] = 'eng';
    • $config['frontendLangs'] with an array of supported languages, for example
      $config['frontendLangs'] = array(
          'ita' => 'italiano',
          'eng' => 'english'
    • Eventually edit the config var $config['frontendLangsMap'] according to your needs to add or remove maps of languages to autodetecting language choice
      $config['frontendLangsMap'] = array(
      	'it' => 'ita',
      	'en' => 'eng',
      	'en_us' => 'eng',
      	'en-us' => 'eng',
      	'en_gb' => 'eng'
      where the key is the language comes from HTTP client request and the related value is the language you have defined in $config['frontendLangs']
    • Choose a name for the cookie where the language will be wrote on (always in frontend.ini.php)
      $config["cookieName"] = array(
      	"langSelect" => "basicExampleLang"
  2. translate your contents from BEdita backend through out the Translations module;
  3. use the Smarty tag {t}text to translate{/t} and/or the CakePHP method __('text to translate', true) to write all the static parts of your frontend;
  4. translate these static parts. Read 'How to Create BEdita translations' and apply it to your frontend. You have to use the locale frontend folder to put the .po files and launch the shell script
    ./ gettext update -frontend path/to/your/frontend
    to update .po files with the strings to translate;
  5. if some static translations you have wrote in .po files doesn't appear you should cleanup the cached file with
    ./ bedita cleanup -frontend path/to/your/frontend

Now your frontend app is ready to be browsed in different languages.

When a visitor comes to your frontend app the system tries to autodetect the language choice through $config['frontendLangsMap'].
If autodetecting fails, the default language defined in $config['frontendLang'] is used. The language is wrote in session and a cookie with the language used is automatically set, so if a user returns to visit your frontend he starts to navigate with the language of his last visit. The cookie name can be found and edited in $config["cookieName"]["langSelect"] variable in frontend.ini.php as indicated in the above point 3.

Change language on the fly

You can change the frontend language from a language to another, for example from english to italian, simply with:

The language will be set to italian and the client will be redirected to the referred, so if you have loaded the page and you write in the address bar the language will be changed to italian and the will be reloaded.

Instead to change language and redirect to a specific section (or content) with nickname my-nickname you could write in the address bar

and so on for all the other languages.

The view

At this point you could add an element to switch language in the view of your frontend app. In the view you'll have the current language in the $currLang variable while $conf is an object that contains all the configuration variables. Therefore a simple example of Smarty view can be:

{foreach from=$conf->frontendLangs key="lang" item="label"}
	{if $currLang == $lang}
		{$label} | 
		< a href="{$html->url('/lang/')}{$lang}" >{$label}< /a > |