public function render(\Erebot\IntlInterface $translator) { $locale = $translator->getLocale(\Erebot\IntlInterface::LC_MESSAGES); $coreTranslator = new \Erebot\Intl('Erebot\\Styling'); $coreTranslator->setLocale(\Erebot\IntlInterface::LC_MESSAGES, $locale); // DO NOT CHANGE THE CODE BELOW, ESPECIALLY COMMENTS & WHITESPACES. // It has all been carefully crafted to make both xgettext and // PHP_CodeSniffer happy! Also, it avoids relying on OS line endings // as it breaks xgettext on at least Windows platforms. $rule = $coreTranslator->_("%with-words:\n" . " 0: 0 seconds;\n" . " 1: 1 second;\n" . " 2: =#0= seconds;\n" . " 60/60: <%%min<;\n" . " 61/60: <%%min<, >%with-words>;\n" . " 3600/60: <%%hr<;\n" . " 3601/60: <%%hr<, >%with-words>;\n" . " 86400/86400: <%%day<;\n" . " 86401/86400: <%%day<, >%with-words>;\n" . " 604800/604800: <%%week<;\n" . " 604801/604800: <%%week<, >%with-words>;\n" . "%%min:\n" . " 1: 1 minute;\n" . " 2: =#0= minutes;\n" . "%%hr:\n" . " 1: 1 hour;\n" . " 2: =#0= hours;\n" . "%%day:\n" . " 1: 1 day;\n" . " 2: =#0= days;\n" . "%%week:\n" . " 1: 1 week;\n" . " 2: =#0= weeks;"); $formatter = new \NumberFormatter($locale, \NumberFormatter::PATTERN_RULEBASED, $rule); return (string) $formatter->format($this->value); }
public function getTranslator($component) { if (isset($this->locale)) { $translator = new \Erebot\Intl($component); $translator->setLocale(\Erebot\IntlInterface::LC_MESSAGES, $this->locale); $categories = array(\Erebot\IntlInterface::LC_MONETARY, \Erebot\IntlInterface::LC_NUMERIC, \Erebot\IntlInterface::LC_TIME); foreach ($categories as $category) { $translator->setLocale($category, $this->coreTranslator->getLocale($category)); } return $translator; } return $this->coreTranslator; }
public function getTranslator($component) { if (isset($this->locale)) { $translator = new \Erebot\Intl($component); $translator->setLocale(\Erebot\IntlInterface::LC_MESSAGES, $this->locale); $categories = array(\Erebot\IntlInterface::LC_MONETARY, \Erebot\IntlInterface::LC_NUMERIC, \Erebot\IntlInterface::LC_TIME); $proxiedTranslator = $this->proxified->getTranslator($component); foreach ($categories as $category) { $translator->setLocale($category, $proxiedTranslator->getLocale($category)); } return $translator; } if ($this->proxified === $this) { throw new \Erebot\NotFoundException('No translator associated'); } return $this->proxified->getTranslator($component); }