1. Go to this page and download the library: Download fdevs/locale 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/ */
fdevs / locale example snippets
Devs\Locale\Model\LocaleText;
use FDevs\Locale\Translator;
// The same text in different languages
$englishText = new LocaleText('I am a programmer', 'en');
$chineseText = new LocaleText('我是程序员', 'zh');
$russianText = new LocaleText('Я программист', 'ru');
$supportedTexts = [
$englishText,
$russianText,
$chineseText,
];
$trans = new Translator();
$trans->setLocale('zh');
// 1. Get text for current locale - ch (Chinese)
$text = $trans->trans($supportedTexts);
echo $text?$text->getText():'';
// Output: "我是程序员"
use FDevs\Locale\Model\PriorityLocale;
use FDevs\Locale\TranslatorPriority;
$priorityLocale = [
new PriorityLocale('uk',['en','ru']),
new PriorityLocale('en',['uk']),
new PriorityLocale('fa',['zh','en']),
];
$trans = new TranslatorPriority('en',$priorityLocale);
$text = $trans->trans($supportedTexts, 'uk');
echo $text?$text->getText():'';
// Output: "I am programmer"
use FDevs\Locale\DataProvider\DataProviderInterface;
class MyProvider implements DataProviderInterface
{
//implement interface
}
use FDevs\Locale\DataProvider\DataProviderRegistry;
use FDevs\Locale\Translator;
use FDevs\Locale\TranslatorPriority;
$registry = new DataProviderRegistry([new MyProvider()]);
$translator = new Translator('en',$registry);
//or
$translator = new TranslatorPriority('en', $priorityLocale, $registry);
bash
$ php composer.phar
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.