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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

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

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

[SOLVED] How to add another cast to $Locale


Go to End


3 Posts   896 Views

Avatar
Josua

Community Member, 87 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, 1391 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, 87 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.