timur-flush / phalclate
A library of internationalization.
v2.1.0
2019-01-23 15:18 UTC
Requires
- php: ^7.2.0
- ext-phalcon: ^3.4.0
- globalcitizen/php-iban: ^2.6.9
- symfony/polyfill-mbstring: >=1.10.0
Requires (Dev)
- codeception/codeception: ^2.5
- php-coveralls/php-coveralls: *
- squizlabs/php_codesniffer: ^3.0.0
- vlucas/phpdotenv: ^3.1.0
README
Phalclate
Phalclate is library developed for internationalization.
p.s I will make normal documentation when my library will be the focus of people's attention. For other questions, please contact me in Telegram.
Installation
composer require timur-flush/phalclate:^2.0
Via Pdo\Postgresql adapter:
Table structure:
use TimurFlush\Phalclate\Adapter\Pdo\Postgresql as PHAdapter; $adapter = new PHAdapter( [ 'host' => '127.0.0.1', #Host 'port' => 5432, #Port 'dbname' => '', #Database name 'username' => '', #Username //'password' => '', #Password of user (Optional parameter) //'schema' => '', # Database schema (Optional parameter, by default: public) 'tableName' => 'translations' # Name of table ] );
use TimurFlush\Phalclate\Manager as PHManager; use TimurFlush\Phalclate\Entity\{ Language as PHLanguage, Region as PHRegion }; //Initialize of russian language. $ru = new PHLanguage('ru'); //Setup of region (optional) $ru->addRegion( new PHRegion('ru') ); //Initialize of english language. $en = new PHLanguage('en'); //Setup of regions (optional) $en->setRegions([ new PHRegion('US'), new PHRegion('GB') ]); $manager = new PHManager( $adapter, [ 'baseLanguages' => [$ru, $en], //Base languages (Required, Array of PHLanguage objects) 'currentLanguage' => 'en', //Current language (Required, One of the above else will be throwed exception) 'currentRegion' => 'US', //Current region (Optional, Any, however if the region is not found then it will not be setted.) 'failOverTranslation' => 'lol' //Fail over translation (Optional) ] ); //Example 1 echo $manager->getTranslation( 'hello', true, //passed boolean argument is first fetch mode. (Optional, Allows the use of translations from other regions, by default false) ['name' => 'John'] //passed array argument is placeholders. (Optional) '' //Passed string argument is custom fail over translation. (Optional) ); // Hello, John. //Please note that the last 3 arguments can be passed in any order. //Example 2 echo $manager->getTranslation('notFoundable'); // lol //Example 3 echo $manager->getTranslation('position', true); //centre //Example 4 echo $manager->getTranslation('notFoundable', 'kek'); //kek
Requirements
Author
Timur Flush. Telegram: @flush02 or https://t.me/flush02
License
BSD-3-Clause