Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

MINOR Fixed tests related to i18nLegacyAdapter changes

  • Loading branch information...
commit d57e864110e96112774b5c796cf66cf8eb8b5497 1 parent f61dbfd
@chillu chillu authored
View
6 i18n/i18n.php
@@ -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.
@@ -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)
@@ -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)
View
2  tests/i18n/_fakewebroot/i18nothermodule/lang/de_DE.php
@@ -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'])) {
View
2  tests/i18n/_fakewebroot/themes/testtheme1/lang/de_DE.php
@@ -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'])) {
View
2  tests/i18n/i18nSSLegacyAdapterTest.php
@@ -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,
));
View
19 tests/i18n/i18nTest.php
@@ -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"'
@@ -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'
);
@@ -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'
);
@@ -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'
);
Please sign in to comment.
Something went wrong with that request. Please try again.