O'Reilly logo

Magento 2 Developer's Guide by Branko Ajzele

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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: ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required