示例#1
0
文件: G11n.php 项目: titon/g11n
 /**
  * Sets up the application with the defined locale key; the key will be formatted to a lowercase dashed URL friendly format.
  * The system will then attempt to load the locale resource bundle and finalize configuration settings.
  *
  * @param \Titon\G11n\Locale $locale
  * @return \Titon\G11n\Locale
  */
 public function addLocale(Locale $locale)
 {
     $key = self::canonicalize($locale->getCode());
     if (isset($this->_locales[$key])) {
         return $this->_locales[$key];
     }
     // Configure and initialize
     foreach ($this->getResourcePaths() as $domain => $paths) {
         $locale->addResourcePaths($domain, $paths);
     }
     $locale->initialize();
     // Set the locale
     $this->_locales[$key] = $locale;
     // Set the parent as well
     if ($parent = $locale->getParentLocale()) {
         $this->addLocale($parent);
     }
     // Set fallback if none defined
     if (!$this->_fallback) {
         $this->setFallback($key);
     }
     return $locale;
 }