Jump to:

22976 Posts in 11702 Topics by 2826 members

General Questions

SilverStripe Forums » General Questions » Where to store the multilanguage content?

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: 1087 Views
  • pepperoni
    Avatar
    Community Member
    1 Post

    Where to store the multilanguage content? Link to this post

    Hi,

    my website uses multilingual content and for sure I have to translate my templates also. Example:

    mymodule/templates/BigPage1.ss

    <h1><% _t("TITLE1","This is the BigPage1.ss") %></h1>
    <p><% include SmallPage %></p>

    mymodule/templates/BigPage2.ss

    <h1><% _t("TITLE2","This is the BigPage2.ss") %></h1>
    <p><% include SmallPage %></p>

    mymodule/includes/SmallPage.ss

    <% _t("SAMPLE","Just a sample text.") %>

    So, where to store the content now? Should I save the "en_US.php" in mymodule/lang/ or in mysite/lang/. What about contents in /themes/mytheme/ ? This is my first question, because I don't really get it, that you have to store the translated data in mysite/lang, when you translate your themes!? Ain't it?

    Well, let's go to my second question: After finding where to store my translated pieces I should now how to save them. I've read that you always have to address the highest template, else the variable is not found. As far as I know the following code will not work

    $lang['en_US']['SmallPage.ss']['SAMPLE'] = "The translated text";
    $lang['en_US']['BigPage1.ss']['TITLE1'] = "Title of BigPage1";
    $lang['en_US']['BigPage2.ss']['TITLE2'] = "Title of BigPage2";


    at least for the including of the small page because you should use BigPage.ss instead. To make my example work I need the following, dont I?

    $lang['en_US']['BigPage1.ss']['SAMPLE'] = "The translated text";
    $lang['en_US']['BigPage2.ss']['SAMPLE'] = "The translated text";
    $lang['en_US']['BigPage1.ss']['TITLE1'] = "Title of BigPage1";
    $lang['en_US']['BigPage2.ss']['TITLE2'] = "Title of BigPage2";


    are there any regulations to follow? I'd appreciate a link or an explanation to where the template content is searched by silverstripe. oh man, I wrote so much, I hope anybody answers...

    Greetings
    pepperoni

  • dalesaurus
    Avatar
    Community Member
    283 Posts

    Re: Where to store the multilanguage content? Link to this post

    Well I have read it but I am a bit daunted by your undertaking. This is some pretty advanced i18n work you're up to, this forum probably isn't the best place to get your hands dirty.

    If you have a change try to catch one of the core team on IRC. Mentioning i18n issues always gets people excited!

  • Fuzz10
    Avatar
    Community Member
    786 Posts

    Re: Where to store the multilanguage content? Link to this post

    >This is some pretty advanced i18n work you're up to, this forum probably isn't
    >the best place to get your hands dirty.

    Advanced ? I disagree, this is a pretty basic question that pops up for everyone doing multi-lingual sites.

    To be honest , I've always created my own IF -> THEN construction for translating template-content , because I wasn't sure about the LANG files construction. So I'm interested in the answer too.. ;)

  • Willr
    Avatar
    Forum Moderator
    5462 Posts

    Re: Where to store the multilanguage content? Link to this post

    I'm pretty sure the i18n TextCollector is designed to work with mysite/ folders. Noot too sure on themes, as they do have a slightly different setup but Perhaps try running

    http://<mysite>/dev/tasks/i18nTextCollectorTask/?module=mysite

    And see if that generates the lang folder in mysite with the translation templates.

    For your individual modules you would just replace mysite with your module name.

  • banal
    Avatar
    Community Member
    901 Posts

    Re: Where to store the multilanguage content? Link to this post

    Hi pepperoni

    Your translated file looks fine. Instead of using the template file as "namespace" you could also use an arbitrary string, like this:

    $lang['en_US']['MySite']['SAMPLE'] = 'Sample US';

    Then access it in the template like this:

    <% _t('MySite.SAMPLE', 'Dummy') %>

    This is useful, when you're using the same translation in multiple templates.

    Your code should work the way it is now.. if it doesn't check the following:
    - Did you enable i18n in the _config.php file? You have to call i18n::enable(); there.
    - Do you set the current locale? You can hard-code it in your _config.php using: i18n::set_locale('xx_XX');.
    - If you want the i18n locale set depending on the current "Translatable" language, put the following in your Page_Controller class:

    public function init(){
       parent::init();
       
       if($this->dataRecord->hasExtension('Translatable')) {
          i18n::set_locale($this->dataRecord->Locale);
       }
    }

    Above code is taken from: http://doc.silverstripe.org/doku.php?id=multilingualcontent#setting_the_i18n_locale
    Something like: i18n::set_locale(Translatable::get_current_locale()); would work as well.

    HTH

    Update Sorry, forgot to add: Yes, you would place your lang file in mysite/lang/

  • dalesaurus
    Avatar
    Community Member
    283 Posts

    Re: Where to store the multilanguage content? Link to this post

    Advanced ? I disagree, this is a pretty basic question that pops up for everyone doing multi-lingual sites.

    Ok, how about the honest answer: I am an uneducated rube when it comes to SS and i18n, and also a stupid American who generally assumes everyone speaks English. I will be of no use to the OP but I'd at least like to make the effort to let them know someone has read it.

    Better fuzz?

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