Jump to:

1970 Posts in 1275 Topics by 607 members

Form Questions

SilverStripe Forums » Form Questions » How to translate Enum-based dropdowns

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

Page: 1
Go to End
Author Topic: 1093 Views
  • javelin
    Avatar
    Community Member
    12 Posts

    How to translate Enum-based dropdowns Link to this post

    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;
       }

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