Jump to:

10994 Posts in 2728 Topics by 1819 members

All other Modules

SilverStripe Forums » All other Modules » The _t() function problem

Discuss all other Modules here.

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

Page: 1
Go to End
Author Topic: 1416 Views
  • gordon
    Avatar
    Community Member
    2 Posts

    The _t() function problem Link to this post

    Hi everyone,

    I've got some problem with using _t() function in my multilanguage site.

    In my template i put:

    <% _t('DESIGN', 'some text') %>

    I have 2 lang files under mysite/lang folder: en_US.php and pl_PL.php where I enter:

    $lang['en_US']['Page.ss']['DESIGN'] = 'some text';

    - for en_US.php

    and

    $lang['pl_PL']['Page.ss']['DESIGN'] = 'polish text';

    - for pl_PL.php

    Whatever language I choose in my site it always give me back 'polish text'. Its seems to work ok, but it never wants to load english text (unless I delete pl_PL.php).

    In my _config.php I have:

    i18n::enable();
    Translatable::set_default_locale('pl_PL');
    Object::add_extension('SiteTree', 'Translatable');

    I dont have a clue what is wrong... General content translations done in CMS admin work fine.
    Any help I will be grateful.

    Regards,
    Gordon

  • Juanitou
    Avatar
    Community Member
    323 Posts

    Re: The _t() function problem Link to this post

    Hi Gordon!

    In my _config.php I have some other lines:

    // Define allowed locales overriding those present in i18n::$common_locales
    global $allowed_locales;
    $allowed_locales = array(
          'fr_FR' => array('French', 'fran&ccedil;ais'),
          'en_GB' => array('English', 'English'),
          'es_ES' => array('Spanish', 'espa&ntilde;ol')
       );
    i18n::$common_locales = $allowed_locales;

    // Define defaults
    i18n::set_locale('fr_FR');
    setlocale(LC_ALL, 'fr_FR.UTF8', 'fr_FR', 'fr-FR', 'french'); // Needed for dates

    Also, you need to set your locale in the init() function of your Page_Controller with some code implementing i18n::set_locale(). Do you have it? (see here).

    Hope it helps,
    Juan

  • yurigoul
    Avatar
    Community Member
    202 Posts

    Re: The _t() function problem Link to this post

    Shouldn't it be:

    <% _t('Page.ss.DESIGN', 'some text') %>

    Or should this work regardless because page.ss is the location?

  • Juanitou
    Avatar
    Community Member
    323 Posts

    Re: The _t() function problem Link to this post

    That’s true! There’s also a bug with included templates: http://open.silverstripe.org/ticket/4915

  • gordon
    Avatar
    Community Member
    2 Posts

    Re: The _t() function problem Link to this post

    Thank you for your responses.

    Juanitou, ,you were right, I didnt set locale in my Page_Controller.
    After adding this in my init() function:

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


    everything is working just fine

    Thanks!

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