Jump to:

10931 Posts in 2614 Topics by 1810 members

All other Modules

SilverStripe Forums » All other Modules » Language file not picked up

Discuss all other Modules here.

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

Page: 1
Go to End
Author Topic: 275 Views
  • Sygmoral
    Avatar
    Community Member
    23 Posts

    Language file not picked up Link to this post

    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?

  • martimiz
    Avatar
    Forum Moderator
    1068 Posts

    Re: Language file not picked up Link to this post

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

  • Sygmoral
    Avatar
    Community Member
    23 Posts

    Re: Language file not picked up Link to this post

    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?

  • Sygmoral
    Avatar
    Community Member
    23 Posts

    Re: Language file not picked up Link to this post

    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

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