From f8ead3efacf2a617c40f08f3c4cb999c574d1e8e Mon Sep 17 00:00:00 2001 From: "renan.saddam" Date: Thu, 30 Oct 2008 03:10:40 +0000 Subject: [PATCH] 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 --- cake/libs/l10n.php | 28 +++++++--------------------- cake/tests/cases/libs/l10n.test.php | 14 ++++++++++++++ 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/cake/libs/l10n.php b/cake/libs/l10n.php index 0c139181c..3cf961405 100644 --- a/cake/libs/l10n.php +++ b/cake/libs/l10n.php @@ -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; diff --git a/cake/tests/cases/libs/l10n.test.php b/cake/tests/cases/libs/l10n.test.php index 584e518f2..92a868b30 100644 --- a/cake/tests/cases/libs/l10n.test.php +++ b/cake/tests/cases/libs/l10n.test.php @@ -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; } /**