Jump to:

3392 Posts in 976 Topics by 852 members

Template Questions

SilverStripe Forums » Template Questions » one.com and i18n

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

Page: 1
Go to End
Author Topic: 583 Views
  • dacar
    Avatar
    Community Member
    168 Posts

    one.com and i18n Link to this post

    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?

  • dacar
    Avatar
    Community Member
    168 Posts

    Re: one.com and i18n Link to this post

    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?

  • dacar
    Avatar
    Community Member
    168 Posts

    Re: one.com and i18n Link to this post

    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'

  • dacar
    Avatar
    Community Member
    168 Posts

    Re: one.com and i18n Link to this post

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

  • BigMoose
    Avatar
    Community Member
    19 Posts

    Re: one.com and i18n Link to this post

    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.

  • BigMoose
    Avatar
    Community Member
    19 Posts

    Re: one.com and i18n Link to this post

    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.

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