Handling non-expected locale and removing duplicated code block. Fixes #5671.

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7801 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
renan.saddam 2008-10-30 03:10:40 +00:00
parent 53296d975c
commit f8ead3efac
2 changed files with 21 additions and 21 deletions

View file

@ -405,28 +405,14 @@ class L10n extends Object {
}
if (isset($this->__l10nCatalog[$langKey])) {
$this->language = $this->__l10nCatalog[$langKey]['language'];
$this->languagePath = array(
$this->__l10nCatalog[$langKey]['locale'],
$this->__l10nCatalog[$langKey]['localeFallback']
);
$this->lang = $langKey;
$this->locale = $this->__l10nCatalog[$langKey]['locale'];
$this->charset = $this->__l10nCatalog[$langKey]['charset'];
if ($this->default) {
if (isset($this->__l10nMap[$this->default]) && isset($this->__l10nCatalog[$this->__l10nMap[$this->default]])) {
$this->languagePath[] = $this->__l10nCatalog[$this->__l10nMap[$this->default]]['localeFallback'];
} else if (isset($this->__l10nCatalog[$this->default])) {
$this->languagePath[] = $this->__l10nCatalog[$this->default]['localeFallback'];
}
}
$this->found = true;
Configure::write('Config.language', $this->lang);
Configure::write('charset', $this->charset);
$this->__setLanguage($langKey);
return true;
} else if (strpos($langKey, '-') !== false) {
$langKey = substr($langKey, 0, 2);
if (isset($this->__l10nCatalog[$langKey])) {
$this->__setLanguage($langKey);
return true;
}
}
}
return false;

View file

@ -154,6 +154,20 @@ class L10nTest extends CakeTestCase {
$expected = 'es_mx';
$this->assertEqual($result, $expected);
$_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'en_xy,en_ca';
$l10n->get();
$result = $l10n->language;
$expected = 'English';
$this->assertEqual($result, $expected);
$result = $l10n->languagePath;
$expected = array('eng', 'eng', 'eng');
$this->assertEqual($result, $expected);
$result = $l10n->locale;
$expected = 'eng';
$this->assertEqual($result, $expected);
$_SERVER = $__SERVER;
}
/**