php-i18n
php-i18n copied to clipboard
Forced Lang
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;
}
}
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?