Jump to:

22997 Posts in 11853 Topics by 2828 members

General Questions

SilverStripe Forums » General Questions » Translatable: Return only Language

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

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

Page: 1
Go to End
Author Topic: 655 Views
  • JuLo
    Avatar
    Community Member
    37 Posts

    Translatable: Return only Language Link to this post

    Hi,

    I feel very silly because I feel I've achieved much more complicated things than that in my few days of learning Silverstripe, but I can't figure out how to return only the Language of the Locale.
    For example, if the language is en_US, I want to display EN.

    Does something already exists, like the .Nice format or the .RFC1766 format. (and where do I find a list of these existing formats)?

    Or do I have to a php function in the Page_Controller?
    (A bit of help with that too, if that's what I have to do, will be much appreciated too)

    Thanks,

    Julien

  • ChrisBryer
    Avatar
    Community Member
    95 Posts

    Re: Translatable: Return only Language Link to this post

    I think there is an array in sapphire/core/i18n.php called $common_locales that you can use as a lookup table to translate your locale to the name of the language. if that doesnt work, there are a few other arrays in i18n that may help.

    i think this might work (not tested)

    i18n::$common_locales[Translatable::get_current_locale()][0]
    or
    i18n::$common_locales['en_US'][0]

    -Chris

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