示例#1
0
文件: LocaleTest.php 项目: titon/g11n
 /**
  * Test that the locale meta data is parsed correctly.
  * If the bundle has a parent, also test that the values between the two are merged correctly.
  */
 public function testGetLocale()
 {
     $parent = $this->parent->allConfig();
     $formats = $this->formats->allConfig();
     $inflections = $this->inflections->allConfig();
     $validations = $this->validations->allConfig();
     // Parent
     $this->assertTrue(is_array($parent));
     $this->assertArraysEqual(['code' => 'ex', 'language' => 'ex', 'iso2' => 'ex', 'iso3' => 'exp', 'timezone' => '', 'title' => 'Example Parent', 'initialize' => false], $parent);
     // Formats
     $this->assertTrue(is_array($formats));
     $this->assertArraysEqual(['code' => 'ex_FM', 'language' => 'ex', 'region' => 'FM', 'iso2' => 'ex', 'iso3' => ['exf', 'frm'], 'timezone' => '', 'title' => 'Example for Formats', 'parent' => 'ex', 'initialize' => false], $formats);
     // Inflections
     $this->assertTrue(is_array($inflections));
     $this->assertArraysEqual(['code' => 'ex_IN', 'language' => 'ex', 'region' => 'IN', 'iso2' => 'ex', 'iso3' => 'inf', 'timezone' => '', 'title' => 'Example for Inflections', 'parent' => 'ex', 'initialize' => false], $inflections);
     // Validations
     $this->assertTrue(is_array($validations));
     $this->assertArraysEqual(['code' => 'ex_VA', 'language' => 'ex', 'region' => 'VA', 'iso2' => 'ex', 'iso3' => 'val', 'timezone' => '', 'title' => 'Example for Validations', 'parent' => 'ex', 'initialize' => false], $validations);
     // By key
     $this->assertEquals('ex', $this->parent->getConfig('code'));
     $this->assertEquals('ex', $this->parent->getConfig('iso2'));
     $this->assertEquals('exp', $this->parent->getConfig('iso3'));
     $this->assertEquals('', $this->parent->getConfig('timezone'));
     try {
         $this->parent->getConfig('fakeKey');
         $this->assertTrue(false);
     } catch (Exception $e) {
         $this->assertTrue(true);
     }
 }
示例#2
0
文件: Locale.php 项目: titon/g11n
 /**
  * Return the parent locale if it exists.
  *
  * @uses Titon\G11n\Locale
  *
  * @return \Titon\G11n\Locale
  */
 public function getParentLocale()
 {
     if ($this->_parent) {
         return $this->_parent;
     }
     if (!$this->hasConfig('parent')) {
         return null;
     }
     $parent = new Locale($this->getConfig('parent'));
     $parent->initialize();
     // Merge parent config
     $this->addConfig($this->allConfig() + $parent->allConfig());
     $this->_parent = $parent;
     return $parent;
 }