Jump to:

23481 Posts in 18965 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » Multilingual support in templates

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: 1245 Views
  • gonace
    Avatar
    Community Member
    11 Posts

    Multilingual support in templates Link to this post

    Im trying to do some multilingual support but can't get i to work, I've added this in my sv_SE.php language file:

    $lang['sv_SE']['SplashScreen']['SVENSKA'] = "Svenska";
    $lang['sv_SE']['SplashScreen']['ENGLISH'] = "English";

    And this is my template:

    <div id="SplashScreen" class="hidden">
       <div id="SplashContent">
          <div id="SplashLanguages">
             <a onclick=""><% _t('SplashScreen.SVENSKA', 'Swedish') %></a>
             <a onclick=""><% _t('SplashScreen.ENGLISH', 'English') %></a>
          </div>
       </div>
    </div>

    But all that I can see is the fallback "Swedish" and "English"

  • Martin Pales
    Avatar
    Community Member
    19 Posts

    Re: Multilingual support in templates Link to this post

    Your sv_SE.php language file should contain template filename. Like this:

    $lang['sv_SE']['SplashScreen.ss']['SVENSKA'] = "Svenska";
    $lang['sv_SE']['SplashScreen.ss']['ENGLISH'] = "English";

    Without .ss it only works in your SplashScreen.php (class/controller file).

    Harl

  • gonace
    Avatar
    Community Member
    11 Posts

    Re: Multilingual support in templates Link to this post

    Tried to add .ss to SplashScreen, but still the only thing that shows is the fallback string!

  • martimiz
    Avatar
    Forum Moderator
    1086 Posts

    Re: Multilingual support in templates Link to this post

    The preferred way is to just leave out the namespace bit in templates, to keep it readable, and add:

    <a onclick=""><% _t('SVENSKA', 'Swedish') %></a>
    <a onclick=""><% _t('ENGLISH', 'English') %></a>


    Now, if you template name were to be mytemplate.ss, you can add this to your language file and SilverStripe should find it:

    $lang['sv_SE']['mytemplate.ss']['SVENSKA'] = "Svenska";
    $lang['sv_SE']['mytemplate.ss']['ENGLISH'] = "English";

    Just in case: it still might not work if your template is included in some other template. In that case you could use the enveloping template's namespace. So supposing a template sometemplate.ss has a <% include mytemplate %>, add this to your languagefile:

    $lang['sv_SE']['sometemplate.ss']['SVENSKA'] = "Svenska";
    $lang['sv_SE']['sometemplate.ss']['ENGLISH'] = "English";


    Hope it helps,
    Martine

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