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.

General Questions /

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

[SOLVED] How to add another cast to $Locale


Reply


3 Posts   565 Views

Avatar
Josua

Community Member, 86 Posts

27 February 2012 at 8:27pm

Hi!

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

How to add another cast to $Locale for template?

Thanks.

Regards,
Jose A.

Avatar
martimiz

Forum Moderator, 1132 Posts

29 February 2012 at 4:51am

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

Avatar
Josua

Community Member, 86 Posts

29 February 2012 at 6:11am

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.