1. Go to this page and download the library: Download amitkhare/easy-translator 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/ */
amitkhare / easy-translator example snippets
sh
= new AmitKhare\EasyTranslator\EasyTranslator();
$t->setLocalePath("PATH/TO/LOCALES/DIRECTORY/");
// save a hi-IN.lang file in above location,
// Note: file extention should be `.lang`
// i.e. : en-IN.lang, hi-IN.lang, en-US.lang, en-UK.lang
$t->setLocale("hi-IN");
echo $t->translate("FIELD_NOT_SET",["USERNAME"]);
//OUTPUT: `यूजरनेम` फील्ड खली है.
sh
use AmitKhare\EasyTranslator; // use namespace.
// autoload via composer
= new EasyTranslator(); // instantiate EasyTranslator;
$t->setLocalePath("PATH/TO/LOCALES/DIRECTORY/");
// save a hi-IN.lang file in above location,
// Note: file extention should be `.lang`
// i.e. : en-IN.lang, hi-IN.lang, en-US.lang, en-UK.lang
$t->setLocale("en-IN");
$keyString = "FIELD_NOT_SET";
$replacements = ["USERNAME"];
$locale = "hi-IN";
echo $t->translate($keyString);
//OUTPUT: The field is not set.
// OR ###########################################
echo $t->translate($keyString,$replacements);
//OUTPUT: The `Username` field is not set.
// OR ###########################################
echo $t->translate($keyString,$replacements,$locale);
//OUTPUT: `यूजरनेम` फील्ड खली है.
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.