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.

We've moved the forum!

Please use for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Template Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba and i18n

Go to End

7 Posts   5060 Views


Community Member, 173 Posts

24 April 2013 at 6:45am

Edited: 24/04/2013 6:38pm


has anybody had trouble with SS3.05, and i18n? I can not get it working.

global $allowed_i18n;
$allowed_i18n = array(
'dk' => "da_DK",
'en' => "en_US",
'de' => "de_DE"

i18n::$common_locales = array(
'da_DK' => array('Danish', 'Danish'),
'en_US' => array('English (US)', 'English (US)'),
'de_DE' => array('German', 'Deutsch')
Translatable::set_allowed_locales(array('de_DE', 'da_DK', 'en_US'));
Object::add_extension('SiteTree', 'Translatable');
Object::add_extension('SiteConfig', 'Translatable');


public function init() {

if($this->dataRecord->hasExtension('Translatable')) {


global $lang;
// translated fields
$lang['de_DE']['']['HOME'] = 'Start';
$lang['de_DE']['']['ABOUT'] = '&Uuml;ber uns';
$lang['de_DE']['']['SERVICES'] = 'Service';
$lang['de_DE']['']['WORKS'] = 'Unsere Arbeit';
$lang['de_DE']['']['CONTACT'] = 'Kontakt';
$lang['de_DE']['']['TRANSLATABLEFIELD'] = 'Translatable field translation';

$lang['de_DE']['']['MORE'] = 'mehr';
$lang['de_DE']['']['PREV'] = 'zurück';
$lang['de_DE']['']['NEXT'] = 'weiter';
$lang['de_DE']['']['EXPERTISE'] = 'Unsere Expertise';
$lang['de_DE']['']['ALL'] = 'Alle Kategorien';
$lang['de_DE']['']['CONTACTFORM'] = 'Kontakt';
$lang['de_DE']['']['NAME'] = 'Name';
$lang['de_DE']['']['EMAIL'] = 'Email';
$lang['de_DE']['']['MESSAGE'] = 'Nachricht';
$lang['de_DE']['']['SENDAMESSAGE'] = 'Absenden';

$lang['de_DE']['']['SHOWINPAGE'] = 'Zeige Seiten auf deutsch.';
$lang['de_DE']['Page']['SHOWINPAGE'] = 'Zeige Seiten auf deutsch.';
$lang['de_DE']['SHOWINPAGE'] = 'Zeige Seiten auf deutsch.';

$lang['de_DE']['Page']['SERVICES'] = 'Service';
$lang['de_DE']['Top']['SERVICES'] = 'Service';


<% _t('','Services') %> OR
<% _t('Page.SERVICES','Services') %> OR
<% _t('SERVICES','Services') %>

The t-function will not be translated???

But <% sprintf(_t('SHOWINPAGE','Show page in %s'),$Locale.Nice) %> Is translated to "Show page in german".

Can anybody help?


Community Member, 173 Posts

24 April 2013 at 6:27pm

i have just put an echo to the init function to show the current locale:

if($this->dataRecord->hasExtension('Translatable')) {
echo i18n::get_locale();

At this point everything works fine. Why does Silverstripe not find my translation files?


Community Member, 173 Posts

24 April 2013 at 6:36pm

de.yml doesn't work, too:

    HOME: 'Start'
    ABOUT: '&Uuml;ber uns'
    SERVICES: 'Service'
    WORKS: 'Unsere Arbeit'
    CONTACT: 'Kontakt'
    MORE: 'mehr'
    PREV: 'zurück'
    NEXT: 'weiter'
    EXPERTISE: 'Unsere Expertise'
    ALL: 'Alle Kategorien'
    CONTACTFORM: 'Kontakt'
    NAME: 'Name'
    EMAIL: 'Email'
    MESSAGE: 'Nachricht'
    SENDAMESSAGE: 'Absenden'


Community Member, 173 Posts

24 April 2013 at 6:46pm


Sorry for spamming you. I haven' read the docs carefully. on it says:
$entity: Unique identifier, composed by a namespace and an entity name, with a dot separating them. Both are arbitrary names, although by convention we use the name of the containing class or template. Use this identifier to reference the same translation elsewhere in your code.

It has to be: <% _t('Page.HOME','Home') %>


Community Member, 19 Posts

11 April 2014 at 7:32am

Hi dacar,
I am struggling with this myself. I used translatable with SS 2.x, but am trying to get things to work in SS3 with the add-on module.

I get your solution within the template was to use <% _t('Page.HOME','Home') %>. However, what sort of file did you use to hold the actual translation? Did you use the mysite/lang/de_DE.php to hold this information, or did you use de.yml?

If you used de_DE.php, how did you structure it?
$lang['de_DE']['']['HOME'] = 'Start'; OR
$lang['de_DE']['Page']['HOME'] = 'Start';

or something completely different?

I have been trying various things but cannot get my translations to work.


Community Member, 19 Posts

11 April 2014 at 8:38am

Ok, I got this solved for myself here.

I have a template for a contact page called
In my template file I have something like this:

<p><%t ContactPage.EMAIL "Email:" %></p>
<p><%t ContactPage.PHONE "Phone:" %> 555-555-5555</p>
<p><%t ContactPage.TOLL_FREE "Toll Free:" %>1-800-555-5555</p>
<p><%t ContactPage.FAX "Fax:" %>333-333-3333</p>

I have been making translations in french, and so I have created a file: mysite/lang/fr.yml

The code in this file looks like:

    EMAIL: 'Courriel:'
    PHONE: 'T&eacute;l&eacute;phone:'
    TOLL_FREE: 'Sans frais:'
    FAX: 'T&eacute;l&eacute;copieur:'

I had problems at first because I did not indent things in the Yaml file. I needed to use the 2 spaces indent or else it would not work.


Community Member, 5 Posts

9 September 2016 at 10:11pm

Edited: 09/09/2016 11:01pm


I had same problem with 3.4 version of Silverstripe: all translations added via php/js work like a charm (using module), but theme folder translations are not taken for some reason.
I solved my problem so, that after running the i18n-task, moved all the created translations FROM file inside the theme/<your-template>/lang/ folder to mysite/lang/<corresponding-file> folder (at the end of the file there) and removed lang folder from theme folder entirely.

Hope that helps somebody in the future :)