From 779442381f9b360610390930509aa4cbc2acea7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaime=20Pe=CC=81rez?= <jaime.perez@uninett.no> Date: Tue, 4 Oct 2016 16:26:05 +0200 Subject: [PATCH] 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. --- lib/SimpleSAML/Locale/Translate.php | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/lib/SimpleSAML/Locale/Translate.php b/lib/SimpleSAML/Locale/Translate.php index 004a7cd81..4f3abf901 100644 --- a/lib/SimpleSAML/Locale/Translate.php +++ b/lib/SimpleSAML/Locale/Translate.php @@ -467,4 +467,32 @@ class Translate ); 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); + } } -- GitLab