Jump to:

3443 Posts in 1030 Topics by 871 members

Template Questions

SilverStripe Forums » Template Questions » [SOLVED] Problem with translations _t() returns always same language

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

Page: 1
Go to End
Author Topic: 1445 Views
  • Dreadmaaan
    Avatar
    Community Member
    3 Posts

    [SOLVED] Problem with translations _t() returns always same language Link to this post

    Hey there,

    I have an annoying problem using the _t() function in my templates. I'm trying to translate the search result template and for that matter I created two languagefiles in the mysite/lang folder, de_DE.php and en_US.php . But the template only displays the german texts, no matter which language I choose. You can try it out for yourself @ http://sng.cotec-it-systeme.de/

    en_US.php

    global $lang;

    $lang['en_US']['Page_results']['NoResults'] = 'Sorry, your search query did not return any results';
    $lang['en_US']['Page_results']['MoreAbout'] = 'more about';
    $lang['en_US']['Page_results']['NextPage'] = 'Next page';
    $lang['en_US']['Page_results']['PrevPage'] = 'Previous page';
    $lang['en_US']['Page_results']['GoToPage'] = 'Go to page';
    $lang['en_US']['SearchForm']['SearchResults'] = 'Search results';

    de_DE.php

    i18n::include_locale_file('sleepNgo', 'en_US');

    global $lang;

    if(array_key_exists('de_DE', $lang) && is_array($lang['de_DE'])) {
       $lang['de_DE'] = array_merge($lang['en_US'], $lang['de_DE']);
    } else {
       $lang['de_DE'] = $lang['en_US'];
    }

    $lang['de_DE']['Page_results']['NoResults'] = '2Zu Ihrer Suche gibt es leider keine Ergebnisse.';
    $lang['de_DE']['Page_results']['MoreAbout'] = '2Mehr zu';
    $lang['de_DE']['Page_results']['NextPage'] = '2Nächste Seite';
    $lang['de_DE']['Page_results']['PrevPage'] = '2Vorherige Seite';
    $lang['de_DE']['Page_results']['GoToPage'] = '2Gehe zu Seite';
    $lang['de_DE']['SearchForm']['SearchResults'] = '2Suchergebnisse';

    _config.php (snippet)

    i18n::set_locale('de_DE');
    Translatable::set_default_locale('de_DE');
    Translatable::set_allowed_locales(array(
    'de_DE',
    'en_US',
    )
    );
    Object::add_extension('SiteTree', 'Translatable');
    Object::add_extension('SiteConfig', 'Translatable');

    Page_results.ss (snippet)

    <a class="readMoreLink" href="$Link" title="<% _t('Page_results.MoreAbout','1Mehr zu') %> &quot;{$Title}&quot;">
    <% _t('Page_results.MoreAbout','1Mehr zu') %> &quot;{$Title}&quot;...
    </a>

    What am I doing wrong?

    greetings
    Martin

  • MarcusDalgren
    Avatar
    Community Member
    288 Posts

    Re: [SOLVED] Problem with translations _t() returns always same language Link to this post

    If you're doing direct template translation then it needs to be Page_results.ss not just Page_results. Also leave out the domain so it says just MoreAbout instead of Page_results.MoreAbout since the _t() function in the template automatically gets its name as the namespace.

    So <% _t('MoreAbout','1Mehr zu') %> will become $lang['en_US']['Page_results.ss']['MoreAbout']

  • Dreadmaaan
    Avatar
    Community Member
    3 Posts

    Re: [SOLVED] Problem with translations _t() returns always same language Link to this post

    Sadly, this doesn't work either. Again, only the german texts from de_DE.php are being displayed.

    If I remove (or rename) the de_DE.php file, the fallback text of the _f() function in the template shows up, no matter which language is currently active. I don't get it, it seems like the english translations aren't even being read.

    Any ideas?

  • mv
    Avatar
    Community Member
    5 Posts
  • Dreadmaaan
    Avatar
    Community Member
    3 Posts

    Re: [SOLVED] Problem with translations _t() returns always same language Link to this post

    That worked. Thank you so much!

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