i18n

i18n is the abbreviation for internationalization. Magento adds i18n support out of the box, thus adapting to various languages and regions without application changes. Within app/functions.php, there is a __() translation function, which is defined as follows:

function __()
{
    $argc = func_get_args();

    $text = array_shift($argc);
    if (!empty($argc) && is_array($argc[0])) {
        $argc = $argc[0];
    }

    return new \Magento\Framework\Phrase($text, $argc);
}

This translation function accepts a variable number of arguments and passes them to a constructor of the \Magento\Framework\Phrase class and returns its instance. The Phrase class has the __toString method, which then returns the translated string.

Here are a few examples of how we can use the __() function: ...

Get Magento 2 Developer's Guide now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.