Translate an application ######################## Each application possess the :file:`lang` directory where are located translation files, that will be called **dictionaries**. This directory include as many subdirectories as languages we want to translate the application into. Dictionaries will be define in these subdirectories. These language directories are named following locales, as for example :file:`fr` (French), or :file:`en` (English). .. image:: images/i18n_folder_structure.png Dictionaries are PHP files returning a array, similarly as configuration file. .. seealso:: :ref:`I18n class API ` File :file:`metadata.config.php` ================================ ``metadata`` are a particular case, since they are cached. They need a translation file on their own. First step is to define which dictionaries ``metadata`` need to be translated. .. code-block:: php :emphasize-lines: 6 'My app', 'namespace' => 'My\App', 'i18n_file' => 'my_app::metadata', // ... other keys ); As all change on :file:`metadata`, don't forget to apply changes in the application manager. Next, you need to create the :file:`my_app::lang/fr/metadata.lang.php` dictionary: .. code-block:: php 'My application', ); Novius OS automatically knows which keys has to be translated in the :file:`metadata` file and will get corresponding translations. Other files =========== Elsewhere, you need to use the :func:`__()` function, which will retrieve (by default) the translations from the :file:`my_app::default` dictionary. .. code-block:: php /default.lang.php __('Translate this'); Advanced mode: configure your own dictionaries ---------------------------------------------- If you don't want to put all your translations in the :file:`default.lang.php` file, you can configure in which dictionary the translations will be retrieved, **in each file** which uses the :func:`__()` function. It is quite simple for view and configuration files: .. code-block:: php /common.lang.php It is a little more complicated for admin controllers, because language depends on the user and is known only after authentication, which happens in ``before()``. ``prepare_i18n()`` has been implemented to solve this problem: .. code-block:: php :emphasize-lines: 9-12 /dictionary.lang.php if it exists // Otherwise in my_app::lang//common.lang.php __('Translate this');