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.

All other Modules /

Discuss all other Modules here.

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

Language file not picked up

Go to End

4 Posts   685 Views


Community Member, 34 Posts

19 April 2014 at 11:34am

Edited: 19/04/2014 11:35am

I'm a bit amazed I don't manage to get this to work, but well.

I already have my website translated into Spanish (from English). I'm using the Translatable module for that, works great. es_ES is in Translatable's allowed_locales.

For some specific custom templates, I'm using the _t construct, had the en.yml created for mysite, and then copied that file to es.yml. I changed the first line to read es:, and made the required translations.

I can't seem to figure out how to get the es.yml file to actually load though. It keeps using the value from en.yml (which I changed from the _t() construct, to make sure it actually does read from a language file).

es.yml is of course in the same folder as en.yml. It's the exact same file format with no syntax errors (as far as I can see). The file is also readable etc. I tried renaming it to es_ES.yml, as well as changing that first line to es_ES:. I tried adding es or es_ES to i18n:common_locales in config.yml. I tried removing any non-ansi characters. I did dev/build/, flush=1 and flush=all. Of course, I'm logged in as Administrator, and I uncached the template.

I do see any changes that I make in en.yml, but not those in es.yml, even though I'm on a Spanish page.

I simply don't know what else to try... how to make it load that es.yml file on pages that are Spanish?


Forum Moderator, 1203 Posts

19 April 2014 at 10:49pm

Make sure to do a ?flush=all...


Community Member, 34 Posts

20 April 2014 at 1:39am

Thanks for the suggestion. I have been doing that a lot though! :)

I found what's missing: despite being on a Spanish page (as determined by the Translatable module), SilverStripe does not believe it needs to choose the Spanish language files for the modules. In other words, Translatable's current_language is not synchronized with i18n's current_language.

Perhaps it's a config thing? I currently have in _config.php:

Translatable::set_allowed_locales(array( // available locales

And nothing about i18n, since en_US as default is fine, and I can't see any method to set available locales for i18n. I don't have any other locale/language settings anywhere else.

I can get it to work by putting the following in Page.php's init():


It just seems strange that I need to do this. Did I miss a setting somewhere, or is this simply the way?


Community Member, 34 Posts

20 April 2014 at 4:10am

Edited: 19/02/2015 4:28pm

Well, guess I can answer that myself... yes, i18n's locale needs to be set explicitly, based on Translatable's.

[edit in 2015]
Add this to your Page_Controller's init:

		// sync i18n with Translatable
        if($this->dataRecord->hasExtension('Translatable')) {
			setlocale(LC_ALL, $this->dataRecord->Locale.'.UTF-8');  // if you use php's date() formats etc