Load a localization package

@param string $lang  Language ID
@param array  $add   Additional text labels/messages
@param array  $merge Additional text labels/messages to merge
358763
public function load_language($lang = null, $add = array(), $merge = array())
    {
        $lang = $this->language_prop($lang ?: $_SESSION['language']);

        // load localized texts
        if (empty($this->texts) || $lang != $_SESSION['language']) {
            $this->texts = array();

            // handle empty lines after closing PHP tag in localization files
            ob_start();

            // get english labels (these should be complete)
            @include(RCUBE_LOCALIZATION_DIR . 'en_US/labels.inc');
            @include(RCUBE_LOCALIZATION_DIR . 'en_US/messages.inc');

            if (is_array($labels))
                $this->texts = $labels;
            if (is_array($messages))
                $this->texts = array_merge($this->texts, $messages);

            // include user language files
            if ($lang != 'en' && $lang != 'en_US' && is_dir(RCUBE_LOCALIZATION_DIR . $lang)) {
                include_once(RCUBE_LOCALIZATION_DIR . $lang . '/labels.inc');
                include_once(RCUBE_LOCALIZATION_DIR . $lang . '/messages.inc');

                if (is_array($labels))
                    $this->texts = array_merge($this->texts, $labels);
                if (is_array($messages))
                    $this->texts = array_merge($this->texts, $messages);
            }

            ob_end_clean();

            $_SESSION['language'] = $lang;
        }

        // append additional texts (from plugin)
        if (is_array($add) && !empty($add)) {
            $this->texts += $add;
        }

        // merge additional texts (from plugin)
        if (is_array($merge) && !empty($merge)) {
            $this->texts = array_merge($this->texts, $merge);
        }
    }
356129
public function mergeWith(Translation $translation, $options = Merge::DEFAULTS)
    {
        Merge::mergeTranslation($translation, $this, $options);
        Merge::mergeReferences($translation, $this, $options);
        Merge::mergeComments($translation, $this, $options);
        Merge::mergeExtractedComments($translation, $this, $options);
        Merge::mergeFlags($translation, $this, $options);

        return $this;
    }
333693
private function publishLanguages($register)
    {
        // read language files from folder
        $langPath = $this->path . '/lang';
        if (!file_exists($langPath)) {
            return;
        }
        $files = [];
        list_files($files, $langPath, ['php'], false);

        // update manifest
        $manifest = $this->getManifest('languages');
        /** @noinspection PhpIncludeInspection */
        $list = file_exists($manifest) ? include $manifest : [];
        $basePathLength = strlen(base_path()) + 1;
        foreach ($files as $file) {
            $locale = basename($file, '.php');
            if ($register) {
                if (!isset($list[$locale])) {
                    $list[$locale] = [];
                }
                $list[$locale][$this->plugin] = substr($file, $basePathLength);
            }
            else {
                if (isset($list[$locale])) {
                    unset($list[$locale][$this->plugin]);
                    if (empty($list[$locale])) {
                        unset($list[$locale]);
                    }
                }
            }
        }
        $this->saveArray($manifest, $list);
    }
272047
public function loadAllFile($folder, $language = "default") {
        $this->folder = $folder;
        $this->language = $language;
		
        $msg = array();
        if($language == "default")
            @include($folder."message.php");
        else
        @include($folder."message_".$language.".php");

        /*
         * Some OSes don't distinguish between empty array and FALSE (they may return FALSE in case of no match),
         * therefore the foreach may trigger a Warning even if there is no error
         */
        $ressourceFiles = glob($folder."message_custom_".$language."_*.php");
        if ($ressourceFiles){
            foreach ($ressourceFiles as $filename) {
                @include($filename);
            }
        }

        $this->msg = $msg;
    }
738807
static Map<String,String> loadContent( String lang ) {

		Map<String,String> result = new LinkedHashMap<> ();
		try {
			InputStream in = TranslationBundle.class.getResourceAsStream( "/" + lang + ".json" );
			ByteArrayOutputStream os = new ByteArrayOutputStream();
			Utils.copyStreamSafely( in, os );
			String content = os.toString( "UTF-8" );

			Matcher m = Pattern.compile( ROW_PATTERN ).matcher( content );
			while( m.find()) {

				// Get the value
				String s = m.group( 2 );

				// Replace i18n parameters here (when it makes sense)
				try {
					ErrorCode ec = ErrorCode.valueOf( m.group( 1 ));
					for( int i=0; i<ec.getI18nProperties().length; i++ ) {
						s = s.replace( "{" + i + "}", ec.getI18nProperties()[ i ]);
					}

				} catch( IllegalArgumentException e ) {
					// nothing
				}

				result.put( m.group( 1 ), s );
			}

		} catch( Exception e ) {
			final Logger logger = Logger.getLogger( TranslationBundle.class.getName());
			Utils.logException( logger, e );
		}

		return result;
	}
1066343
protected function load($lang, $path, array $packages)
    {
        // 扫描目录并加载语言包
        foreach ($packages as $package) {
            $file = sprintf('%s/%s.php', $path, str_replace('.', '/', $package));

            // 语言文件不存在
            if (!is_file($file)) {
                continue;
            }

            // 无效语言包
            $return = include $file;
            if (!is_array($return)) {
                continue;
            }

            foreach ($return as $key => $value) {
                $this->imported[$lang][$key] = $value;
            }
        }
    }
266389
public function load($langfile, $lang=null) {

        if (!$lang) {
            $lang = $this->locale;
        }

        if ($path = $this->app->path($langfile)){

            if (!isset($this->_languages[$lang])){
                $this->_languages[$lang] = [];
            }

            $langtable = include($path);

            $this->_languages[$lang] = \array_merge($this->_languages[$lang], (array)$langtable);

            return true;
        }

        return false;
    }
1222096
protected function loadStrings(string $language, string $file): void
	{
		if($this->cache !== null)
		{
			if($this->loadFromCache($language, $file))
			{
				return;
			}

			$this->rebuildCache = true;
		}

		$this->strings[$language][$file] = $this->loader->loadStrings($language, $file);
	}
141
private function getTranslationGroups($lang = 'en'): void
    {
        $dir = resource_path('lang/'. $lang . '/');
        $files = array_diff(scandir($dir), array('..', '.'));

        foreach($files as $index => $filename){
            $groupname = str_replace(".php", "", $filename);
            $this->updateTranslationGroups($groupname);
        }

    }
1171092
public static function mergeFlags(Translation $from, Translation $to, $options = self::DEFAULTS)
    {
        if ($options & self::FLAGS_THEIRS) {
            $to->deleteFlags();
        }

        if (!($options & self::FLAGS_OURS)) {
            foreach ($from->getFlags() as $flag) {
                $to->addFlag($flag);
            }
        }
    }
1162194
function addLanguage($languageKey, $content) {
        //If the langage exists and it's an array, add to it instead of replacing it.
        if (is_array($this->getLanguage($languageKey))) {
            $this->languages[$languageKey][] = $content[0];
            return;
        }
        $this->languages[$languageKey] = $content;
        return $this;
    }
997588
public function setupLocalization(LocalizablePackageInterface $package, $locale = null, $translator = 'current')
    {
        if ($translator === 'current') {
            $translator = $this->localization->getActiveTranslateObject();
        }
        if (is_object($translator)) {
            $locale = (string) $locale;
            if ($locale === '') {
                $locale = $this->localization->getLocale();
            }
            $languageFile = $package->getTranslationFile($locale);
            if (is_file($languageFile)) {
                $translator->addTranslationFile('gettext', $languageFile);
            }
        }
    }
157689
private function translateWithLang($key, $lang) {
        if (!isset($this->translations[$lang]) || !isset($this->translations[$lang][$key])) {
            return null;
        }

        return $this->translations[$lang][$key];
    }
37471
public function mergeWith(Translations $translations, $options = Merge::DEFAULTS)
    {
        Merge::mergeHeaders($translations, $this, $options);
        Merge::mergeTranslations($translations, $this, $options);

        return $this;
    }
53668
public function add_entry_or_merge($entry)
    {
        if (is_array($entry)) {
            $entry = new EntryTranslations($entry);
        }
        $key = $entry->key();
        if (false === $key) {
            return false;
        }
        if (isset($this->entries[$key])) {
            $this->entries[$key]->merge_with($entry);
        } else {
            $this->entries[$key] = &$entry;
        }

        return true;
    }
226861
public function setLanguage($lang)
    {
        $this->clearCachedValueIf($this->lang != $lang);
        $this->lang = $lang;
    }
266062
public function mergeTranslations(LocaleContract $locale = null, array $ignored = [])
    {
        $merged       = [];
        $translations = array_merge(
            is_null($locale) ? [] : $locale->getTranslations(),
            $this->getTranslations()
        );

        foreach ($translations as $key => $trans) {
            if ( ! Str::startsWith($key, $ignored)) {
                $merged[$key] = $trans;
            }
        }

        return $merged;
    }