Elgg\I18n\Translator::loadTranslations PHP Method

loadTranslations() public method

By default this loads only English and the language of the logged in user. The optional $language argument can be used to load translations on-demand in case we need to translate something to a language not loaded by default for the current request.
public loadTranslations ( string $language = null )
$language string Language code
    public function loadTranslations($language = null)
    {
        if (elgg_is_system_cache_enabled()) {
            $loaded = true;
            if ($language) {
                $languages = array($language);
            } else {
                $languages = array_unique(array('en', $this->getCurrentLanguage()));
            }
            foreach ($languages as $language) {
                $data = elgg_load_system_cache("{$language}.lang");
                if ($data) {
                    $this->addTranslation($language, unserialize($data));
                } else {
                    $loaded = false;
                }
            }
            if ($loaded) {
                $GLOBALS['_ELGG']->i18n_loaded_from_cache = true;
                // this is here to force
                $GLOBALS['_ELGG']->language_paths[$this->defaultPath] = true;
                return;
            }
        }
        // load core translations from languages directory
        $this->registerTranslations($this->defaultPath, false, $language);
        // Plugin translation have already been loaded for the default
        // languages by ElggApplication::bootCore(), so there's no need
        // to continue unless loading a specific language on-demand
        if ($language) {
            $this->loadPluginTranslations($language);
        }
    }