/** * {@inheritdoc} */ public function load($locale) { $dictionary = $this->loader->load($locale); if (isset($this->extends[$locale])) { $dictionary += $this->load($this->extends[$locale]); } if ($this->fallbackLocale !== null && $locale !== $this->fallbackLocale) { $dictionary += $this->load($this->fallbackLocale); } return $dictionary; }
/** * @param string $key * * @param Locale $locale * * @return string|null */ private function translateIn($key, Locale $locale) { $localeString = $locale->toString(); if (!isset($this->texts[$localeString])) { $this->texts[$localeString] = $this->loader->load($locale); } $texts = $this->texts[$localeString]; return isset($texts[$key]) ? $texts[$key] : null; }
/** * @param string $key The translation key to look up. * @param array $parameters An associative array of parameters to replace in the translated string. * @param string|null $locale The locale to translate in, or null to use the default locale. * * @return string * * @throws \Exception */ public function translate($key, array $parameters = [], $locale = null) { if ($locale === null) { if ($this->defaultLocale === null) { throw new \Exception('No default locale has been set.'); } $locale = $this->defaultLocale; } if (!isset($this->dictionaries[$locale])) { $this->dictionaries[$locale] = $this->loader->load($locale); } $dictionary = $this->dictionaries[$locale]; if (!isset($dictionary[$key])) { return $key; } $value = $dictionary[$key]; if ($parameters) { return $this->replaceParameters($value, $parameters); } return $value; }