/** * Returns translation of a string. If no translation exists, the original * string will be returned. No parameters are replaced. * * $hello = I18n::get('Hello friends, my name is :name'); * * @param string $string text to translate * @param string $lang target language * @return string */ public static function get($string, $lang = NULL) { if (!$lang) { // Use the global target language $lang = Lang::instance()->getCurrentLang()['iso']; } // Load the translation table for this language $items = I18n::load($lang); // Return the translated string if it exists return isset($items[$string]) ? $items[$string] : $string; }
function __($string, array $values = NULL, $lang = null) { if (!$lang) { $lang = Lang::instance()->getCurrentLang()['iso']; } if ($lang !== Lang::DEFAULT_LANGUAGE) { // The message and target languages are different // Get the translation for this message $string = I18n::get($string, $lang); } return empty($values) ? $string : strtr($string, $values); }