Jump to:

23361 Posts in 18124 Topics by 2862 members

General Questions

SilverStripe Forums » General Questions » Locale/i18n for dummies

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Page: 1
Go to End
Author Topic: 2389 Views
  • dendeffe
    Avatar
    Community Member
    135 Posts

    Locale/i18n for dummies Link to this post

    I’m trying to use locale translations for the first time, but I seem to be missing a few things.

    This is what i’m doing:

    • I add this to cms/_config.php

    i18n::enable();
    i18n::set_default_lang('nl');

    • I add a folder called lang in mysite. Inside this folder I add a file called nl_NL.php
    • In this file I add:

    <?php

    global $lang;

    $lang['nl_NL']['Page']['TEST'] = 'Test';

    ?>

    • In the template (Page.ss) I add

    <% _t('TEST') %>

  • dalesaurus
    Avatar
    Community Member
    283 Posts

    Re: Locale/i18n for dummies Link to this post

    SS looks for the current user's locale first, failing that it falls back on the site default. I'll bet the user you're logged in as was created when your site was set to en_US as the default. Ensure your user account's language is set to nl_NL or try logging out and viewing your site.

  • dendeffe
    Avatar
    Community Member
    135 Posts

    Re: Locale/i18n for dummies Link to this post

    Thanks dalesaurus.

    That didn’t solve the problem though. I also tried the suggestions here http://www.silverstripe.org/general-questions/show/267122?showPost=267153 as that question seems realy similar.

    Is there extra documentation besides http://doc.silverstripe.com/doku.php?id=i18n with more examples/tutorials,…?

  • dalesaurus
    Avatar
    Community Member
    283 Posts

    Re: Locale/i18n for dummies Link to this post

    Hmm, I'm at a loss then. The New Zealanders should be coming online soon, I'm sure one of them will be able to assist.

    The wiki is the sole source of documentation at this time (aside from sifting through the code yourself). When you get this sorted out please be sure to update it or let me know and I'll be happy to do it.

  • dendeffe
    Avatar
    Community Member
    135 Posts

    Re: Locale/i18n for dummies Link to this post

    Ok, this is what I was doing wrong:

    1/ It seems you need to use the following formatting.

    In the template:

    <% _t('Page.TEST') %>

    In the language file

    $lang['nl_NL']['Page']['TEST'] = 'Test';

    You can’t exclude the 'page' part. It doesn't have to be 'page', but you can't use:

    $lang['nl_NL']['TEST'] = 'Test';

    2/ Tou need this in your Page_Controller

    class Page_Controller extends ContentController {
       
    public function init() {
       parent::init();

       ...
          if($this->dataRecord->hasExtension('Translatable')) {
           i18n::set_locale($this->dataRecord->Locale);
       }
          
    }

    Both things I found a bit difficult to get from the documentation. Hope other people having problems with it find this useful.

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