Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » need basic multilangual content help

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: 2053 Views
  • sybalos
    Avatar
    Community Member
    4 Posts

    need basic multilangual content help Link to this post

    Hi all,

    This a basic question on multilangual content with SS. I have a used car website to manage. There is a list of car model with picture, description and some other infos. The translation work fine in the cms. But what if i want to translate some static field title without the cms admin. For example: The value of a Kilometer field is handle buy the cms, but i want to translate the title "Kilometer" without the cms. Sorry for my bad english and hope i made myself clear.
    thx.

  • Matt
    Avatar
    Core Development Team
    84 Posts

    Re: need basic multilangual content help Link to this post

    This is what I do:

    <?php
       /**
        * Returns the current language
        * Should either be the string 'en' or 'es'
        */
       function CurrentLang() {
          return Translatable::current_lang();
       }
    ?>

    That will return the current two-letter language code (en, es, fr, jp, de etc).

    You can also just call current_lang in the templates, but that's a little slower.

    So you would use it like this in the templates: <% if CurrentLang = en %>something<% end_if %>

    Also, if you want it to be in multiple languages, this might be better:

    <% _t(STRING, Some string here) %>


    Then you can define "STRING" in the $lang arrays inside the lang/ directory of your project, just like the _t() calls all throughout the rest of sapphire. Take a look at some of the templates in sapphire/templates to see how that's done.

    Hope that helps!

  • Digital-Punk.co.uk
    Avatar
    Community Member
    51 Posts

    Re: need basic multilangual content help Link to this post

    I'm confused

    I try to make strings translatable but it doesn't work for me.. Translations in CMS works, translation in template with CurrentLang works but when I put the string, from lang array comes translation only for 1 language and other labguages shows default text from string.

    In config I have this:

    i18n::enable();
    i18n::set_locale('lt_LT');
    i18n::set_default_lang('lt');
    HTTP::set_cache_age(0);

    In page:

    function CurrentLang() {
    return Translatable::current_lang();
    }

    Currently in template I have this:

    <% if CurrentLang = lt %>tralialia<% end_if %>


    But I want to have this:

    <% _t('STRING' , 'tralialia') %>

    I created catalog 'lang' in 'mysite' and created files for lang array in different languages.

    Where can be my mistake?

  • Ingo
    Avatar
    Forum Moderator
    801 Posts

    Re: need basic multilangual content help Link to this post

    So, the <% _t() %> call is not resolved by the template parser? Or does it show the default language string instead of the translation?
    Did you use the textcollector to create your /lang files? Not 100% necessary, but can help to avoid mistakes. See http://doc.silverstripe.com/doku.php?id=i18n&s=textcollector

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