Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » template in 2 language

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

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

Page: 1
Go to End
Author Topic: 3236 Views
  • Webbear
    Avatar
    Community Member
    5 Posts

    template in 2 language Link to this post

    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

  • cliersch
    Avatar
    Community Member
    75 Posts

    Re: template in 2 language Link to this post

    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');

  • Webbear
    Avatar
    Community Member
    5 Posts

    Re: template in 2 language Link to this post

    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.

  • Webbear
    Avatar
    Community Member
    5 Posts

    Re: template in 2 language Link to this post

    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.

  • lekoala
    Avatar
    Community Member
    30 Posts

    Re: template in 2 language Link to this post

    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...

  • Webbear
    Avatar
    Community Member
    5 Posts

    Re: template in 2 language Link to this post

    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...)

  • lekoala
    Avatar
    Community Member
    30 Posts

    Re: template in 2 language Link to this post

    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';

    3236 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.