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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Form Questions /

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

How to translate Enum-based dropdowns


Go to End


2 Posts   2682 Views

Avatar
javelin

Community Member, 12 Posts

9 June 2010 at 7:53am

Edited: 09/06/2010 7:56am

I've found that keeping a site multilingual is quite easy with Silverstripe except for a few parts.

Recently I ran into trouble with some forms that are automatically generated by getFrontEndFields() (used extensively in this project).

Some Dropdowns are generated from enum-type db-fields and they display the hardcoded strings from my datamodel. I didn't find an easy way to translate these so I resorted to hacking the core. I inserted the following function into Enum.php and redirected a call in the enumValues-function inside Enum.php.

I hope that maybe someone can make use of this or, even better, maybe that someone has a better way to implement this without hacking core. I'm no programmer so this was created out of necessity.

This then requires a line in a lang-file formatted something like:
$lang['sv_SE']['Enum-ApartmentCategory']['LÄGENHET'] = 'Lägenhet';

function translateArray($array) {
		foreach ($array as $key => $value) {
			$array[$key] = _t('Enum-'.$this->name.".".mb_strtoupper($key), $value);
		}
		return $array;
	}

Avatar
sebastiankozub

Community Member, 59 Posts

24 September 2015 at 1:42am

Here is a little bit old but quite clean and easy solution.
For newest version of SS you will need to change it a little bit,
but general way looks OK:
http://www.balbuss.com/translating-an-enum-dropdown/