Skip to content

Commit

Permalink
MINOR Fixed tests related to i18nLegacyAdapter changes
Browse files Browse the repository at this point in the history
  • Loading branch information
chillu committed Apr 15, 2012
1 parent f61dbfd commit d57e864
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 12 deletions.
6 changes: 4 additions & 2 deletions i18n/i18n.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
require_once 'Zend/Translate.php';
require_once 'i18nRailsYamlAdapter.php';
require_once 'i18nSSLegacyAdapter.php';

/**
* Base-class for storage and retrieval of translated entities.
Expand Down Expand Up @@ -1475,11 +1476,11 @@ static function _t($entity, $string = "", $context = "") {
foreach($translators as $name => $translator) {
$adapter = $translator->getAdapter();

// if language table isn't loaded for this locale, get it for each of the modules
// If language table isn't loaded for this locale, get it for each of the modules.
// The method will automatically load fallback languages (the lang for a locale).
if(!$adapter->isAvailable($locale) && !$adapter->isAvailable($lang)) {
i18n::include_by_locale($locale);
}

$translation = $adapter->translate($entity, $locale);

// Return translation only if we found a match thats not the entity itself (Zend fallback)
Expand Down Expand Up @@ -1904,6 +1905,7 @@ function($a, $b) use(&$prios) {
foreach($selectedLocales as $selectedLocale) {
$filename = $adapter->getFilenameForLocale($selectedLocale);
$filepath = "{$module}/lang/" . $filename;

if($filename && !file_exists($filepath)) continue;
$adapter->addTranslation(
array('content' => $filepath, 'locale' => $selectedLocale)
Expand Down
2 changes: 0 additions & 2 deletions tests/i18n/_fakewebroot/i18nothermodule/lang/de_DE.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php

i18n::include_locale_file('i18nothermodule', 'en_US');

global $lang;

if(array_key_exists('de_DE', $lang) && is_array($lang['de_DE'])) {
Expand Down
2 changes: 0 additions & 2 deletions tests/i18n/_fakewebroot/themes/testtheme1/lang/de_DE.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php

i18n::include_locale_file('i18nothermodule', 'en_US');

global $lang;

if(array_key_exists('de_DE', $lang) && is_array($lang['de_DE'])) {
Expand Down
2 changes: 1 addition & 1 deletion tests/i18n/i18nSSLegacyAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function setUp() {
// Emulates behaviour in i18n::get_translators()
$this->origAdapter = i18n::get_translator('core');
$adapter = new Zend_Translate(array(
'adapter' => 'i18nRailsYamlAdapter',
'adapter' => 'i18nSSLegacyAdapter',
'locale' => i18n::default_locale(),
'disableNotices' => true,
));
Expand Down
19 changes: 14 additions & 5 deletions tests/i18n/i18nTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -349,9 +349,18 @@ function testMultipleTranslators() {
// Load non-exclusive to retain core class autoloading
$classManifest = new SS_ClassManifest($this->alternateBasePath, true, true, false);
SS_ClassLoader::instance()->pushManifest($classManifest);

// Changed manifest, so we also need to unset all previously collected messages.
// The easiest way to do this it to register a new adapter.
$adapter = new Zend_Translate(array(
'adapter' => 'i18nRailsYamlAdapter',
'locale' => i18n::default_locale(),
'disableNotices' => true,
));
i18n::register_translator($adapter, 'core');

i18n::set_locale('en_US');

$this->assertEquals(
i18n::_t('i18nTestModule.ENTITY'),
'Entity with "Double Quotes"'
Expand All @@ -370,12 +379,12 @@ function testMultipleTranslators() {
i18n::register_translator($translator, 'custom', 11);
$this->assertEquals(
i18n::_t('i18nTestModule.ENTITY'),
'i18nTestModule.ENTITY CustomAdapter (en_US)',
'i18nTestModule.ENTITY CustomAdapter (en)',
'Existing entities overruled by adapter with higher priority'
);
$this->assertEquals(
i18n::_t('AdapterEntity1', 'AdapterEntity1'),
'AdapterEntity1 CustomAdapter (en_US)',
'AdapterEntity1 CustomAdapter (en)',
'New entities only defined in new adapter are detected'
);

Expand All @@ -387,7 +396,7 @@ function testMultipleTranslators() {
i18n::register_translator($translator, 'othercustom_lower_prio', 5);
$this->assertEquals(
i18n::_t('i18nTestModule.ENTITY'),
'i18nTestModule.ENTITY CustomAdapter (en_US)',
'i18nTestModule.ENTITY CustomAdapter (en)',
'Adapter with lower priority loses'
);

Expand All @@ -399,7 +408,7 @@ function testMultipleTranslators() {
i18n::register_translator($translator, 'othercustom_higher_prio', 15);
$this->assertEquals(
i18n::_t('i18nTestModule.ENTITY'),
'i18nTestModule.ENTITY OtherCustomAdapter (en_US)',
'i18nTestModule.ENTITY OtherCustomAdapter (en)',
'Adapter with higher priority wins'
);

Expand Down

0 comments on commit d57e864

Please sign in to comment.