Jump to:

22976 Posts in 11702 Topics by 2826 members

General Questions

SilverStripe Forums » General Questions » Help with the _t function

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: 1291 Views
  • yurigoul
    Avatar
    Community Member
    202 Posts

    Help with the _t function Link to this post

    Can someone please explain to me how I have to use the _t function in my templates with php and with js?

    I have translatable and i18n turned on in my config and everything seems ok (login page is German and I can create translations)

    In sapphire/lang/de_DE.php it says: $lang['de_DE']['SearchForm']['SEARCH'] = 'Suche';
    In sapphire/lang/en_US.php it says: $lang['de_DE']['SearchForm']['SEARCH'] = 'Search';

    I use _t('SEARCHFORM.SEARCH') in my page.php to set the text of the searchbutton, but the searchbutton gets no text (and there is no error).

    i18n.js loads de_DE and en_US language files, and the translation for SEARCHFORM.SEARCH is in those files. However, if I use <% _t('SEARCHFORM.SEARCH') %> the result is again empty.

    I have looked everywhere in wiki and forum and book, but I can not find anything, so it must be something fairly obvious that I am missing

  • Juanitou
    Avatar
    Community Member
    322 Posts

    Re: Help with the _t function Link to this post

    Hi!

    Well, SearchForm and SEARCHFORM are two different strings, aren’t they?

    Hope it helps,
    Juan

  • yurigoul
    Avatar
    Community Member
    202 Posts

    Re: Help with the _t function Link to this post

    Ok both now work, I feel a bit stupid

    I thought one would go over the js and one not, but they both go over the php

    Alas they are now somehow both in german... I will look into it

    EDIT: it worked completely as soon as I reinserted the code below into the page_controller->init even though it changes the language of the login form (part is in german, the other part is in english):

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

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