예제 #1
0
 /**
  * Inits the language file according to the current language the site/user uses
  *
  * @throws AppException
  */
 protected function initLanguage()
 {
     // Init only once
     if (empty(self::$init_stages[$this->name]['language']) && $this->paths->exists('dir.language')) {
         $path = $this->paths->get('dir.language');
         $this->language = new Language();
         $languages = ['en'];
         // If there is a different language code ist set, override the english values with values from this language
         // file
         $site_language = $this->core->config->get('Core', 'site.language.default');
         if ($site_language != 'en') {
             $languages[] = $site_language;
         }
         foreach ($languages as $language) {
             $filename = $path . DIRECTORY_SEPARATOR . $language . '.php';
             if (!file_exists($filename)) {
                 throw new AppException(sprintf('No english languagefile (%s.php) found in languagedir "%s"', $language, $path));
             }
             $this->language->load($filename);
         }
         // Set Core language as fallback language to all app that are nor Core
         if ($this->name != 'Core') {
             $this->language->setFallbackLanguage($this->core->getAppInstance('Core')->language);
         }
         self::$init_stages[$this->name]['language'] = true;
     }
 }
예제 #2
0
 /**
  * Returns the string of string of a specific language key or an array of strings flagge as preserved
  *
  * You can create linked strings by setting '@@your.linked.string' as result in your language file.
  *
  * Will query a set fallback language object when the requested key is not set in apps language strings.
  * This way it is possible to create a chain of fallback request from one app to another.
  *
  * Important: Do not create circle requests!
  *
  * @param string $key
  *
  * @return string|array
  */
 public function get(string $key)
 {
     //
     $result = $this->strings[$key] ?? $key;
     // Is there a redirection to another string?
     if (is_string($result) && substr($result, 0, 2) == '@@') {
         $result = $this->get(substr($result, 2));
     }
     if ($result == $key && isset($this->fallback_language)) {
         $result = $this->fallback_language->get($key);
     }
     return $result;
 }