vintage/yii2-i18n

Internalization module for automatic adding of translations to database

Installs: 4 523

Dependents: 0

Suggesters: 0

Security: 0

Stars: 5

Watchers: 2

Forks: 42

Open Issues: 1

Type:yii2-extension

1.3.0 2017-08-30 06:57 UTC

This package is not auto-updated.

Last update: 2024-11-10 02:29:52 UTC


README

Internalization module for Yii2


Internalization module for automatic adding of translations to database.

Based on Zelenin I18N module.

Total Downloads Latest Stable Version Latest Unstable Version

Installation

Install package

Run command

composer require vintage/yii2-i18n

or add

"vintage/yii2-i18n": "~1.1"

to the require section of your composer.json.

Configuration

  1. Configure I18N component in common part of your application
'components' => [
    'i18n' => [
        'class' => vintage\i18n\components\I18N::className(),
        'languages' => ['ru-RU', 'de-DE', 'it-IT'],
    ],
    // ...
],
  1. Configure module in backend part of your application
'modules' => [
	'i18n' => vintage\i18n\Module::className(),
	// ...
],
  1. Applying migrations
./yii migrate --migrationPath=@vintage/i18n/migrations

Usage

Go to http://backend.your-app.dev/translations for translating of messages.

PHP to database import

If you have an old project with PHP-based i18n you may migrate to DbSource via console.

Run command

./yii i18n/import @common/messages

where @common/messages is path to app translations

Database to PHP export

Run command

./yii i18n/export @vintage/i18n/messages vintage/i18n

where @vintage/i18n/messages is path to app translations and vintage/i18n is translations category in DB.

Using yii category with database

Import translations from PHP files

./yii i18n/import @yii/messages

Configure I18N component

'components' => [
    'i18n' => [
        'class'=> vintage\i18n\components\I18N::className(),
        'languages' => ['ru-RU', 'de-DE', 'it-IT'],
        'translations' => [
            'yii' => [
                'class' => yii\i18n\DbMessageSource::className()
            ],
        ],
    ],
],

Caching

Cache will be updates automaticly if you updates translations in dashboard.

If you using \yii\caching\FileCache your config should be like following

// common/config/main.php
`components` => [
    // ...
    'i18n' => [
        'class'=> vintage\i18n\components\I18N::className(),
        'languages' => ['ru-RU', 'de-DE', 'it-IT'],
        'enableCaching' => true,
        'cache' => 'i18nCache',
    ],
    'i18nCache' => [
        'class' => \yii\caching\FileCache::className(),
        'cachePath' => '@frontend/runtime/cache',
    ],
],

Other

Component uses yii\i18n\MissingTranslationEvent for auto-add of missing translations to database.

Read more about I18N in official guide.

Licence

License

This project is released under the terms of the BSD-3-Clause license.

Copyright (c) 2017, Vintage Web Production