1. Go to this page and download the library: Download timur-flush/phalclate 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/ */
timur-flush / phalclate example snippets
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
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.