Allow apps to overwrite translation domains from third party plugins.

This commit is contained in:
euromark 2014-12-23 13:09:53 +01:00
parent c540e2b798
commit 5c5fb59c8d
4 changed files with 54 additions and 1 deletions

View file

@ -70,6 +70,12 @@ Cache::config('default', array('engine' => 'File'));
*
*/
/**
* To prefer app translation over plugin translation, you can set
*
* Configure::write('I18n.preferApp', true);
*/
/**
* You can attach event listeners to the request lifecycle as Dispatcher Filter. By default CakePHP bundles two filters:
*

View file

@ -387,7 +387,9 @@ class I18n {
$pluginDomain = Inflector::underscore($plugin);
if ($pluginDomain === $domain) {
$searchPaths[] = CakePlugin::path($plugin) . 'Locale' . DS;
$searchPaths = array_reverse($searchPaths);
if (!Configure::read('I18n.preferApp')) {
$searchPaths = array_reverse($searchPaths);
}
break;
}
}

View file

@ -1758,6 +1758,30 @@ class I18nTest extends CakeTestCase {
$this->assertTrue(in_array('25 = 0 or > 1 (from plugin)', $plurals));
}
/**
* Test that Configure::read('I18n.preferApp') will prefer app.
*
* @return void
*/
public function testPluginTranslationPreferApp() {
// Reset internally stored entries
I18n::clear();
Cache::clear(false, '_cake_core_');
Configure::write('I18n.preferApp', true);
App::build(array(
'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
));
Configure::write('Config.language', 'po');
$singular = $this->_domainSingular();
$this->assertEquals('Plural Rule 1', $singular);
$plurals = $this->_domainPlural();
$this->assertTrue(in_array('0 = 0 or > 1', $plurals));
}
/**
* testPoMultipleLineTranslation method
*

View file

@ -0,0 +1,21 @@
msgid ""
msgstr ""
"Project-Id-Version: CakePHP Testsuite\n"
"POT-Creation-Date: 2008-05-15 02:51-0700\n"
"PO-Revision-Date: \n"
"Last-Translator: CakePHP I18N & I10N Team <i10n.cakephp@gmail.com>\n"
"Language-Team: CakePHP I18N & I10N Team <i10n.cakephp@gmail.com>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=n != 1;\n"
"X-Poedit-Language: Two Forms of Plurals\n"
"X-Poedit-SourceCharset: utf-8\n"
msgid "Plural Rule 1"
msgstr "Plural Rule 1"
msgid "%d = 1"
msgid_plural "%d = 0 or > 1"
msgstr[0] "%d = 1"
msgstr[1] "%d = 0 or > 1"