motion / yii2-language-provider
This package provides interface for language provider for Yii2 Framework
Installs: 16 187
Dependents: 2
Suggesters: 0
Security: 0
Stars: 5
Watchers: 2
Forks: 0
Open Issues: 2
Type:yii2-extension
Requires
- yiisoft/yii2: ~2.0.13
Requires (Dev)
- codeception/codeception: ~2.0
This package is not auto-updated.
Last update: 2024-12-22 05:44:59 UTC
README
This package provides interface for language provider for accessing application languages from any storage for Yii2 Framework. It's allows to you create multi-language modules for using in Yii2 based application. As example of integration to module you can see yii2-email-template extension.
From the box you can use:
If you want to create your implementation of language provider you should implement interface
motion\i18n\LanguageProviderInterface
.
Installation
The preferred way to install this extension is through composer.
Either run
$ composer require motion/yii2-language-provider
or add
"motion/yii2-language-provider": "~2.1"
to the require
section of your composer.json
.
Usage
Config language provider
Example
$config = [ 'languages' => [ [ 'label' => 'English', 'locale' => 'en', ], [ 'label' => 'Ukrainian', 'locale' => 'uk', ], [ 'label' => 'Russian', 'locale' => 'ru', ], ], 'defaultLanguage' => [ 'label' => 'English', 'locale' => 'en', ], ]; $provider = new \motion\i18n\ConfigLanguageProvider($config); $provider->getLanguages(); // returns list of languages $provider->getDefaultLanguage(); // returns default language $provider->getLanguageLabel('en'); // returns language label by locale (`English`)
Database language provider
Example
$config = [ 'db' => 'secondDb', 'labelField' => 'title', ]; $provider = new \motion\i18n\DbLanguageProvider($config); $provider->getLanguages(); // returns list of languages $provider->getDefaultLanguage(); // returns default language $provider->getLanguageLabel('uk'); // returns language label by locale
Tests
You can run tests with composer command
$ composer test
or using following command
$ codecept build && codecept run
Licence
This project is released under the terms of the BSD-3-Clause license.
Copyright (c) 2017-2018, Motion Web Production