Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthieu Napoli <matthieu@mnapoli.fr>2015-02-09 05:09:51 +0300
committerMatthieu Napoli <matthieu@mnapoli.fr>2015-02-10 00:23:22 +0300
commit3bf35892dd9c42d7765c3e79906abc06cc6f350b (patch)
tree53bccdc99d95f08ee3c2ff577176e0e8092a8e2d /core/Translation
parente084b065d0b8abd8684fb74be4d1e0e66db33f74 (diff)
#7094 Added a new "Development" language that shows the raw translation id
This language is shown when development mode is enabled.
Diffstat (limited to 'core/Translation')
-rw-r--r--core/Translation/Loader/DevelopmentLoader.php72
1 files changed, 72 insertions, 0 deletions
diff --git a/core/Translation/Loader/DevelopmentLoader.php b/core/Translation/Loader/DevelopmentLoader.php
new file mode 100644
index 0000000000..a75af4bd2e
--- /dev/null
+++ b/core/Translation/Loader/DevelopmentLoader.php
@@ -0,0 +1,72 @@
+<?php
+/**
+ * Piwik - free/libre analytics platform
+ *
+ * @link http://piwik.org
+ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
+ */
+
+namespace Piwik\Translation\Loader;
+
+/**
+ * Loads a pseudo-language for developers where translation are equal to translation ids.
+ */
+class DevelopmentLoader implements LoaderInterface
+{
+ const LANGUAGE_ID = 'dev';
+
+ /**
+ * Decorated loader.
+ *
+ * @var LoaderInterface
+ */
+ private $loader;
+
+ /**
+ * @var string
+ */
+ private $fallbackLanguage = 'en';
+
+ /**
+ * @param LoaderInterface $loader Decorate another loader to add the pseudo-language.
+ */
+ public function __construct(LoaderInterface $loader)
+ {
+ $this->loader = $loader;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function load($language, array $directories)
+ {
+ if ($language !== self::LANGUAGE_ID) {
+ return $this->loader->load($language, $directories);
+ }
+
+ return $this->getDevelopmentTranslations($directories);
+ }
+
+ private function getDevelopmentTranslations(array $directories)
+ {
+ $fallbackTranslations = $this->loader->load($this->fallbackLanguage, $directories);
+
+ $translations = array();
+
+ foreach ($fallbackTranslations as $section => $sectionFallbackTranslations) {
+ $translationIds = array_keys($sectionFallbackTranslations);
+ $sectionTranslations = $this->prefixTranslationsWithSection($section, $translationIds);
+
+ $translations[$section] = array_combine($translationIds, $sectionTranslations);
+ }
+
+ return $translations;
+ }
+
+ private function prefixTranslationsWithSection($section, $translationIds)
+ {
+ return array_map(function ($translation) use ($section) {
+ return $section . '_' . $translation;
+ }, $translationIds);
+ }
+}