Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Ensure L10n::get() consistently returns the set language. Closes #2737

  • Loading branch information...
commit 1949a20b5ae8613e3b531ba0c467ff26282fcff9 1 parent 35b48c2
@ADmad ADmad authored
Showing with 13 additions and 6 deletions.
  1. +5 −2 lib/Cake/I18n/L10n.php
  2. +8 −4 lib/Cake/Test/Case/I18n/L10nTest.php
View
7 lib/Cake/I18n/L10n.php
@@ -343,9 +343,12 @@ public function __construct() {
public function get($language = null) {
if ($language !== null) {
return $this->_setLanguage($language);
- } elseif ($this->_autoLanguage() === false) {
- return $this->_setLanguage();
}
+
+ if (!$this->_autoLanguage()) {
+ $this->_setLanguage();
+ }
+ return $this->lang;
}
/**
View
12 lib/Cake/Test/Case/I18n/L10nTest.php
@@ -34,8 +34,9 @@ public function testGet() {
$localize = new L10n();
// Catalog Entry
- $localize->get('en');
+ $lang = $localize->get('en');
+ $this->assertEquals('en', $lang);
$this->assertEquals('English', $localize->language);
$this->assertEquals(array('eng', 'eng'), $localize->languagePath);
$this->assertEquals('eng', $localize->locale);
@@ -57,8 +58,9 @@ public function testGet() {
// Default Entry
define('DEFAULT_LANGUAGE', 'en-us');
- $localize->get('use_default');
+ $lang = $localize->get('use_default');
+ $this->assertEquals('en-us', $lang);
$this->assertEquals('English (United States)', $localize->language);
$this->assertEquals(array('en_us', 'eng'), $localize->languagePath);
$this->assertEquals('en_us', $localize->locale);
@@ -86,15 +88,17 @@ public function testGetAutoLanguage() {
$_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'inexistent,en-ca';
$localize = new L10n();
- $localize->get();
+ $lang = $localize->get();
+ $this->assertEquals('en-ca', $lang);
$this->assertEquals('English (Canadian)', $localize->language);
$this->assertEquals(array('en_ca', 'eng', 'eng'), $localize->languagePath);
$this->assertEquals('en_ca', $localize->locale);
$_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'es_mx';
- $localize->get();
+ $lang = $localize->get();
+ $this->assertEquals('es-mx', $lang);
$this->assertEquals('Spanish (Mexican)', $localize->language);
$this->assertEquals(array('es_mx', 'spa', 'eng'), $localize->languagePath);
$this->assertEquals('es_mx', $localize->locale);
Please sign in to comment.
Something went wrong with that request. Please try again.