From 68c6afc56f3758154cfb96cba6fd48a6b5535590 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Mon, 26 Feb 2018 22:53:00 +0100 Subject: Load theme translations files automatically Fixes #1077 Take a look at the docs update to see how it works --- tests/LanguagesTest.php | 26 +++++++++++++++++++++ tests/languages/fr/LanguagesFrTest.php | 26 +++++++++++++++++++++ .../dummy/language/fr/LC_MESSAGES/dummy.mo | Bin 0 -> 431 bytes .../dummy/language/fr/LC_MESSAGES/dummy.po | 16 +++++++++++++ 4 files changed, 68 insertions(+) create mode 100644 tests/utils/customtpl/dummy/language/fr/LC_MESSAGES/dummy.mo create mode 100644 tests/utils/customtpl/dummy/language/fr/LC_MESSAGES/dummy.po (limited to 'tests') diff --git a/tests/LanguagesTest.php b/tests/LanguagesTest.php index 864ce630..4951e09a 100644 --- a/tests/LanguagesTest.php +++ b/tests/LanguagesTest.php @@ -175,6 +175,32 @@ class LanguagesTest extends \PHPUnit_Framework_TestCase $this->assertEquals($text, t($text)); } + /** + * Test t() with an extension language file coming from the theme in gettext mode + */ + public function testTranslationThemeExtensionGettext() + { + $this->conf->set('translation.mode', 'gettext'); + $this->conf->set('raintpl_tpl', 'tests/utils/customtpl/'); + $this->conf->set('theme', 'dummy'); + new Languages('en', $this->conf); + $txt = 'rooster'; // ignore me poedit + $this->assertEquals('rooster', t($txt, $txt, 1, 'dummy')); + } + + /** + * Test t() with an extension language file coming from the theme in PHP mode + */ + public function testTranslationThemeExtensionPhp() + { + $this->conf->set('translation.mode', 'php'); + $this->conf->set('raintpl_tpl', 'tests/utils/customtpl/'); + $this->conf->set('theme', 'dummy'); + new Languages('en', $this->conf); + $txt = 'rooster'; // ignore me poedit + $this->assertEquals('rooster', t($txt, $txt, 1, 'dummy')); + } + /** * Test t() with an extension language file in gettext mode */ diff --git a/tests/languages/fr/LanguagesFrTest.php b/tests/languages/fr/LanguagesFrTest.php index 79d05172..0cf74891 100644 --- a/tests/languages/fr/LanguagesFrTest.php +++ b/tests/languages/fr/LanguagesFrTest.php @@ -172,4 +172,30 @@ class LanguagesFrTest extends \PHPUnit_Framework_TestCase $this->assertEquals('voiture', t($txt, $txt, 1, 'test')); $this->assertEquals('Fouille', t('Search', 'Search', 1, 'test')); } + + /** + * Test t() with an extension language file coming from the theme in gettext mode + */ + public function testTranslationThemeExtensionGettext() + { + $this->conf->set('translation.mode', 'gettext'); + $this->conf->set('raintpl_tpl', 'tests/utils/customtpl/'); + $this->conf->set('theme', 'dummy'); + new Languages('en', $this->conf); + $txt = 'rooster'; // ignore me poedit + $this->assertEquals('coq', t($txt, $txt, 1, 'dummy')); + } + + /** + * Test t() with an extension language file coming from the theme in PHP mode + */ + public function testTranslationThemeExtensionPhp() + { + $this->conf->set('translation.mode', 'php'); + $this->conf->set('raintpl_tpl', 'tests/utils/customtpl/'); + $this->conf->set('theme', 'dummy'); + new Languages('en', $this->conf); + $txt = 'rooster'; // ignore me poedit + $this->assertEquals('coq', t($txt, $txt, 1, 'dummy')); + } } diff --git a/tests/utils/customtpl/dummy/language/fr/LC_MESSAGES/dummy.mo b/tests/utils/customtpl/dummy/language/fr/LC_MESSAGES/dummy.mo new file mode 100644 index 00000000..8daae0c9 Binary files /dev/null and b/tests/utils/customtpl/dummy/language/fr/LC_MESSAGES/dummy.mo differ diff --git a/tests/utils/customtpl/dummy/language/fr/LC_MESSAGES/dummy.po b/tests/utils/customtpl/dummy/language/fr/LC_MESSAGES/dummy.po new file mode 100644 index 00000000..90d1abb0 --- /dev/null +++ b/tests/utils/customtpl/dummy/language/fr/LC_MESSAGES/dummy.po @@ -0,0 +1,16 @@ +msgid "" +msgstr "" +"Project-Id-Version: Theme extension test\n" +"POT-Creation-Date: 2017-05-20 13:54+0200\n" +"PO-Revision-Date: 2018-03-26 19:09+0200\n" +"Last-Translator: \n" +"Language-Team: Shaarli\n" +"Language: fr_FR\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-Generator: Poedit 2.0.6\n" + +msgid "rooster" +msgstr "coq" -- cgit v1.2.3