Habari\Locale::_t PHP Method

_t() public static method

Return a version of the string translated into the current locale
public static _t ( string $text, array $args = [], string $domain = 'habari' ) : string
$text string The text to echo translated
$args array
$domain string (optional) The domain to search for the message
return string The translated string
    public static function _t($text, $args = array(), $domain = 'habari')
    {
        if (is_string($args)) {
            $domain = $args;
        }
        if (isset(self::$messages[$domain][$text])) {
            $t = self::$messages[$domain][$text][1][0];
        } else {
            $t = $text;
        }
        if (!empty($args) && is_array($args)) {
            $trs = array();
            foreach ($args as $key => $value) {
                if (is_string($key)) {
                    $usekey = $key;
                    switch ($key[0]) {
                        case '@':
                            // HTML Escape
                            $value = Utils::htmlspecialchars($value);
                            break;
                        case ':':
                            // Use literally
                            //$value = $value;
                            break;
                        case '{':
                            // Table name
                            $value = DB::table(preg_replace('#^\\{(.+)\\}?$#', '$1', $key));
                            break;
                    }
                    $trs[$usekey] = str_replace('%', '%%', $value);
                }
            }
            $t = strtr($t, $trs);
            array_unshift($args, $t);
            $t = call_user_func_array('sprintf', $args);
        }
        return $t;
    }

Usage Example

Example #1
0
/**
 * Return a version of the string translated into the current locale, alias for HabariLocale::_t()
 *
 * @param string $text The text to translate
 * @param array $args
 * @param string $domain
 * @return string The translated string
 */
function _t($text, $args = array(), $domain = 'habari')
{
    return Locale::_t($text, $args, $domain);
}