2008-03-20 04:00:49 +01:00
|
|
|
<?php
|
2016-06-15 06:03:16 +02:00
|
|
|
|
|
|
|
use SilverStripe\ORM\DataObject;
|
2011-11-26 14:34:11 +01:00
|
|
|
require_once 'Zend/Translate.php';
|
|
|
|
|
2008-06-15 15:33:53 +02:00
|
|
|
/**
|
2012-04-12 08:02:46 +02:00
|
|
|
* @package framework
|
2008-06-15 15:33:53 +02:00
|
|
|
* @subpackage tests
|
|
|
|
*/
|
2008-03-20 04:00:49 +01:00
|
|
|
class i18nTest extends SapphireTest {
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2008-11-06 03:50:14 +01:00
|
|
|
/**
|
|
|
|
* @var string $tmpBasePath Used to write language files.
|
2012-03-24 04:38:57 +01:00
|
|
|
* We don't want to store them inside framework (or in any web-accessible place)
|
2008-11-06 03:50:14 +01:00
|
|
|
* in case something goes wrong with the file parsing.
|
|
|
|
*/
|
|
|
|
protected $alternateBaseSavePath;
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2008-11-06 03:50:14 +01:00
|
|
|
/**
|
|
|
|
* @var string $alternateBasePath Fake webroot with a single module
|
|
|
|
* /i18ntestmodule which contains some files with _t() calls.
|
|
|
|
*/
|
|
|
|
protected $alternateBasePath;
|
2010-04-12 04:03:16 +02:00
|
|
|
|
|
|
|
protected $extraDataObjects = array(
|
|
|
|
'i18nTest_DataObject'
|
|
|
|
);
|
|
|
|
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function setUp() {
|
2008-11-06 03:50:14 +01:00
|
|
|
parent::setUp();
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2013-10-03 03:49:18 +02:00
|
|
|
$this->alternateBasePath = $this->getCurrentAbsolutePath() . DIRECTORY_SEPARATOR . "_fakewebroot";
|
|
|
|
$this->alternateBaseSavePath = TEMP_FOLDER . DIRECTORY_SEPARATOR . 'i18nTextCollectorTest_webroot';
|
2008-11-06 03:50:14 +01:00
|
|
|
FileSystem::makeFolder($this->alternateBaseSavePath);
|
2013-03-21 19:48:54 +01:00
|
|
|
Config::inst()->update('Director', 'alternate_base_folder', $this->alternateBasePath);
|
2008-11-06 03:50:14 +01:00
|
|
|
|
2011-03-23 04:43:50 +01:00
|
|
|
// Push a template loader running from the fake webroot onto the stack.
|
2012-11-02 08:28:39 +01:00
|
|
|
$templateManifest = new SS_TemplateManifest($this->alternateBasePath, null, false, true);
|
2011-11-26 14:34:11 +01:00
|
|
|
$templateManifest->regenerate(false);
|
|
|
|
SS_TemplateLoader::instance()->pushManifest($templateManifest);
|
2013-03-21 19:48:54 +01:00
|
|
|
$this->_oldTheme = Config::inst()->get('SSViewer', 'theme');
|
|
|
|
Config::inst()->update('SSViewer', 'theme', 'testtheme1');
|
2011-03-23 04:43:50 +01:00
|
|
|
|
2010-10-15 05:23:02 +02:00
|
|
|
$this->originalLocale = i18n::get_locale();
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2011-11-26 14:34:11 +01:00
|
|
|
// Override default adapter to avoid cached translations between tests.
|
|
|
|
// Emulates behaviour in i18n::get_translators()
|
|
|
|
$this->origAdapter = i18n::get_translator('core');
|
|
|
|
$adapter = new Zend_Translate(array(
|
|
|
|
'adapter' => 'i18nRailsYamlAdapter',
|
|
|
|
'locale' => i18n::default_locale(),
|
|
|
|
'disableNotices' => true,
|
|
|
|
));
|
|
|
|
i18n::register_translator($adapter, 'core');
|
|
|
|
$adapter->removeCache();
|
|
|
|
i18n::include_by_locale('en');
|
2008-11-06 03:50:14 +01:00
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function tearDown() {
|
2011-03-23 04:43:50 +01:00
|
|
|
SS_TemplateLoader::instance()->popManifest();
|
2010-10-15 05:23:02 +02:00
|
|
|
i18n::set_locale($this->originalLocale);
|
2013-03-21 19:48:54 +01:00
|
|
|
Config::inst()->update('Director', 'alternate_base_folder', null);
|
|
|
|
Config::inst()->update('SSViewer', 'theme', $this->_oldTheme);
|
2011-11-26 14:34:11 +01:00
|
|
|
i18n::register_translator($this->origAdapter, 'core');
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2008-12-04 23:38:32 +01:00
|
|
|
parent::tearDown();
|
2008-11-06 03:50:14 +01:00
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testGetExistingTranslations() {
|
2008-03-20 04:00:49 +01:00
|
|
|
$translations = i18n::get_existing_translations();
|
2013-08-20 14:07:07 +02:00
|
|
|
$this->assertTrue(isset($translations['en_US']), 'Checking for en translation');
|
|
|
|
$this->assertEquals($translations['en_US'], 'English (United States)');
|
|
|
|
$this->assertTrue(isset($translations['de_DE']), 'Checking for de_DE translation');
|
2008-03-20 04:00:49 +01:00
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2014-01-30 03:55:14 +01:00
|
|
|
public function testGetClosestTranslation() {
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2014-01-30 03:55:14 +01:00
|
|
|
// Validate necessary assumptions for this test
|
|
|
|
$translations = i18n::get_existing_translations();
|
|
|
|
$this->assertTrue(isset($translations['en_US']));
|
|
|
|
$this->assertTrue(isset($translations['en_GB']));
|
|
|
|
$this->assertTrue(isset($translations['es_ES']));
|
|
|
|
$this->assertTrue(isset($translations['es_AR']));
|
|
|
|
$this->assertFalse(isset($translations['en_ZZ']));
|
|
|
|
$this->assertFalse(isset($translations['es_ZZ']));
|
|
|
|
$this->assertFalse(isset($translations['zz_ZZ']));
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2014-01-30 03:55:14 +01:00
|
|
|
// Test indeterminate locales
|
|
|
|
$this->assertEmpty(i18n::get_closest_translation('zz_ZZ'));
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2014-01-30 03:55:14 +01:00
|
|
|
// Test english fallback
|
|
|
|
$this->assertEquals('en_US', i18n::get_closest_translation('en_US'));
|
|
|
|
$this->assertEquals('en_GB', i18n::get_closest_translation('en_GB'));
|
|
|
|
$this->assertEquals('en_US', i18n::get_closest_translation('en_ZZ'));
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2014-01-30 03:55:14 +01:00
|
|
|
// Test spanish fallbacks
|
|
|
|
$this->assertEquals('es_AR', i18n::get_closest_translation('es_AR'));
|
|
|
|
$this->assertEquals('es_ES', i18n::get_closest_translation('es_ES'));
|
|
|
|
$this->assertEquals('es_ES', i18n::get_closest_translation('es_XX'));
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testDataObjectFieldLabels() {
|
2008-10-29 22:07:17 +01:00
|
|
|
$oldLocale = i18n::get_locale();
|
|
|
|
i18n::set_locale('de_DE');
|
2008-11-01 14:26:08 +01:00
|
|
|
$obj = new i18nTest_DataObject();
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2011-11-26 14:34:11 +01:00
|
|
|
i18n::get_translator('core')->getAdapter()->addTranslation(array(
|
|
|
|
'i18nTest_DataObject.MyProperty' => 'MyProperty'
|
|
|
|
), 'en_US');
|
|
|
|
i18n::get_translator('core')->getAdapter()->addTranslation(array(
|
|
|
|
'i18nTest_DataObject.MyProperty' => 'Mein Attribut'
|
|
|
|
), 'de_DE');
|
|
|
|
|
2008-10-29 22:07:17 +01:00
|
|
|
$this->assertEquals(
|
|
|
|
$obj->fieldLabel('MyProperty'),
|
|
|
|
'Mein Attribut'
|
|
|
|
);
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2011-11-26 14:34:11 +01:00
|
|
|
i18n::get_translator('core')->getAdapter()->addTranslation(array(
|
|
|
|
'i18nTest_DataObject.MyUntranslatedProperty' => 'Mein Attribut'
|
|
|
|
), 'en_US');
|
2008-10-29 22:07:17 +01:00
|
|
|
$this->assertEquals(
|
|
|
|
$obj->fieldLabel('MyUntranslatedProperty'),
|
|
|
|
'My Untranslated Property'
|
|
|
|
);
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2008-10-29 22:07:17 +01:00
|
|
|
i18n::set_locale($oldLocale);
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testProvideI18nEntities() {
|
2008-11-01 14:26:08 +01:00
|
|
|
$oldLocale = i18n::get_locale();
|
|
|
|
i18n::set_locale('en_US');
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2011-11-26 14:34:11 +01:00
|
|
|
i18n::get_translator('core')->getAdapter()->addTranslation(array(
|
|
|
|
'i18nTest_Object.MyProperty' => 'Untranslated'
|
|
|
|
), 'en_US');
|
|
|
|
i18n::get_translator('core')->getAdapter()->addTranslation(array(
|
|
|
|
'i18nTest_Object.my_translatable_property' => 'Übersetzt'
|
|
|
|
), 'de_DE');
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2008-11-01 14:26:08 +01:00
|
|
|
$this->assertEquals(
|
|
|
|
i18nTest_Object::$my_translatable_property,
|
|
|
|
'Untranslated'
|
|
|
|
);
|
|
|
|
$this->assertEquals(
|
|
|
|
i18nTest_Object::my_translatable_property(),
|
|
|
|
'Untranslated'
|
|
|
|
);
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2008-11-01 14:26:08 +01:00
|
|
|
i18n::set_locale('en_US');
|
|
|
|
$this->assertEquals(
|
|
|
|
i18nTest_Object::my_translatable_property(),
|
|
|
|
'Untranslated',
|
|
|
|
'Getter returns original static value when called in default locale'
|
|
|
|
);
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2008-11-01 14:26:08 +01:00
|
|
|
i18n::set_locale('de_DE');
|
|
|
|
$this->assertEquals(
|
|
|
|
i18nTest_Object::my_translatable_property(),
|
|
|
|
'Übersetzt',
|
|
|
|
'Getter returns translated value when called in another locale'
|
|
|
|
);
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testTemplateTranslation() {
|
2008-11-06 03:50:14 +01:00
|
|
|
$oldLocale = i18n::get_locale();
|
2011-04-12 05:11:33 +02:00
|
|
|
|
2008-11-06 03:50:14 +01:00
|
|
|
i18n::set_locale('en_US');
|
2011-11-26 14:34:11 +01:00
|
|
|
i18n::get_translator('core')->getAdapter()->addTranslation(array(
|
|
|
|
'i18nTestModule.MAINTEMPLATE' => 'Main Template',
|
2012-04-18 03:21:07 +02:00
|
|
|
'i18nTestModule.ss.SPRINTFNONAMESPACE' => 'My replacement no namespace: %s',
|
2011-11-26 14:34:11 +01:00
|
|
|
'i18nTestModule.LAYOUTTEMPLATE' => 'Layout Template',
|
2012-04-18 03:21:07 +02:00
|
|
|
'i18nTestModule.ss.LAYOUTTEMPLATENONAMESPACE' => 'Layout Template no namespace',
|
2011-11-26 14:34:11 +01:00
|
|
|
'i18nTestModule.SPRINTFNAMESPACE' => 'My replacement: %s',
|
|
|
|
'i18nTestModule.WITHNAMESPACE' => 'Include Entity with Namespace',
|
2012-04-18 03:21:07 +02:00
|
|
|
'i18nTestModuleInclude.ss.NONAMESPACE' => 'Include Entity without Namespace',
|
2011-11-26 14:34:11 +01:00
|
|
|
'i18nTestModuleInclude.ss.SPRINTFINCLUDENAMESPACE' => 'My include replacement: %s',
|
2012-04-18 03:21:07 +02:00
|
|
|
'i18nTestModuleInclude.ss.SPRINTFINCLUDENONAMESPACE' => 'My include replacement no namespace: %s'
|
2011-11-26 14:34:11 +01:00
|
|
|
), 'en_US');
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2008-11-06 03:50:14 +01:00
|
|
|
$viewer = new SSViewer('i18nTestModule');
|
2013-10-03 03:49:18 +02:00
|
|
|
$parsedHtml = Convert::nl2os($viewer->process(new ArrayData(array('TestProperty' => 'TestPropertyValue'))));
|
2008-11-06 03:50:14 +01:00
|
|
|
$this->assertContains(
|
2013-10-03 03:49:18 +02:00
|
|
|
Convert::nl2os("Layout Template\n"),
|
2008-11-06 03:50:14 +01:00
|
|
|
$parsedHtml
|
|
|
|
);
|
2012-04-18 03:21:07 +02:00
|
|
|
$this->assertContains(
|
2013-10-03 03:49:18 +02:00
|
|
|
Convert::nl2os("Layout Template no namespace\n"),
|
2012-04-18 03:21:07 +02:00
|
|
|
$parsedHtml
|
|
|
|
);
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2008-11-06 03:50:14 +01:00
|
|
|
i18n::set_locale('de_DE');
|
2011-11-26 14:34:11 +01:00
|
|
|
i18n::get_translator('core')->getAdapter()->addTranslation(array(
|
|
|
|
'i18nTestModule.MAINTEMPLATE' => 'TRANS Main Template',
|
2012-04-18 03:21:07 +02:00
|
|
|
'i18nTestModule.ss.SPRINTFNONAMESPACE' => 'TRANS My replacement no namespace: %s',
|
2011-11-26 14:34:11 +01:00
|
|
|
'i18nTestModule.LAYOUTTEMPLATE' => 'TRANS Layout Template',
|
2012-04-18 03:21:07 +02:00
|
|
|
'i18nTestModule.ss.LAYOUTTEMPLATENONAMESPACE' => 'TRANS Layout Template no namespace',
|
2011-11-26 14:34:11 +01:00
|
|
|
'i18nTestModule.SPRINTFNAMESPACE' => 'TRANS My replacement: %s',
|
|
|
|
'i18nTestModule.WITHNAMESPACE' => 'TRANS Include Entity with Namespace',
|
2012-04-18 03:21:07 +02:00
|
|
|
'i18nTestModuleInclude.ss.NONAMESPACE' => 'TRANS Include Entity without Namespace',
|
2011-11-26 14:34:11 +01:00
|
|
|
'i18nTestModuleInclude.ss.SPRINTFINCLUDENAMESPACE' => 'TRANS My include replacement: %s',
|
2012-04-18 03:21:07 +02:00
|
|
|
'i18nTestModuleInclude.ss.SPRINTFINCLUDENONAMESPACE' => 'TRANS My include replacement no namespace: %s'
|
2011-11-26 14:34:11 +01:00
|
|
|
), 'de_DE');
|
|
|
|
|
2008-11-06 03:50:14 +01:00
|
|
|
$viewer = new SSViewer('i18nTestModule');
|
2013-10-03 03:49:18 +02:00
|
|
|
$parsedHtml = Convert::nl2os($viewer->process(new ArrayData(array('TestProperty' => 'TestPropertyValue'))));
|
2008-11-06 03:50:14 +01:00
|
|
|
$this->assertContains(
|
2013-10-03 03:49:18 +02:00
|
|
|
Convert::nl2os("TRANS Main Template\n"),
|
2008-11-06 03:50:14 +01:00
|
|
|
$parsedHtml
|
|
|
|
);
|
|
|
|
$this->assertContains(
|
2013-10-03 03:49:18 +02:00
|
|
|
Convert::nl2os("TRANS Layout Template\n"),
|
2008-11-06 03:50:14 +01:00
|
|
|
$parsedHtml
|
|
|
|
);
|
2012-04-18 03:21:07 +02:00
|
|
|
$this->assertContains(
|
2013-10-03 03:49:18 +02:00
|
|
|
Convert::nl2os("TRANS Layout Template no namespace\n"),
|
2012-04-18 03:21:07 +02:00
|
|
|
$parsedHtml
|
|
|
|
);
|
2008-11-06 03:50:14 +01:00
|
|
|
$this->assertContains(
|
2013-10-03 03:49:18 +02:00
|
|
|
Convert::nl2os("TRANS My replacement: TestPropertyValue\n"),
|
2008-11-06 03:50:14 +01:00
|
|
|
$parsedHtml
|
|
|
|
);
|
|
|
|
$this->assertContains(
|
2013-10-03 03:49:18 +02:00
|
|
|
Convert::nl2os("TRANS Include Entity with Namespace\n"),
|
2008-11-06 03:50:14 +01:00
|
|
|
$parsedHtml
|
|
|
|
);
|
2012-04-18 03:21:07 +02:00
|
|
|
$this->assertContains(
|
2013-10-03 03:49:18 +02:00
|
|
|
Convert::nl2os("TRANS Include Entity without Namespace\n"),
|
2012-04-18 03:21:07 +02:00
|
|
|
$parsedHtml
|
|
|
|
);
|
2008-11-06 03:50:14 +01:00
|
|
|
$this->assertContains(
|
2013-10-03 03:49:18 +02:00
|
|
|
Convert::nl2os("TRANS My include replacement: TestPropertyValue\n"),
|
2008-11-06 03:50:14 +01:00
|
|
|
$parsedHtml
|
|
|
|
);
|
2012-04-18 03:21:07 +02:00
|
|
|
$this->assertContains(
|
2013-10-03 03:49:18 +02:00
|
|
|
Convert::nl2os("TRANS My include replacement no namespace: TestPropertyValue\n"),
|
2012-04-18 03:21:07 +02:00
|
|
|
$parsedHtml
|
|
|
|
);
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2008-11-06 03:50:14 +01:00
|
|
|
i18n::set_locale($oldLocale);
|
|
|
|
}
|
2011-04-12 05:11:33 +02:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testNewTMethodSignature() {
|
2011-04-12 05:11:33 +02:00
|
|
|
global $lang;
|
|
|
|
$oldLocale = i18n::get_locale();
|
|
|
|
|
|
|
|
i18n::set_locale('en_US');
|
2012-04-16 08:58:42 +02:00
|
|
|
|
|
|
|
i18n::get_translator('core')->getAdapter()->addTranslation(array(
|
|
|
|
'i18nTestModule.NEWMETHODSIG' => 'TRANS New _t method signature test',
|
2012-05-01 20:56:07 +02:00
|
|
|
'i18nTestModule.INJECTIONS' => 'TRANS Hello {name} {greeting}. But it is late, {goodbye}',
|
|
|
|
'i18nTestModule.INJECTIONSLEGACY' => 'TRANS Hello %s %s. But it is late, %s',
|
2012-04-16 08:58:42 +02:00
|
|
|
), 'en_US');
|
2011-04-12 05:11:33 +02:00
|
|
|
|
|
|
|
$entity = "i18nTestModule.INJECTIONS";
|
|
|
|
$default = "Hello {name} {greeting}. But it is late, {goodbye}";
|
|
|
|
|
|
|
|
$translated = i18n::_t('i18nTestModule.NEWMETHODSIG',"New _t method signature test");
|
|
|
|
$this->assertContains(
|
|
|
|
"TRANS New _t method signature test",
|
|
|
|
$translated
|
|
|
|
);
|
|
|
|
|
2012-09-26 23:34:00 +02:00
|
|
|
$translated = i18n::_t($entity.'_DOES_NOT_EXIST', $default,
|
|
|
|
array("name"=>"Mark", "greeting"=>"welcome", "goodbye"=>"bye"));
|
2011-04-12 05:11:33 +02:00
|
|
|
$this->assertContains(
|
|
|
|
"Hello Mark welcome. But it is late, bye",
|
|
|
|
$translated, "Testing fallback to the translation default (but using the injection array)"
|
|
|
|
);
|
|
|
|
|
2012-09-26 23:34:00 +02:00
|
|
|
$translated = i18n::_t($entity, $default,
|
|
|
|
array("name"=>"Paul", "greeting"=>"good you are here", "goodbye"=>"see you"));
|
2011-04-12 05:11:33 +02:00
|
|
|
$this->assertContains(
|
|
|
|
"TRANS Hello Paul good you are here. But it is late, see you",
|
|
|
|
$translated, "Testing entity, default string and injection array"
|
|
|
|
);
|
|
|
|
|
2012-09-26 23:34:00 +02:00
|
|
|
$translated = i18n::_t($entity, $default, "New context (this should be ignored)",
|
|
|
|
array("name"=>"Steffen", "greeting"=>"willkommen", "goodbye"=>"wiedersehen"));
|
2011-04-12 05:11:33 +02:00
|
|
|
$this->assertContains(
|
|
|
|
"TRANS Hello Steffen willkommen. But it is late, wiedersehen",
|
|
|
|
$translated, "Full test of translation, using default, context and injection array"
|
|
|
|
);
|
|
|
|
|
|
|
|
$translated = i18n::_t($entity, array("name"=>"Cat", "greeting"=>"meow", "goodbye"=>"meow"));
|
|
|
|
$this->assertContains(
|
|
|
|
"TRANS Hello Cat meow. But it is late, meow",
|
|
|
|
$translated, "Testing a translation with just entity and injection array"
|
|
|
|
);
|
|
|
|
|
2012-05-01 20:56:07 +02:00
|
|
|
$translated = i18n::_t(
|
|
|
|
'i18nTestModule.INJECTIONSLEGACY', // has %s placeholders
|
|
|
|
array("name"=>"Cat", "greeting2"=>"meow", "goodbye"=>"meow")
|
|
|
|
);
|
|
|
|
$this->assertContains(
|
|
|
|
"TRANS Hello Cat meow. But it is late, meow",
|
|
|
|
$translated, "Testing sprintf placeholders with named injections"
|
|
|
|
);
|
|
|
|
|
2012-12-21 11:46:30 +01:00
|
|
|
$translated = i18n::_t(
|
|
|
|
'i18nTestModule.INJECTIONSLEGACY', // has %s placeholders
|
|
|
|
array("Cat", "meow"/*, "meow" */) // remove third arg
|
|
|
|
);
|
|
|
|
$this->assertContains(
|
|
|
|
"TRANS Hello Cat meow. But it is late, ",
|
|
|
|
$translated, "Testing sprintf placeholders with unnamed injections and too few args"
|
|
|
|
);
|
|
|
|
|
2012-05-01 20:56:07 +02:00
|
|
|
$translated = i18n::_t(
|
|
|
|
'i18nTestModule.INJECTIONS', // has {name} placeholders
|
|
|
|
array("Cat", "meow", "meow")
|
|
|
|
);
|
|
|
|
$this->assertContains(
|
|
|
|
"TRANS Hello Cat meow. But it is late, meow",
|
|
|
|
$translated, "Testing named injection placeholders with unnamed injections"
|
|
|
|
);
|
|
|
|
|
2011-04-12 05:11:33 +02:00
|
|
|
i18n::set_locale($oldLocale);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* See @i18nTestModule.ss for the template that is being used for this test
|
|
|
|
* */
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testNewTemplateTranslation() {
|
2011-04-12 05:11:33 +02:00
|
|
|
global $lang;
|
|
|
|
$oldLocale = i18n::get_locale();
|
|
|
|
|
|
|
|
i18n::set_locale('en_US');
|
2012-04-16 08:58:42 +02:00
|
|
|
i18n::get_translator('core')->getAdapter()->addTranslation(array(
|
|
|
|
'i18nTestModule.NEWMETHODSIG' => 'TRANS New _t method signature test',
|
|
|
|
'i18nTestModule.INJECTIONS' => 'TRANS Hello {name} {greeting}. But it is late, {goodbye}'
|
|
|
|
),'en_US');
|
2011-04-12 05:11:33 +02:00
|
|
|
|
|
|
|
$viewer = new SSViewer('i18nTestModule');
|
2013-10-03 03:49:18 +02:00
|
|
|
$parsedHtml = Convert::nl2os($viewer->process(new ArrayData(array('TestProperty' => 'TestPropertyValue'))));
|
2011-04-12 05:11:33 +02:00
|
|
|
$this->assertContains(
|
2013-10-03 03:49:18 +02:00
|
|
|
Convert::nl2os("Hello Mark welcome. But it is late, bye\n"),
|
2011-04-12 05:11:33 +02:00
|
|
|
$parsedHtml, "Testing fallback to the translation default (but using the injection array)"
|
|
|
|
);
|
2012-04-16 08:58:42 +02:00
|
|
|
|
2011-04-12 05:11:33 +02:00
|
|
|
$this->assertContains(
|
2013-10-03 03:49:18 +02:00
|
|
|
Convert::nl2os("TRANS Hello Paul good you are here. But it is late, see you\n"),
|
2011-04-12 05:11:33 +02:00
|
|
|
$parsedHtml, "Testing entity, default string and injection array"
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertContains(
|
2013-10-03 03:49:18 +02:00
|
|
|
Convert::nl2os("TRANS Hello Cat meow. But it is late, meow\n"),
|
2011-04-12 05:11:33 +02:00
|
|
|
$parsedHtml, "Testing a translation with just entity and injection array"
|
|
|
|
);
|
|
|
|
|
|
|
|
//test injected calls
|
|
|
|
$this->assertContains(
|
2013-10-03 03:49:18 +02:00
|
|
|
Convert::nl2os(
|
|
|
|
"TRANS Hello ".Director::absoluteBaseURL()." ".i18n::get_locale().". But it is late, global calls\n"
|
|
|
|
),
|
2012-09-26 23:34:00 +02:00
|
|
|
$parsedHtml,
|
|
|
|
"Testing a translation with just entity and injection array, but with global variables injected in"
|
2011-04-12 05:11:33 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
i18n::set_locale($oldLocale);
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testGetLocaleFromLang() {
|
2009-04-30 01:15:38 +02:00
|
|
|
$this->assertEquals('en_US', i18n::get_locale_from_lang('en'));
|
|
|
|
$this->assertEquals('de_DE', i18n::get_locale_from_lang('de_DE'));
|
|
|
|
$this->assertEquals('xy_XY', i18n::get_locale_from_lang('xy'));
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testValidateLocale() {
|
2010-12-03 01:27:41 +01:00
|
|
|
$this->assertTrue(i18n::validate_locale('en_US'), 'Known locale in underscore format is valid');
|
|
|
|
$this->assertTrue(i18n::validate_locale('en-US'), 'Known locale in dash format is valid');
|
|
|
|
$this->assertFalse(i18n::validate_locale('en'), 'Short lang format is not valid');
|
|
|
|
$this->assertFalse(i18n::validate_locale('xx_XX'), 'Unknown locale in correct format is not valid');
|
|
|
|
$this->assertFalse(i18n::validate_locale(''), 'Empty string is not valid');
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testTranslate() {
|
2011-11-26 14:34:11 +01:00
|
|
|
$oldLocale = i18n::get_locale();
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2011-11-26 14:34:11 +01:00
|
|
|
i18n::get_translator('core')->getAdapter()->addTranslation(array(
|
|
|
|
'i18nTestModule.ENTITY' => 'Entity with "Double Quotes"',
|
|
|
|
), 'en_US');
|
|
|
|
i18n::get_translator('core')->getAdapter()->addTranslation(array(
|
|
|
|
'i18nTestModule.ENTITY' => 'Entity with "Double Quotes" (de)',
|
|
|
|
'i18nTestModule.ADDITION' => 'Addition (de)',
|
|
|
|
), 'de');
|
|
|
|
i18n::get_translator('core')->getAdapter()->addTranslation(array(
|
|
|
|
'i18nTestModule.ENTITY' => 'Entity with "Double Quotes" (de_AT)',
|
|
|
|
), 'de_AT');
|
2014-08-15 08:53:05 +02:00
|
|
|
|
|
|
|
|
2011-11-26 14:34:11 +01:00
|
|
|
$this->assertEquals(i18n::_t('i18nTestModule.ENTITY'), 'Entity with "Double Quotes"',
|
|
|
|
'Returns translation in default language'
|
|
|
|
);
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2011-11-26 14:34:11 +01:00
|
|
|
i18n::set_locale('de');
|
|
|
|
$this->assertEquals(i18n::_t('i18nTestModule.ENTITY'), 'Entity with "Double Quotes" (de)',
|
|
|
|
'Returns translation according to current locale'
|
|
|
|
);
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2011-11-26 14:34:11 +01:00
|
|
|
i18n::set_locale('de_AT');
|
|
|
|
$this->assertEquals(i18n::_t('i18nTestModule.ENTITY'), 'Entity with "Double Quotes" (de_AT)',
|
|
|
|
'Returns specific regional translation if available'
|
|
|
|
);
|
|
|
|
$this->assertEquals(i18n::_t('i18nTestModule.ADDITION'), 'Addition (de)',
|
|
|
|
'Returns fallback non-regional translation if regional is not available'
|
|
|
|
);
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2011-11-26 14:34:11 +01:00
|
|
|
i18n::set_locale('fr');
|
|
|
|
$this->assertEquals(i18n::_t('i18nTestModule.ENTITY'), '',
|
|
|
|
'Returns empty translation without default string if locale is not found'
|
|
|
|
);
|
|
|
|
$this->assertEquals(i18n::_t('i18nTestModule.ENTITY', 'default'), 'default',
|
|
|
|
'Returns default string if locale is not found'
|
|
|
|
);
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2011-11-26 14:34:11 +01:00
|
|
|
i18n::set_locale($oldLocale);
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testIncludeByLocale() {
|
2011-11-26 14:34:11 +01:00
|
|
|
// Looping through modules, so we can test the translation autoloading
|
|
|
|
// Load non-exclusive to retain core class autoloading
|
|
|
|
$classManifest = new SS_ClassManifest($this->alternateBasePath, true, true, false);
|
|
|
|
SS_ClassLoader::instance()->pushManifest($classManifest);
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2011-11-26 14:34:11 +01:00
|
|
|
$adapter = i18n::get_translator('core')->getAdapter();
|
|
|
|
$this->assertTrue($adapter->isAvailable('en'));
|
|
|
|
$this->assertFalse($adapter->isAvailable('de'));
|
2014-08-15 08:53:05 +02:00
|
|
|
$this->assertFalse($adapter->isTranslated('i18nTestModule.ENTITY', 'de'),
|
2011-11-26 14:34:11 +01:00
|
|
|
'Existing unloaded entity not available before call'
|
|
|
|
);
|
2014-08-15 08:53:05 +02:00
|
|
|
$this->assertFalse($adapter->isTranslated('i18nTestModule.ENTITY', 'af'),
|
2011-11-26 14:34:11 +01:00
|
|
|
'Non-existing unloaded entity not available before call'
|
|
|
|
);
|
2014-08-15 08:53:05 +02:00
|
|
|
|
BUGFIX i18n module load order in i18n::include_by_locale()
The "project" module (normally mysite) is considered with the highest priority. Yet, the project's i18n is loaded first and cannot overwrite existing translations. I've added a array_reverse(), so the iteration keeps the translation of the module with the highest priority.
Old $sortedModules: mysite, (other_modules,) cms, admin, framework.
New $sortedModules: framework, admin, cms, (other_modules,) mysite.
2013-08-05 13:17:29 +02:00
|
|
|
// set _fakewebroot module priority
|
|
|
|
Config::inst()->update('i18n', 'module_priority', array('subfolder','i18ntestmodule'));
|
2010-10-15 03:15:54 +02:00
|
|
|
|
2011-11-26 14:34:11 +01:00
|
|
|
i18n::include_by_locale('de');
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2011-11-26 14:34:11 +01:00
|
|
|
$this->assertTrue($adapter->isAvailable('en'));
|
|
|
|
$this->assertTrue($adapter->isAvailable('de'));
|
|
|
|
$this->assertTrue($adapter->isTranslated('i18nTestModule.ENTITY', null, 'de'), 'Includes module files');
|
|
|
|
$this->assertTrue($adapter->isTranslated('i18nTestTheme1.LAYOUTTEMPLATE', null, 'de'), 'Includes theme files');
|
|
|
|
$this->assertTrue($adapter->isTranslated('i18nTestModule.OTHERENTITY', null, 'de'), 'Includes submodule files');
|
2014-08-15 08:53:05 +02:00
|
|
|
|
BUGFIX i18n module load order in i18n::include_by_locale()
The "project" module (normally mysite) is considered with the highest priority. Yet, the project's i18n is loaded first and cannot overwrite existing translations. I've added a array_reverse(), so the iteration keeps the translation of the module with the highest priority.
Old $sortedModules: mysite, (other_modules,) cms, admin, framework.
New $sortedModules: framework, admin, cms, (other_modules,) mysite.
2013-08-05 13:17:29 +02:00
|
|
|
// check module priority
|
2014-08-15 08:53:05 +02:00
|
|
|
$this->assertEquals($adapter->translate('i18nTestModule.PRIORITYNOTICE', 'de'),
|
BUGFIX i18n module load order in i18n::include_by_locale()
The "project" module (normally mysite) is considered with the highest priority. Yet, the project's i18n is loaded first and cannot overwrite existing translations. I've added a array_reverse(), so the iteration keeps the translation of the module with the highest priority.
Old $sortedModules: mysite, (other_modules,) cms, admin, framework.
New $sortedModules: framework, admin, cms, (other_modules,) mysite.
2013-08-05 13:17:29 +02:00
|
|
|
'High Module Priority (de)'
|
|
|
|
);
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2011-11-26 14:34:11 +01:00
|
|
|
SS_ClassLoader::instance()->popManifest();
|
2010-10-15 03:15:54 +02:00
|
|
|
}
|
2012-05-29 13:54:49 +02:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testIncludeByLocaleWithoutFallbackLanguage() {
|
2012-05-29 13:54:49 +02:00
|
|
|
$classManifest = new SS_ClassManifest($this->alternateBasePath, true, true, false);
|
|
|
|
SS_ClassLoader::instance()->pushManifest($classManifest);
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2012-05-29 13:54:49 +02:00
|
|
|
$adapter = i18n::get_translator('core')->getAdapter();
|
|
|
|
$this->assertTrue($adapter->isAvailable('en'));
|
|
|
|
$this->assertFalse($adapter->isAvailable('mi')); // not defined at all
|
|
|
|
$this->assertFalse($adapter->isAvailable('mi_NZ')); // defined, but not loaded yet
|
2014-08-15 08:53:05 +02:00
|
|
|
$this->assertFalse($adapter->isTranslated('i18nTestModule.ENTITY', 'mi'),
|
2012-05-29 13:54:49 +02:00
|
|
|
'Existing unloaded entity not available before call'
|
|
|
|
);
|
2014-08-15 08:53:05 +02:00
|
|
|
$this->assertFalse($adapter->isTranslated('i18nTestModule.ENTITY', 'mi_NZ'),
|
2012-05-29 13:54:49 +02:00
|
|
|
'Non-existing unloaded entity not available before call'
|
|
|
|
);
|
|
|
|
|
|
|
|
i18n::include_by_locale('mi_NZ');
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2012-05-29 13:54:49 +02:00
|
|
|
$this->assertFalse($adapter->isAvailable('mi'));
|
|
|
|
$this->assertTrue($adapter->isAvailable('mi_NZ'));
|
|
|
|
$this->assertTrue($adapter->isTranslated('i18nTestModule.ENTITY', null, 'mi_NZ'), 'Includes module files');
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2012-05-29 13:54:49 +02:00
|
|
|
SS_ClassLoader::instance()->popManifest();
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testRegisterTranslator() {
|
2011-11-26 14:34:11 +01:00
|
|
|
$translator = new Zend_Translate(array(
|
|
|
|
'adapter' => 'i18nTest_CustomTranslatorAdapter',
|
|
|
|
'disableNotices' => true,
|
|
|
|
));
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2011-11-26 14:34:11 +01:00
|
|
|
i18n::register_translator($translator, 'custom', 10);
|
|
|
|
$translators = i18n::get_translators();
|
|
|
|
$this->assertArrayHasKey('custom', $translators[10]);
|
2012-05-09 12:43:22 +02:00
|
|
|
$this->assertInstanceOf('Zend_Translate', $translators[10]['custom']);
|
|
|
|
$this->assertInstanceOf('i18nTest_CustomTranslatorAdapter', $translators[10]['custom']->getAdapter());
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2011-11-26 14:34:11 +01:00
|
|
|
i18n::unregister_translator('custom');
|
|
|
|
$translators = i18n::get_translators();
|
|
|
|
$this->assertArrayNotHasKey('custom', $translators[10]);
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testMultipleTranslators() {
|
2011-11-26 14:34:11 +01:00
|
|
|
// Looping through modules, so we can test the translation autoloading
|
|
|
|
// Load non-exclusive to retain core class autoloading
|
|
|
|
$classManifest = new SS_ClassManifest($this->alternateBasePath, true, true, false);
|
|
|
|
SS_ClassLoader::instance()->pushManifest($classManifest);
|
2012-04-15 16:46:30 +02:00
|
|
|
|
|
|
|
// 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');
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2011-11-26 14:34:11 +01:00
|
|
|
i18n::set_locale('en_US');
|
2012-04-15 16:46:30 +02:00
|
|
|
|
2011-11-26 14:34:11 +01:00
|
|
|
$this->assertEquals(
|
|
|
|
i18n::_t('i18nTestModule.ENTITY'),
|
|
|
|
'Entity with "Double Quotes"'
|
|
|
|
);
|
|
|
|
$this->assertEquals(
|
|
|
|
i18n::_t('AdapterEntity1', 'AdapterEntity1'),
|
|
|
|
'AdapterEntity1',
|
|
|
|
'Falls back to default string if not found'
|
|
|
|
);
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2011-11-26 14:34:11 +01:00
|
|
|
// Add a new translator
|
|
|
|
$translator = new Zend_Translate(array(
|
|
|
|
'adapter' => 'i18nTest_CustomTranslatorAdapter',
|
|
|
|
'disableNotices' => true,
|
|
|
|
));
|
|
|
|
i18n::register_translator($translator, 'custom', 11);
|
|
|
|
$this->assertEquals(
|
|
|
|
i18n::_t('i18nTestModule.ENTITY'),
|
2012-05-28 02:29:50 +02:00
|
|
|
'i18nTestModule.ENTITY CustomAdapter (en_US)',
|
2011-11-26 14:34:11 +01:00
|
|
|
'Existing entities overruled by adapter with higher priority'
|
|
|
|
);
|
|
|
|
$this->assertEquals(
|
|
|
|
i18n::_t('AdapterEntity1', 'AdapterEntity1'),
|
2012-05-28 02:29:50 +02:00
|
|
|
'AdapterEntity1 CustomAdapter (en_US)',
|
2011-11-26 14:34:11 +01:00
|
|
|
'New entities only defined in new adapter are detected'
|
|
|
|
);
|
2012-05-28 04:10:58 +02:00
|
|
|
|
2011-11-26 14:34:11 +01:00
|
|
|
// Add a second new translator to test priorities
|
|
|
|
$translator = new Zend_Translate(array(
|
|
|
|
'adapter' => 'i18nTest_OtherCustomTranslatorAdapter',
|
|
|
|
'disableNotices' => true,
|
|
|
|
));
|
2014-08-15 08:53:05 +02:00
|
|
|
i18n::register_translator($translator, 'othercustom_lower_prio', 5);
|
2011-11-26 14:34:11 +01:00
|
|
|
$this->assertEquals(
|
|
|
|
i18n::_t('i18nTestModule.ENTITY'),
|
2012-05-28 02:29:50 +02:00
|
|
|
'i18nTestModule.ENTITY CustomAdapter (en_US)',
|
2011-11-26 14:34:11 +01:00
|
|
|
'Adapter with lower priority loses'
|
|
|
|
);
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2011-11-26 14:34:11 +01:00
|
|
|
// Add a third new translator to test priorities
|
|
|
|
$translator = new Zend_Translate(array(
|
|
|
|
'adapter' => 'i18nTest_OtherCustomTranslatorAdapter',
|
|
|
|
'disableNotices' => true,
|
|
|
|
));
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2011-11-26 14:34:11 +01:00
|
|
|
i18n::register_translator($translator, 'othercustom_higher_prio', 15);
|
2012-05-28 04:10:58 +02:00
|
|
|
|
2011-11-26 14:34:11 +01:00
|
|
|
$this->assertEquals(
|
|
|
|
i18n::_t('i18nTestModule.ENTITY'),
|
2012-05-28 06:20:28 +02:00
|
|
|
'i18nTestModule.ENTITY OtherCustomAdapter (en_US)',
|
2011-11-26 14:34:11 +01:00
|
|
|
'Adapter with higher priority wins'
|
|
|
|
);
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2011-11-26 14:34:11 +01:00
|
|
|
i18n::unregister_translator('custom');
|
|
|
|
i18n::unregister_translator('othercustom_lower_prio');
|
|
|
|
i18n::unregister_translator('othercustom_higher_prio');
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2011-11-26 14:34:11 +01:00
|
|
|
SS_ClassLoader::instance()->popManifest();
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2013-03-27 20:42:46 +01:00
|
|
|
public function testGetLanguageName() {
|
|
|
|
Config::inst()->update(
|
2014-08-15 08:53:05 +02:00
|
|
|
'i18n',
|
|
|
|
'common_languages',
|
2013-03-27 20:42:46 +01:00
|
|
|
array('de_CGN' => array('name' => 'German (Cologne)', 'native' => 'Kölsch'))
|
|
|
|
);
|
|
|
|
$this->assertEquals('German (Cologne)', i18n::get_language_name('de_CGN'));
|
|
|
|
$this->assertEquals('Kölsch', i18n::get_language_name('de_CGN', true));
|
|
|
|
}
|
2008-10-29 22:07:17 +01:00
|
|
|
}
|
|
|
|
|
2008-11-01 14:26:08 +01:00
|
|
|
class i18nTest_DataObject extends DataObject implements TestOnly {
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2013-03-21 19:48:54 +01:00
|
|
|
private static $db = array(
|
2008-10-29 22:07:17 +01:00
|
|
|
'MyProperty' => 'Varchar',
|
|
|
|
'MyUntranslatedProperty' => 'Text'
|
|
|
|
);
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2013-03-21 19:48:54 +01:00
|
|
|
private static $has_one = array(
|
2016-06-23 01:37:22 +02:00
|
|
|
'HasOneRelation' => 'SilverStripe\\Security\\Member'
|
2008-10-29 22:07:17 +01:00
|
|
|
);
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2013-03-21 19:48:54 +01:00
|
|
|
private static $has_many = array(
|
2016-06-23 01:37:22 +02:00
|
|
|
'HasManyRelation' => 'SilverStripe\\Security\\Member'
|
2008-10-29 22:07:17 +01:00
|
|
|
);
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2013-03-21 19:48:54 +01:00
|
|
|
private static $many_many = array(
|
2016-06-23 01:37:22 +02:00
|
|
|
'ManyManyRelation' => 'SilverStripe\\Security\\Member'
|
2008-10-29 22:07:17 +01:00
|
|
|
);
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2009-04-29 02:07:39 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param boolean $includerelations a boolean value to indicate if the labels returned include relation fields
|
2014-08-15 08:53:05 +02:00
|
|
|
*
|
2009-04-29 02:07:39 +02:00
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function fieldLabels($includerelations = true) {
|
2009-04-29 02:07:39 +02:00
|
|
|
$labels = parent::fieldLabels($includerelations);
|
2008-11-02 21:01:49 +01:00
|
|
|
$labels['MyProperty'] = _t('i18nTest_DataObject.MyProperty', 'My Property');
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2008-11-02 21:01:49 +01:00
|
|
|
return $labels;
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2008-05-16 06:14:50 +02:00
|
|
|
}
|
2008-11-01 14:26:08 +01:00
|
|
|
|
|
|
|
class i18nTest_Object extends Object implements TestOnly, i18nEntityProvider {
|
|
|
|
static $my_translatable_property = "Untranslated";
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public static function my_translatable_property() {
|
2008-11-01 14:26:08 +01:00
|
|
|
return _t("i18nTest_Object.my_translatable_property", self::$my_translatable_property);
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function provideI18nEntities() {
|
2008-11-01 14:26:08 +01:00
|
|
|
return array(
|
|
|
|
"i18nTest_Object.my_translatable_property" => array(
|
|
|
|
self::$my_translatable_property
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2012-02-12 21:22:11 +01:00
|
|
|
|
2014-08-15 08:53:05 +02:00
|
|
|
class i18nTest_CustomTranslatorAdapter extends Zend_Translate_Adapter
|
2012-09-26 23:34:00 +02:00
|
|
|
implements TestOnly,i18nTranslateAdapterInterface {
|
2011-11-26 14:34:11 +01:00
|
|
|
protected function _loadTranslationData($filename, $locale, array $options = array()) {
|
|
|
|
return array(
|
|
|
|
$locale => array(
|
|
|
|
'AdapterEntity1' => 'AdapterEntity1 CustomAdapter (' . $locale . ')',
|
|
|
|
'i18nTestModule.ENTITY' => 'i18nTestModule.ENTITY CustomAdapter (' . $locale . ')',
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function toString() {
|
2011-11-26 14:34:11 +01:00
|
|
|
return 'i18nTest_CustomTranslatorAdapter';
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function getFilenameForLocale($locale) {
|
2011-11-26 14:34:11 +01:00
|
|
|
return false; // not file based
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-26 23:34:00 +02:00
|
|
|
class i18nTest_OtherCustomTranslatorAdapter extends Zend_Translate_Adapter
|
|
|
|
implements TestOnly,i18nTranslateAdapterInterface {
|
2011-11-26 14:34:11 +01:00
|
|
|
protected function _loadTranslationData($filename, $locale, array $options = array()) {
|
|
|
|
return array(
|
|
|
|
$locale => array(
|
|
|
|
'i18nTestModule.ENTITY' => 'i18nTestModule.ENTITY OtherCustomAdapter (' . $locale . ')',
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function toString() {
|
2011-11-26 14:34:11 +01:00
|
|
|
return 'i18nTest_OtherCustomTranslatorAdapter';
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function getFilenameForLocale($locale) {
|
2011-11-26 14:34:11 +01:00
|
|
|
return false; // not file based
|
|
|
|
}
|
|
|
|
}
|