PHP code example of abcms / yii2-multilanguage
1. Go to this page and download the library: Download abcms/yii2-multilanguage library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
abcms / yii2-multilanguage example snippets
$config = [
......
'language' => 'en',
'sourceLanguage' => 'en',
......
];
[
'components' => [
......
'multilanguage' => [
'class' => 'abcms\multilanguage\Multilanguage',
'languages' => [
'en' => 'English',
'ar' => 'Arabic',
'fr' => 'French',
],
],
],
]
'bootstrap' => ['log', 'multilanguage'],
'urlManager' => [
'class' => abcms\multilanguage\UrlManager::className(),
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
'<lang:([a-z]{2,3}(-[A-Z]{2})?)>/<controller>/<action>/' => '<controller>/<action>',
],
],
<?= abcms\multilanguage\widgets\LanguageBar::widget()
<a class="<?= (Yii::$app->language == 'en') ? 'active' : '';
'controllerMap' => [
'migrate' => [
'class' => 'yii\console\controllers\MigrateController',
'migrationNamespaces' => [
'abcms\library\migrations',
'abcms\multilanguage\migrations',
],
],
],
[
'class' => \abcms\multilanguage\behaviors\ModelBehavior::className(),
'attributes' => [
'title',
'description:text-area',
],
],
<?= \abcms\multilanguage\widgets\TranslationForm::widget(['model' => $model, 'form' => $form])
<?=
\abcms\multilanguage\widgets\TranslationView::widget([
'model' => $model,
])
$model->automaticTranslationSaving = true;
$translatedModel = $model->translate();
$translatedModels = Yii::$app->multilanguage->translateMultiple($models);