Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Archive

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, biapar, Willr, Ingo, simon_w

template in 2 language


Reply

7 Posts   3289 Views

Avatar
Webbear

26 May 2008 at 6:07pm Community Member, 5 Posts

first, I love SS and I also like the i18n!
Now, I'm getting into troubles because I have to build a template for two language (german and french). On my testinstallation I can switch between languages quite easily using the same alias (url) and linking it with ?lang=de or ?lang=fr. Also the meta tag 'content' is changing correctly. But I'd like to switch also some 'default' links like 'print this page' or even the sitetitle in a h1 and those thing I wrote in the template (and want to let it there). I tried the _t function. The language file is correctly created in folder lang in mysite by /i18n/textcollector/.
But there is no switch of the lang file.
I might have missed an important fact in the config file:

i18n::enable();
i18n::set_locale('de_CH');
i18n::set_default_lang('de');

Can anbody help me with this? Thanks a lot
Webbear

Avatar
cliersch

26 May 2008 at 11:46pm Community Member, 75 Posts

Do you want to use 2 different SS-Installations?
If you want to switch a template between two languages you have to change the set_local parameters in the _config.php.
To switch between German an French:
i18n::set_locale('de_DE');
setlocale (LC_ALL, 'de_DE@euro', 'de_DE', 'de', 'ge');
//i18n::set_locale('fr_FR');
//setlocale (LC_ALL, 'fr_FR@euro', 'fr_FR', 'fr', 'fr');

Avatar
Webbear

27 May 2008 at 9:45am Community Member, 5 Posts

thanks tiga
but sorry, this didn't work out. Don't want to have to ss installation for two languages.
I want one installation, one template with translations of i.e. contact ->Kontakt or drucken -> imprimer.

Avatar
Webbear

29 May 2008 at 12:45am Community Member, 5 Posts

After trying more with i18n and ss I see better how ss works.
The problem I have is not setting the locale (and getting the right lang file) but 'changing' the local setting by url (?lang=fr) to get the right language file.

Avatar
lekoala

29 May 2008 at 1:50am Community Member, 30 Posts

I had the same trouble... what I did was adding in the init of page.php this bit of code :

      /*set locale */
      $curLang=Session::get('currentLang');
      switch($curLang) {
      case "fr":
      i18n::set_locale('fr_FR');;
         break;
      case "en":
      i18n::set_locale('en_US');
         break;   
      }
      /*end of set locale*/

thus, when you set your language with ?lang=en for instance, it will update the locale accordingly... this is only working if you use one locale per language, obviously...

Avatar
Webbear

29 May 2008 at 4:53am Community Member, 5 Posts

Thanks lekoala
coming closer! Where exactly you put this lines in page.php ? And what did you write in _config.php? (It's quite hot those days in Switzerland, brain's getting very slow...)

Avatar
lekoala

29 May 2008 at 7:34pm Community Member, 30 Posts

no worries... here it comes :

class Page_Controller extends ContentController {
   function init() {
      parent::init();
      
      /*set locale */
      $curLang=Session::get('currentLang');
      switch($curLang) {
      case "fr":
      i18n::set_locale('fr_FR');;
         break;
      case "nl":
      i18n::set_locale('nl_NL');
         break;
      case "en":
      i18n::set_locale('en_US');
         break;   
      }
      /*end of set locale*/
      Requirements::themedCSS("layout");
      Requirements::themedCSS("typography");
      Requirements::themedCSS("form");
   }

By the way, I'm not sure that's the best (and recommended) way to deal with locales, but... it works. so...

in _config.php, you just have to make sure that i18n is enabled.

//enable multi lingual support
i18n::enable();

then you can run the textcollector and translate everything... as a side note, here is a sample line of code for translating a template

// in mysite/lang/en_US.php
$lang['en_US']['ActivityPage.ss']['MUST_BE_REGISTERED'] = 'You must be registered to join this event';