示例#1
0
 /**
  * Returns a text by a key/group and current locale.
  * Text can be formatted string and values $p1,$p2,.... can be inserted 
  * 
  * @param string $key Key of text to translate
  * @param string $group Group of keys
  * @param string $p1 Variable 1 to insert in a text if a value fo a key is formatted string
  * @param string $p2 Variable 2
  * @param string $p3 Variable 3
  * @param string $p4 Variable 4
  * @param string $p5 Variable 5
  * 
  * @return string
  */
 public function getText($key, $group = '', $p1 = '', $p2 = '', $p3 = '', $p4 = '', $p5 = '')
 {
     if (is_object($this->translation)) {
         return $this->translation->getText($key, $group, $p1, $p2, $p3, $p4, $p5);
     }
     if (property_exists($this, 'application') && is_object($this->application)) {
         return $this->application->getText($key, $group, $p1, $p2, $p3, $p4, $p5);
     }
     return $key;
 }
示例#2
0
require 'vendor/autoload.php';
// folder where translations are stored
$lang_folder_path = dirname(__FILE__) . '/lang/';
// get locale from url
$locale = $_REQUEST['locale'];
if ($locale == '') {
    // set english of not posted
    $locale = 'en';
}
// create translation object
$translation = new Gelembjuk\Locale\Translate(array('localespath' => $lang_folder_path, 'locale' => $locale));
// =============================================================
echo '<h1>Test 1. Welcome message</h1>';
$username = '******';
// return formatted text , insert user's info
echo '<p>' . $translation->getText('hello', '', $username) . '</p>';
// return big translater text
echo '<div>' . $translation->getText('about', 'frontpage') . '</div>';
// =============================================================
echo '<h1>Test 2. Class with translation functionality</h1>';
class MyClass
{
    // include translation functions
    use Gelembjuk\Locale\GetTextTrait;
    public function doSomething()
    {
        echo $this->getText('welcome') . '<br>';
    }
    public function andAgainWelcome($name)
    {
        // use short call for getText