1. Go to this page and download the library: Download gelembjuk/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/ */
gelembjuk / locale example snippets
$translation = new Gelembjuk\Locale\Translate(
array(
'localespath' => $lang_folder_path, // path to your translations directory
'locale' => $locale // current locale, 2 symbol language code
)
);
echo $translation->getText('hello',''/*default group*/,$username); // hello = Hello, %s on our site. $username will be put in place of %s
echo $translation->getText('welcome');
echo $translation->getText('backsoon','logoutpage'); // custom texts group in a separate web site
class MyClass {
// le\GetTextTrait;
public function doSomething() {
echo $this->getText('welcome').'<br>';
}
public function andAgainWelcome($name) {
// use short call for getText
echo $this->_('hello','',$name).'<br>';
}
}
$obj = new MyClass();
$obj->setTranslation($translation);
$obj->doSomething();
$obj->andAgainWelcome($username);
$obj->setLocale('en');
$obj->andAgainWelcome($username);
$langobj = new Gelembjuk\Locale\Languages(array('localespath' => $lang_folder_path));
// list of used languages, used are languages with a folder in $lang_folder_path
$languages = $langobj->getUsedLanguages();
// print language select form
echo '<form name=\'langform\' method=\'GET\' action="index.php">';
echo $langobj->getHTMLSelect(' name="locale" onchange="document.langform.submit()" ',$locale/*current selected locale*/);
echo '</form>';
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.