Creating a multilanguage application

Every day, we meet more and more international companies, software products, and information resources that publish content on multiple languages. Yii2 provides built-in i18n support for making multilanguage applications.

In this recipe, we are translating the application interface to different languages.

Getting ready

Create a new yii2-app-basic application using the composer, as described in the official guide at http://www.yiiframework.com/doc-2.0/guide-start-installation.html.

How to do it…

  1. Change the main menu labels in the views/layouts/main.php file to use the Yii::t('app/nav', '...') method:
    echo Nav::widget([ 'options' => ['class' => 'navbar-nav navbar-right'], 'items' => [ ['label' => Yii::t('app/nav', ...

Get Yii2 Application Development Cookbook - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.