Documentations

Translation

There are currently three translation axes possible in Voila, translation in controllers, translation in views with twig, and translation of urls. To facilitate all this, a script has been created to automate the search for texts to translate and generate the corresponding files.

Translation in controllers

To translate a string in the controller, simply call the translation function already included in the controller.

$this->translate("Hello world")

Translation in views

To translate a string in a view, simply call the translation function already included in twig.

{{ translate('Hello world') }}

Generate translation files

Before you want to translate your site, you need to "add" the languages ​​in the configuration file (/config/config.php) and add the locale you want to support (here the 'fr')

define('TRANSLATE', true);
define('DEFAULT_LANG', 'en');
define('LANGS', ['en', 'fr']);

Then you need to generate the translation files, to do this, you need to run the following command in the terminal

$ php bin/tranlate.php

And if you want to generate a specific locale, you can pass it as a parameter (here for the 'fr' locale)

$ php bin/tranlate.php fr

Once the files are generated, you can translate the texts in the files in the translation folder (in "/translation/").

translation files are json files (JavaScript Object Notation), it is an array that is transformed into a string that can therefore be placed in a file. As in an associative array, the key is the value to translate, if it does not find a translation, voila will return the key it received, therefore, you should not modify the keys (on the left), but the values ​​associated with them (on the right).

Translation of urls

To translate the urls, you need to generate the translation files (see above), in the translation folder, there should be a routeLO.json file (with LO replaced by the locale). As for the other files, you can replace the data in the table with your translations (on the left, what needs to be translated, so do not touch, on the right what will be rendered in the locale, to be translated)

As this is a table transformed into a string, some characters must be "disabled" with the '\' sign, notably the '\/' sign. For example, the Route "/Error" in French will be written as "\/Error" in the translation file.

"\/Error": "\/fr\/Error",

The translation must not modify the first parameter which represents the locale, so you must only translate what is behind it. Of course, these are URLs, so they must not contain any special characters, spaces, or accents.

"\/Error": "\/fr\/Erreur",