Example #1
0
File: lang.php Project: nasumi/fuel
	public static function load($file, $group = null)
	{
		$lang = array();

		// Use the current language, failing that use the fallback language
		foreach (array(\Config::get('language'), static::$fallback) as $language)
		{
			if ($path = \Fuel::find_file('lang/'.$language, $file, '.php', true))
			{
				$lang = array();
				foreach ($path as $p)
				{
					$lang = $lang + \Fuel::load($p);
				}
				break;
			}
		}

		if ($group === null)
		{
			static::$lines = static::$lines + $lang;
		}
		else
		{
			if ( ! isset(static::$lines[$group]))
			{
				static::$lines[$group] = array();
			}
			static::$lines[$group] = static::$lines[$group] + $lang;
		}
	}
Example #2
0
 /**
  * Loads a language file.
  *
  * @param    mixed        $file        string file | language array | Lang_Interface instance
  * @param    mixed       $group        null for no group, true for group is filename, false for not storing in the master lang
  * @param    string|null $language     name of the language to load, null for the configurated language
  * @param    bool        $overwrite    true for array_merge, false for \Arr::merge
  * @return   array                     the (loaded) language array
  */
 public static function load($file, $group = null, $language = null, $overwrite = false)
 {
     $languages = static::$fallback;
     array_unshift($languages, $language ?: \Config::get('language'));
     if (!is_array($file) and !is_object($file) and array_key_exists($file, static::$loaded_files)) {
         return false;
     }
     $lang = array();
     if (is_array($file)) {
         $lang = $file;
     } elseif (is_string($file)) {
         $info = pathinfo($file);
         $type = 'php';
         if (isset($info['extension'])) {
             $type = $info['extension'];
             // Keep extension when it's an absolute path, because the finder won't add it
             if ($file[0] !== '/' and $file[1] !== ':') {
                 $file = substr($file, 0, -(strlen($type) + 1));
             }
         }
         $class = '\\Lang_' . ucfirst($type);
         if (class_exists($class)) {
             static::$loaded_files[$file] = true;
             $file = new $class($file, $languages);
         } else {
             throw new \FuelException(sprintf('Invalid lang type "%s".', $type));
         }
     }
     if ($file instanceof Lang_Interface) {
         try {
             $lang = $file->load($overwrite);
         } catch (\LangException $e) {
             $lang = array();
         }
         $group = $group === true ? $file->group() : $group;
     }
     if ($group === null) {
         static::$lines = $overwrite ? array_merge(static::$lines, $lang) : \Arr::merge(static::$lines, $lang);
     } else {
         $group = $group === true ? $file : $group;
         if (!isset(static::$lines[$group])) {
             static::$lines[$group] = array();
         }
         static::$lines[$group] = $overwrite ? array_merge(static::$lines[$group], $lang) : \Arr::merge(static::$lines[$group], $lang);
     }
     return $lang;
 }
Example #3
0
 /**
  * Load a language file
  *
  * @param   string
  * @param   string|null  name of the group to load to, null for global
  */
 public static function load($file, $group = null, $language = null)
 {
     $languages = static::$fallback;
     array_unshift($languages, $language ?: \Config::get('language'));
     $lines = array();
     foreach ($languages as $lang) {
         if ($path = \Finder::search('lang/' . $lang, $file, '.php', true)) {
             foreach ($path as $p) {
                 $lines = \Arr::merge(\Fuel::load($p), $lines);
             }
             break;
         }
     }
     if ($group === null) {
         static::$lines = \Arr::merge($lines, static::$lines);
     } else {
         $group = $group === true ? $file : $group;
         if (!isset(static::$lines[$group])) {
             static::$lines[$group] = array();
         }
         static::$lines[$group] = \Arr::merge($lines, static::$lines[$group]);
     }
 }
Example #4
0
File: Lang.php Project: rezon/sugi
 /**
  * Loads the text .po translations file
  *
  * @param str $file - text .po file to load
  * @return boolean
  */
 protected static function loadPo($file)
 {
     $fp = fopen($file, 'r');
     if ($fp === false) {
         return false;
     }
     $type = 0;
     $translations = array();
     $translationKey = "";
     $header = "";
     do {
         $line = trim(fgets($fp));
         if ($line == "" || $line[0] == "#") {
             continue;
         }
         if (preg_match("/msgid[[:space:]]+\"(.+)\"\$/i", $line, $regs)) {
             $type = 1;
             $translationKey = stripcslashes($regs[1]);
         } elseif (preg_match("/msgid[[:space:]]+\"\"\$/i", $line, $regs)) {
             $type = 2;
             $translationKey = "";
         } elseif (preg_match("/^\"(.*)\"\$/i", $line, $regs) && ($type == 1 || $type == 2 || $type == 3)) {
             $type = 3;
             $translationKey .= stripcslashes($regs[1]);
         } elseif (preg_match("/msgstr[[:space:]]+\"(.+)\"\$/i", $line, $regs) && ($type == 1 || $type == 3) && $translationKey) {
             $translations[$translationKey] = stripcslashes($regs[1]);
             $type = 4;
         } elseif (preg_match("/msgstr[[:space:]]+\"\"\$/i", $line, $regs) && ($type == 1 || $type == 3) && $translationKey) {
             $type = 4;
             $translations[$translationKey] = "";
         } elseif (preg_match("/^\"(.*)\"\$/i", $line, $regs) && $type == 4 && $translationKey) {
             $translations[$translationKey] .= stripcslashes($regs[1]);
         } elseif (preg_match("/^\"(.*)\"\$/i", $line, $regs) && $type == 6 && $translationKey) {
             $type = 6;
         } elseif (preg_match("/msgstr[[:space:]]+\"(.+)\"\$/i", $line, $regs) && $type == 2 && !$translationKey) {
             $header .= stripcslashes($regs[1]);
             $type = 5;
         } elseif (preg_match("/msgstr[[:space:]]+\"\"\$/i", $line, $regs) && !$translationKey) {
             $header = "";
             $type = 5;
         } elseif (preg_match("/^\"(.*)\"\$/i", $line, $regs) && $type == 5) {
             $header .= stripcslashes($regs[1]);
         } else {
             unset($translations[$translationKey]);
             $type = 0;
             $translationKey = "";
         }
     } while (!feof($fp));
     fclose($fp);
     static::$lines = array_merge(static::$lines, $translations);
     return true;
 }