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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Locale/i18n for dummies


Go to End


5 Posts   3253 Views

Avatar
dendeffe

Community Member, 135 Posts

19 August 2009 at 10:28pm

I’m trying to use locale translations for the first time, but I seem to be missing a few things.

This is what i’m doing:

• I add this to cms/_config.php

i18n::enable();
i18n::set_default_lang('nl');

• I add a folder called lang in mysite. Inside this folder I add a file called nl_NL.php
• In this file I add:

<?php

global $lang;

$lang['nl_NL']['Page']['TEST'] = 'Test';

?>

• In the template (Page.ss) I add

<% _t('TEST') %>

Avatar
dalesaurus

Community Member, 283 Posts

20 August 2009 at 2:33am

SS looks for the current user's locale first, failing that it falls back on the site default. I'll bet the user you're logged in as was created when your site was set to en_US as the default. Ensure your user account's language is set to nl_NL or try logging out and viewing your site.

Avatar
dendeffe

Community Member, 135 Posts

20 August 2009 at 4:12am

Thanks dalesaurus.

That didn’t solve the problem though. I also tried the suggestions here http://www.silverstripe.org/general-questions/show/267122?showPost=267153 as that question seems realy similar.

Is there extra documentation besides http://doc.silverstripe.com/doku.php?id=i18n with more examples/tutorials,…?

Avatar
dalesaurus

Community Member, 283 Posts

20 August 2009 at 7:47am

Hmm, I'm at a loss then. The New Zealanders should be coming online soon, I'm sure one of them will be able to assist.

The wiki is the sole source of documentation at this time (aside from sifting through the code yourself). When you get this sorted out please be sure to update it or let me know and I'll be happy to do it.

Avatar
dendeffe

Community Member, 135 Posts

1 September 2009 at 6:14am

Ok, this is what I was doing wrong:

1/ It seems you need to use the following formatting.

In the template:

<% _t('Page.TEST') %>

In the language file

$lang['nl_NL']['Page']['TEST'] = 'Test';

You can’t exclude the 'page' part. It doesn't have to be 'page', but you can't use:

$lang['nl_NL']['TEST'] = 'Test';

2/ Tou need this in your Page_Controller

class Page_Controller extends ContentController {
	
public function init() {
	parent::init();

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

Both things I found a bit difficult to get from the documentation. Hope other people having problems with it find this useful.