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

Add translation methods to SimpleSAML\Locale\Translate.

These two methods are equivalent to gettext/gettext's __() and n__(), but using strtr() instead of vsprintf(), so that the placeholders can be names instead of printf() format strings.
parent 8c140de5
No related branches found
No related tags found
No related merge requests found
...@@ -467,4 +467,32 @@ class Translate ...@@ -467,4 +467,32 @@ class Translate
); );
return array(); return array();
} }
public static function translateSingular($original)
{
$text = \Gettext\BaseTranslator::$current->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 translatePlural($original, $plural, $value)
{
$text = \Gettext\BaseTranslator::$current->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);
}
} }
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