示例#1
0
    // include translation functions
    use Gelembjuk\Locale\GetTextTrait;
    public function doSomething()
    {
        echo $this->getText('welcome') . '<br>';
    }
    public function andAgainWelcome($name)
    {
        // use short call for getText
        echo $this->_('hello', '', $name) . '<br>';
        echo $this->_('contact', 'frontpage') . '<br>';
    }
}
$obj = new MyClass();
// this meathod comes from a trait
$obj->setTranslation($translation);
$obj->doSomething();
$obj->andAgainWelcome($username);
echo '<br><br>';
// change to english
$obj->setLocale('en');
// and repeat
$obj->andAgainWelcome($username);
// =============================================================
echo '<h1>Test 3. Show language change select box</h1>';
// output form to change locale
$languages = new Gelembjuk\Locale\Languages(array('localespath' => $lang_folder_path));
echo '<hr><form name=\'langform\' method=\'GET\' action="index.php">';
echo $languages->getHTMLSelect(' name="locale" onchange="document.langform.submit()" ', $locale);
echo '</form>';
// =============================================================