From 1ff5c35de5dbd70a782875a91dd2232fd01b002b Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 28 Apr 2024 14:38:04 +0200 Subject: Adding upstream version 0.10.1. Signed-off-by: Daniel Baumann --- vendor/ipl/i18n/src/Translation.php | 101 ++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 vendor/ipl/i18n/src/Translation.php (limited to 'vendor/ipl/i18n/src/Translation.php') diff --git a/vendor/ipl/i18n/src/Translation.php b/vendor/ipl/i18n/src/Translation.php new file mode 100644 index 0000000..52639da --- /dev/null +++ b/vendor/ipl/i18n/src/Translation.php @@ -0,0 +1,101 @@ +translationDomain === null + ? StaticTranslator::$instance->translate($message, $context) + : StaticTranslator::$instance->translateInDomain($this->translationDomain, $message, $context); + } + + /** + * Translate a message in the given domain + * + * If no translation is found in the specified domain, the translation is also searched for in the default domain. + * + * @param string $domain + * @param string $message + * @param string $context Message context + * + * @return string Translated message or original message if no translation is found + */ + public function translateInDomain($domain, $message, $context = null) + { + return StaticTranslator::$instance->translateInDomain($domain, $message, $context); + } + + /** + * Translate a plural message + * + * The returned message is based on the given number to decide between the singular and plural forms. + * That is also the case if no translation is found. + * + * @param string $singular Singular message + * @param string $plural Plural message + * @param int $number Number to decide between the returned singular and plural forms + * @param string $context Message context + * + * @return string Translated message or original message if no translation is found + */ + public function translatePlural($singular, $plural, $number, $context = null) + { + return $this->translationDomain === null + ? StaticTranslator::$instance->translatePlural($singular, $plural, $number, $context) + : StaticTranslator::$instance->translatePluralInDomain( + $this->translationDomain, + $singular, + $plural, + $number ?? 0, + $context + ); + } + + /** + * Translate a plural message in the given domain + * + * If no translation is found in the specified domain, the translation is also searched for in the default domain. + * + * The returned message is based on the given number to decide between the singular and plural forms. + * That is also the case if no translation is found. + * + * @param string $domain + * @param string $singular Singular message + * @param string $plural Plural message + * @param int $number Number to decide between the returned singular and plural forms + * @param string $context Message context + * + * @return string Translated message or original message if no translation is found + */ + public function translatePluralInDomain($domain, $singular, $plural, $number, $context = null) + { + return StaticTranslator::$instance->translatePluralInDomain( + $domain, + $singular, + $plural, + $number ?? 0, + $context + ); + } +} -- cgit v1.2.3