/** * Test Plural Translate */ public function testPluralTranslateWithAdditionalParams() { $translator = new Translator(); $translator->setDomain('messages'); $translator->setLocale('uk_UA'); $translator->setPath(PATH_APPLICATION . '/locale'); if (function_exists('ngettext')) { $this->assertEquals('2 messages', $translator->translatePlural('%d message', '%d messages', 2, 2)); } else { $this->assertEquals('2 message', $translator->translatePlural('%d message', '%d messages', 2, 2)); } }
/** * Translate plural form * * Example of usage * // plural form + sprintf * // equal to sprintf(ngettext('%d comment', '%d comments', 4), 4) * _n('%d comment', '%d comments', 4, 4) * * // plural form + sprintf * // equal to sprintf(ngettext('%d comment', '%d comments', 4), 4, 'Topic') * _n('%d comment to %s', '%d comments to %s', 4, 'Topic') * * @param string $singular * @param string $plural * @param integer $number * @param string[] $text [optional] * @return string */ function _n($singular, $plural, $number, ...$text) { return Translator::translatePlural($singular, $plural, $number, ...$text); }
/** * Get error template * * @return string */ public function getTemplate() { return Translator::translate($this->template); }
/** * Init instance * * @return Instance */ protected static function initInstance() { $instance = new Instance(); $instance->setOptions(Config::getData('translator')); return $instance; }