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 forum.silverstripe.org 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

one.com and i18n


Go to End


7 Posts   5213 Views

Avatar
dacar

Community Member, 173 Posts

24 April 2013 at 6:45am

Edited: 24/04/2013 6:38pm

Hi,

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

mysite/_config.php:
i18n::set_locale('da_DK');
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_default_locale('da_DK');
Translatable::set_allowed_locales(array('de_DE', 'da_DK', 'en_US'));
Object::add_extension('SiteTree', 'Translatable');
Object::add_extension('SiteConfig', 'Translatable');

mysite/code/page.php

...
public function init() {
parent::init();

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

mysite/lang/de_DE.php

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

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

$lang['de_DE']['Page.ss']['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';
?>

themes/project/templates/page.ss:

<% _t('Page.ss.SERVICES','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?

Avatar
dacar

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')) {
i18n::set_locale($this->dataRecord->Locale);
//i18n::set_locale(Translatable::get_current_locale());
//i18n::set_locale('de_DE');
echo i18n::get_locale();
}

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

Avatar
dacar

Community Member, 173 Posts

24 April 2013 at 6:36pm

de.yml doesn't work, too:

de:
  Page:
    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'

Avatar
dacar

Community Member, 173 Posts

24 April 2013 at 6:46pm

SOLVED!!!

Sorry for spamming you. I haven' read the docs carefully. on http://doc.silverstripe.org/framework/en/topics/i18n 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') %>

Avatar
BigMoose

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 Page.ss 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']['Page.ss']['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.

Avatar
BigMoose

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 ContactPage.ss
In my ContactPage.ss template file I have something like this:

<p><%t ContactPage.EMAIL "Email:" %> info@whatever.com</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:

fr:
  ContactPage:
    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.

Avatar
-lohe-

Community Member, 5 Posts

9 September 2016 at 10:11pm

Edited: 09/09/2016 11:01pm

Hei,

I had same problem with 3.4 version of Silverstripe: all translations added via php/js work like a charm (using https://github.com/silverstripe/silverstripe-translatable 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 :)