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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

All other Modules /

Discuss all other Modules here.

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

The _t() function problem


Go to End


5 Posts   1792 Views

Avatar
gordon

Community Member, 2 Posts

13 February 2010 at 2:34am

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

Avatar
Juanitou

Community Member, 323 Posts

13 February 2010 at 6:08am

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

Avatar
yurigoul

Community Member, 203 Posts

14 February 2010 at 4:29am

Edited: 14/02/2010 4:29am

Shouldn't it be:

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

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

Avatar
Juanitou

Community Member, 323 Posts

14 February 2010 at 5:54am

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

Avatar
gordon

Community Member, 2 Posts

15 February 2010 at 10:16pm

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!