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
No related branches found
No related tags found
No related merge requests found
...@@ -495,4 +495,32 @@ class Translate ...@@ -495,4 +495,32 @@ class Translate
return strtr($text, is_array($args[0]) ? $args[0] : $args); 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 ...@@ -168,8 +168,8 @@ class SimpleSAML_XHTML_Template
$options = array( $options = array(
'cache' => $cache, 'cache' => $cache,
'auto_reload' => $auto_reload, 'auto_reload' => $auto_reload,
'translation_function' => 'gettext', 'translation_function' => array('\SimpleSAML\Locale\Translate', 'translateSingularNativeGettext'),
'translation_function_plural' => 'ngettext', 'translation_function_plural' => array('\SimpleSAML\Locale\Translate', 'translatePluralNativeGettext'),
); );
// set up translation // set up translation
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment