summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/Core/Translator.php26
-rw-r--r--tests/units/Core/TranslatorTest.php45
2 files changed, 62 insertions, 9 deletions
diff --git a/app/Core/Translator.php b/app/Core/Translator.php
index 113c0dc6..ac2e2aae 100644
--- a/app/Core/Translator.php
+++ b/app/Core/Translator.php
@@ -11,13 +11,6 @@ namespace Kanboard\Core;
class Translator
{
/**
- * Locale path
- *
- * @var string
- */
- const PATH = 'app/Locale';
-
- /**
* Locale
*
* @static
@@ -171,9 +164,13 @@ class Translator
* @param string $language Locale code: fr_FR
* @param string $path Locale folder
*/
- public static function load($language, $path = self::PATH)
+ public static function load($language, $path = '')
{
- $filename = $path.DIRECTORY_SEPARATOR.$language.DIRECTORY_SEPARATOR.'translations.php';
+ if ($path === '') {
+ $path = self::getDefaultFolder();
+ }
+
+ $filename = implode(DIRECTORY_SEPARATOR, array($path, $language, 'translations.php'));
if (file_exists($filename)) {
self::$locales = array_merge(self::$locales, require($filename));
@@ -190,4 +187,15 @@ class Translator
{
self::$locales = array();
}
+
+ /**
+ * Get default locales folder
+ *
+ * @access public
+ * @return string
+ */
+ public static function getDefaultFolder()
+ {
+ return implode(DIRECTORY_SEPARATOR, array(__DIR__, '..', 'Locale'));
+ }
}
diff --git a/tests/units/Core/TranslatorTest.php b/tests/units/Core/TranslatorTest.php
new file mode 100644
index 00000000..6aa480e1
--- /dev/null
+++ b/tests/units/Core/TranslatorTest.php
@@ -0,0 +1,45 @@
+<?php
+
+require_once __DIR__.'/../Base.php';
+
+use Kanboard\Core\Translator;
+
+class TranslatorTest extends Base
+{
+ public function setUp()
+ {
+ parent::setUp();
+ Translator::unload();
+ }
+
+ public function testLoading()
+ {
+ $translator = new Translator();
+ $this->assertSame('Yes', $translator->translate('Yes'));
+
+ Translator::load('fr_FR');
+ $this->assertSame('Oui', $translator->translate('Yes'));
+
+ Translator::unload();
+ $this->assertSame('Yes', $translator->translate('Yes'));
+
+ Translator::load('de_DE', Translator::getDefaultFolder());
+ $this->assertSame('Ja', $translator->translate('Yes'));
+ }
+
+ public function testNumberFormatting()
+ {
+ $translator = new Translator();
+ $this->assertSame('1,024.42', $translator->number(1024.42));
+
+ Translator::load('fr_FR');
+ $this->assertSame('1 024,42', $translator->number(1024.42));
+ }
+
+ public function testTranslateEscaping()
+ {
+ $translator = new Translator();
+ $this->assertSame('&lt;b&gt;', $translator->translate('<b>'));
+ $this->assertSame('<b>', $translator->translateNoEscaping('<b>'));
+ }
+}