Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions

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

Help with the _t function


3 Posts   1381 Views


18 December 2009 at 11:30am Community Member, 202 Posts

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 :-)


18 December 2009 at 12:01pm Community Member, 323 Posts


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

Hope it helps,


18 December 2009 at 1:13pm (Last edited: 18 December 2009 1:46pm), Community Member, 202 Posts

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')) {