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.
composer require timur-flush/phalclate:^2.0
Via Pdo\Postgresql adapter:
Table structure:
id(serial) | key(varchar255) | language(char2) | region(varchar255) | value(text) |
---|---|---|---|---|
1 | position | en | GB | centre |
3 | hello | en | [NULL] | Hello, %name%. |
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
Name | Version |
---|---|
PHP | ^7.2.0 |
Phalcon framework | ^3.4.0 |
Timur Flush. Telegram: @flush02 or https://t.me/flush02
BSD-3-Clause