/** * Translate a plural string * * @param string $textSingular The string in singular form to translate * @param string $textPlural The string in plural form to translate * @param integer $number The amount to determine from whether to return singular or plural * @param string|null $context Optional parameter for context based translation * * @return string The translated string */ protected function translatePlural($textSingular, $textPlural, $number, $context = null) { return Translator::translatePlural($textSingular, $textPlural, $number, $this->getTranslationDomain(), $context); }
/** * Translate a plural string * * @see Translator::translatePlural() */ public function translatePlural($textSingular, $textPlural, $number, $context = null) { return Translator::translatePlural($textSingular, $textPlural, $number, $this->translationDomain, $context); }
/** * @depends testWhetherSetupLocaleSetsUpTheGivenLocale */ public function testWhetherTranslatePluralReturnsTheContextForm() { Translator::setupLocale('de_DE'); $result = Translator::translatePlural('context service', 'context services', 3, 'icingatest', 'test-context'); $expected = 'context plural dienste'; $this->assertEquals($expected, $result, 'Translator::translatePlural() could not return the translated context form'); }
public function testWhetherTranslateReturnsTheInputStringInCaseTheGivenDomainIsNotValid() { $this->assertEquals('test', Translator::translate('test', 'invalid_domain')); }
/** * Setup internationalization using gettext * * Uses the preferred user language or the browser suggested language or our default. * * @return string Detected locale code * * @see Translator::DEFAULT_LOCALE For the the default locale code. */ protected function detectLocale() { $auth = Auth::getInstance(); if ($auth->isAuthenticated() && ($locale = $auth->getUser()->getPreferences()->getValue('icingaweb', 'language')) !== null) { return $locale; } if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { return Translator::getPreferredLocaleCode($_SERVER['HTTP_ACCEPT_LANGUAGE']); } return Translator::DEFAULT_LOCALE; }
/** * Translate a string * * Autoselects the module domain, if any, and falls back to the global one if no translation could be found. * * @param string $text The string to translate * * @return string The translated string */ public function translate($text) { $domain = $this->moduleName === null ? 'icinga' : $this->moduleName; return Translator::translate($text, $domain); }
/** * Return the preferred locale based on the given HTTP header and the available translations * * @return string */ protected function getLocale() { $locale = Translator::getPreferredLocaleCode($_SERVER['HTTP_ACCEPT_LANGUAGE']); return $locale; }
/** * Bind text domain for i18n * * @return self */ protected function registerLocales() { if (file_exists($this->localedir) && is_dir($this->localedir)) { Translator::registerDomain($this->name, $this->localedir); } return $this; }
/** * Set up internationalization using gettext * * @return $this */ protected final function setupInternationalization() { if ($this->hasLocales()) { Translator::registerDomain(Translator::DEFAULT_DOMAIN, $this->getLocaleDir()); } $locale = $this->detectLocale(); if ($locale === null) { $locale = Translator::DEFAULT_LOCALE; } try { Translator::setupLocale($locale); } catch (Exception $error) { Logger::error($error); } return $this; }
/** * Bind text domain for i18n * * @return $this */ protected function registerLocales() { if ($this->hasLocales()) { Translator::registerDomain($this->name, $this->localedir); } return $this; }
/** * Translate a string * * Autoselects the module domain, if any, and falls back to the global one if no translation could be found. * * @param string $text The string to translate * * @return string The translated string */ public function translate($text) { $module = $this->getRequest()->getModuleName(); $domain = $module === 'default' ? 'icinga' : $module; return Translator::translate($text, $domain); }
/** * Setup internationalization using gettext * * Uses the preferred user language or the configured default and system default, respectively. * * @return self */ protected function setupInternationalization() { parent::setupInternationalization(); if ($this->user !== null && $this->user->getPreferences() !== null && ($locale = $this->user->getPreferences()->get('app.language') !== null)) { try { Translator::setupLocale($locale); } catch (Exception $error) { Logger::warning('Cannot set locale "' . $locale . '" configured in ' . 'preferences of user "' . $this->user->getUsername() . '"'); } } return $this; }
/** * (non-PHPDoc) * @see Translator::translatePlural() For the function documentation. */ function mtp($domain, $messageId, $messageId2, $number, $context = null) { return Translator::translatePlural($messageId, $messageId2, $number, $domain, $context); }
public function translate($text) { return Translator::translate($text, $this->translationDomain); }
function mt($domain, $messageId) { return Translator::translate($messageId, $domain); }
/** * Setup internationalization using gettext * * Uses the language defined in the global config or the default one * * @return self */ protected function setupInternationalization() { try { Translator::setupLocale($this->config->global !== null ? $this->config->global->get('language', Translator::DEFAULT_LOCALE) : Translator::DEFAULT_LOCALE); } catch (Exception $error) { Logger::error($error); } $localeDir = $this->getApplicationDir('locale'); if (file_exists($localeDir) && is_dir($localeDir)) { Translator::registerDomain('icinga', $localeDir); } return $this; }