Skip to content
Snippets Groups Projects
Commit dca36184 authored by Jaime Pérez's avatar Jaime Pérez
Browse files

Add a couple of methods to perform translations with PHP's native gettext...

Add a couple of methods to perform translations with PHP's native gettext implementation, and start using them.
parent eae50e0d
Branches
Tags
No related merge requests found
......@@ -495,4 +495,32 @@ class Translate
return strtr($text, is_array($args[0]) ? $args[0] : $args);
}
public static function translateSingularNativeGettext($original)
{
$text = gettext($original);
if (func_num_args() === 1) {
return $text;
}
$args = array_slice(func_get_args(), 1);
return strtr($text, is_array($args[0]) ? $args[0] : $args);
}
public static function translatePluralNativeGettext($original, $plural, $value)
{
$text = ngettext($original, $plural, $value);
if (func_num_args() === 3) {
return $text;
}
$args = array_slice(func_get_args(), 3);
return strtr($text, is_array($args[0]) ? $args[0] : $args);
}
}
......@@ -168,8 +168,8 @@ class SimpleSAML_XHTML_Template
$options = array(
'cache' => $cache,
'auto_reload' => $auto_reload,
'translation_function' => 'gettext',
'translation_function_plural' => 'ngettext',
'translation_function' => array('\SimpleSAML\Locale\Translate', 'translateSingularNativeGettext'),
'translation_function_plural' => array('\SimpleSAML\Locale\Translate', 'translatePluralNativeGettext'),
);
// set up translation
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment