Jump to:

23000 Posts in 11854 Topics by 2828 members

General Questions

SilverStripe Forums » General Questions » [SOLVED] How to add another cast to $Locale

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: 447 Views
  • Josua
    Avatar
    Community Member
    86 Posts

    [SOLVED] How to add another cast to $Locale Link to this post

    Hi!

    As $Locale.Nice, I need another cast, $Locale.NiceShort

    How to add another cast to $Locale for template?

    Thanks.

    Regards,
    Jose A.

  • martimiz
    Avatar
    Forum Moderator
    1038 Posts

    Re: [SOLVED] How to add another cast to $Locale Link to this post

    I don't think you can easily extend DBLocale for this, since it is used by Translatable directly. .So maybe the easiest way is to create a function in the page controler, that manipulates the locale? Then call that from the template...

  • Josua
    Avatar
    Community Member
    86 Posts

    Re: [SOLVED] How to add another cast to $Locale Link to this post

    Hi martimiz!

    I've been able to find the solution.
    SilverStripe is wonderful. It's a pity that he lacks a better documentation.
    I put it here in case someone needs it.

    class DBLocaleExtension extends Extension {
    function NiceShort() {
    return i18n::get_language_name(i18n::get_lang_from_locale($this->owner->value));
       }
    }

    In _config.php:

    Object::add_extension('DBLocale', 'DBLocaleExtension');

    Regards,
    Jose A.

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