Locales - graphidev/WOK GitHub Wiki

Locales are the easiest way to translate generic elements as buttons and other static navigation elements.

Generate locale files

Don't worry, it pretty quick to use. First of all, you need to create a properties file as following :

group.element1=value
group.element2=value
...
group.elementN=value
group.subgroup.element1=value
group.subgroup.element2=value
....

The Locales class will generate a JSON file each time it will not find it.

These files must be placed in /locales/%s by default, where %s is the desired language folder.

Get locales values

All you need to know is the locales as you defined in the properties files in . Then you juste give it as parameter of the Locales::_e() method

Locales::_e('locale:group.element');

'locale' correspond to the properties filename

Predefined formats

Datas

I hope you'll be happy to know that you can insert in the locale value thanks to formats. In that way, you juste have to give a second parameter (as array) in the previous functions, like this :

_e('locale:group.element', array('key'=>'value'));

In the properties files, the array key must be defined as

group.item=this is a locale with a :key

Which will give you : This is a locale with a value

Do you got it ? Right ! Go ahead !

Dates and times

You may need to parse datetimes in the visitor formats. In that way, you can use the date format :

[:index|format]

The given data (:index) must be formated as a valid PHP format and "format" correspond to the output format

Money

In the same way, you can define a money format : either according to the visitor money format ...

group.element={:money} please !

.. or a custom money format :

group.element={:money|%i} please !

Other

Locales also integrate some quick predefined formats that you can define with :

(:index|formats)

and where formats correspond to one of the following (separate them with a comma) :

  • trim : remove white spaces before and after
  • uppercase or lowercase : really need explanations ?
  • reverse : reverse the caracters order
  • an integer (1234) which will correspond to the max words to print.

Best for the end : As a PHP developper you should love variables. That's why we decided to allow you to make a reference to an other locale in a locale. Let's see :

group.myfirstlocale=John Doe
group.mysecondlocale=Have you seen &[group.myfirstlocale] ?

Which will give you : Have you seen John Doe ?

Awesome, right ?!