mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
MINOR Fixed tests related to i18nLegacyAdapter changes
This commit is contained in:
parent
f61dbfda09
commit
d57e864110
@ -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 @@ class i18n extends Object implements TemplateGlobalProvider {
|
||||
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 @@ class i18n extends Object implements TemplateGlobalProvider {
|
||||
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)
|
||||
|
@ -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'])) {
|
||||
|
@ -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'])) {
|
||||
|
@ -30,7 +30,7 @@ class i18nSSLegacyAdapterTest extends SapphireTest {
|
||||
// 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,
|
||||
));
|
||||
|
@ -349,9 +349,18 @@ class i18nTest extends SapphireTest {
|
||||
// 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 @@ class i18nTest extends SapphireTest {
|
||||
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 @@ class i18nTest extends SapphireTest {
|
||||
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 @@ class i18nTest extends SapphireTest {
|
||||
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'
|
||||
);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user