.. _php/classes/i18n: I18n #### .. php:namespace:: Nos .. php:class:: I18n Provides the translation related functions. ::setLocale() ------------- .. php:staticmethod:: setLocale($locale) Configure the locale to use for translations. :param string $locale: A valid locale (``en``, ``en_GB``, ``en_GB.utf-8`` and ``en_GB.utf-8@variant`` are all valid). ::restoreLocale() ----------------- .. php:staticmethod:: restoreLocale() Restores the previous locale. ::load() -------- .. php:staticmethod:: load($file) Loads a dictionary for the current locale. :param string $file: Dictionary path. :param string $group: Group name. Default ``null``, use ``$file``. ::get() ------- .. php:staticmethod:: get($message, $default = null) Retrieves a translation from the last loaded dictionary. :param string $message: The message to translate. :param string $default: The default text to return when the message is not found. Default value is the message itself. :returns: The translation or ``null`` if not founded ::gget() -------- .. php:staticmethod:: gget($file, $message, $default = null) Retrieves a translation from a specific dictionary. :param string $file: Which dictionary to look into. :param string $message: The message to translate. :param string $default: The default text to return when the message is not found. Default value is the message itself. :returns: The translation or ``null`` if not founded .. warning:: The dictionary must have been loaded manually before. ::nget() -------- .. php:staticmethod:: nget($singular, $plural, $n) The plural version of :php:meth:`I18n::get`. Some languages have more than one form for plural messages dependent on the count. :param string $singular: The singular form of the string to be converted. Used as the key for the search in the dictionary :param string $plural: The plural form :param string $n: Used to determine which plural form to used depending locale. :returns: The translation or, if not founded, $singular is returned if n == 1, otherwise $plural ::ngget() --------- .. php:staticmethod:: gget($group, $singular, $plural, $n) Retrieves a plural translation from a specific dictionary. :param string $group: Which dictionary to look into. :param string $singular: The singular form of the string to be converted. Used as the key for the search in the dictionary :param string $plural: The plural form :param string $n: Used to determine which plural form to used depending locale. :returns: The translation or, if not founded, $singular is returned if n == 1, otherwise $plural .. warning:: The dictionary must have been loaded manually before. ::current_dictionary() ---------------------- .. php:staticmethod:: current_dictionary($list) Set the current dictionary :param string|array $list: A dictionary file or list of dictionaries. ::dictionary() -------------- .. php:staticmethod:: dictionary($files) Returns a closure that translate messages from a specific dictionary. :param string|array $files: A dictionary file or list of dictionaries. :returns: A callable to translate a message .. code-block:: php