php-i18n icon indicating copy to clipboard operation
php-i18n copied to clipboard

Forced Lang

Open JordanMontel opened this issue 6 years ago • 1 comments

The documentation says :

$i18n->setForcedLang('en'); // force english, even if another user language is available

But in i18n.class.php the variable $forcedLang is never used.

Maybe in the init() function you should test if this variable is not null ? And use it if the user set it ?

Something like

        // search for language file
        $this->appliedLang = NULL;
        if ($this->forcedLang == NULL) {
            foreach ($this->userLangs as $priority => $langcode) {
                $this->langFilePath = $this->getConfigFilename($langcode);
                if (file_exists($this->langFilePath)) {
                    $this->appliedLang = $langcode;
                    break;
                }
            }
        } else {
            $this->langFilePath = $this->getConfigFilename($this->forcedLang);
            if (file_exists($this->langFilePath)) {
                $this->appliedLang = $this->forcedLang;
            }
        }

JordanMontel avatar Jul 16 '18 13:07 JordanMontel

If a forced language is set, then the getUserLangs method should include it in its return value and the forced language should be tried first. However, if the forced language does not exist, then the next choice will be tried. Maybe this is a bit unintuitive. Does the language file for the forced language exist?

Philipp15b avatar Aug 18 '18 08:08 Philipp15b