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, biapar, Willr, Ingo, swaiba, simon_w

Language file not picked up


Reply


4 Posts   454 Views

Avatar
Sygmoral

Community Member, 29 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?

Avatar
martimiz

Forum Moderator, 1132 Posts

19 April 2014 at 10:49pm

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

Avatar
Sygmoral

Community Member, 29 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
   'en_US',
   'es_ES',
   'ru_RU',
   'ar_EG'
));


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():

i18n::set_locale(Translatable::get_current_locale());

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

Avatar
Sygmoral

Community Member, 29 Posts

20 April 2014 at 4:10am

Edited: 20/04/2014 4:11am

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

https://github.com/silverstripe/silverstripe-translatable/blob/master/docs/en/index.md#setting-the-i18n-locale