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
path: root/core
diff options
context:
space:
mode:
authorBenaka Moorthi <benaka.moorthi@gmail.com>2013-09-12 21:38:03 +0400
committerBenaka Moorthi <benaka.moorthi@gmail.com>2013-09-12 22:10:16 +0400
commita5ab907fe3d09ad1aacd1a0718566aad9768889b (patch)
tree6bd50b5c3583b912671f2220f96d96666115ddd3 /core
parent9cd4cd3dd0a68e43fc9e6b9a9826c9a09fde5114 (diff)
Refs #4151, remove loadJavascriptTranslations twig function and automatically generate translation JS for all plugins. Translation JS is now treated as an asset and is included in merged JS.
Note: - Includes tweaks to capture.js: on webpage error stop capture program.
Diffstat (limited to 'core')
-rw-r--r--core/AssetManager.php30
-rw-r--r--core/Translate.php9
-rw-r--r--core/Twig.php23
3 files changed, 30 insertions, 32 deletions
diff --git a/core/AssetManager.php b/core/AssetManager.php
index 682ae0a09a..449d992226 100644
--- a/core/AssetManager.php
+++ b/core/AssetManager.php
@@ -17,6 +17,7 @@ use Piwik\Piwik;
use Piwik\Common;
use Piwik\Version;
use Piwik\PluginsManager;
+use Piwik\Translate;
use lessc;
/**
@@ -46,6 +47,7 @@ class AssetManager
{
const MERGED_CSS_FILE = "asset_manager_global_css.css";
const MERGED_JS_FILE = "asset_manager_global_js.js";
+ const TRANSLATIONS_JS_FILE = "asset_manager_translations_js.js";
const CSS_IMPORT_EVENT = "AssetManager.getStylesheetFiles";
const JS_IMPORT_EVENT = "AssetManager.getJsFiles";
const MERGED_FILE_DIR = "tmp/assets/";
@@ -311,7 +313,9 @@ class AssetManager
*/
private static function generateMergedJsFile()
{
- $mergedContent = "";
+ // initialize the merged content to the translations JavaScript file
+ $translationsFile = self::getTranslationsJsFileLocation();
+ $mergedContent = PHP_EOL . JSMin::minify(file_get_contents($translationsFile));
// Loop through each js file
$files = self::getJsFiles();
@@ -342,8 +346,12 @@ class AssetManager
*/
private static function getIndividualJsIncludes()
{
- $jsFiles = self::getJsFiles();
$jsIncludeString = '';
+
+ // add translations include
+ $jsIncludeString .= sprintf(self::JS_IMPORT_DIRECTIVE, "index.php?module=Proxy&action=getTranslationJs");
+
+ $jsFiles = self::getJsFiles();
foreach ($jsFiles as $jsFile) {
self::validateJsFile($jsFile);
$jsIncludeString = $jsIncludeString . sprintf(self::JS_IMPORT_DIRECTIVE, $jsFile);
@@ -441,6 +449,24 @@ class AssetManager
}
/**
+ * Returns the translations JS file's absolute location.
+ * If the file does not exist, it is generated.
+ *
+ * @return string
+ */
+ public static function getTranslationsJsFileLocation()
+ {
+ $isGenerated = self::isGenerated(self::TRANSLATIONS_JS_FILE);
+
+ if (!$isGenerated) {
+ $translationJs = Translate::getInstance()->getJavascriptTranslations();
+ self::writeAssetToFile($translationJs, self::TRANSLATIONS_JS_FILE);
+ }
+
+ return self::getAbsoluteMergedFileLocation(self::TRANSLATIONS_JS_FILE);
+ }
+
+ /**
* Check if the provided merged file is generated
*
* @param string $filename filename of the merged asset
diff --git a/core/Translate.php b/core/Translate.php
index 09d9734da6..bd537cc569 100644
--- a/core/Translate.php
+++ b/core/Translate.php
@@ -141,9 +141,8 @@ class Translate
* Generate javascript translations array
*
* @param array $moduleList
- * @return string containing javascript code with translations array (including <script> tag)
*/
- public function getJavascriptTranslations(array $moduleList)
+ public function getJavascriptTranslations()
{
if (!in_array('General', $moduleList)) {
$moduleList[] = 'General';
@@ -161,10 +160,6 @@ class Translate
$translations[$plugin][$key . '_js'] = $translations[$plugin][$key];
}
foreach ($translations as $module => $keys) {
- // Skip modules
- if(!in_array($module, $moduleList)) {
- continue;
- }
foreach($keys as $key => $value) {
// Find keys ending with _js
if (preg_match($moduleRegex, $key)) {
@@ -178,7 +173,7 @@ class Translate
'for(var i in translations) { piwik_translations[i] = translations[i];} ';
$js .= 'function _pk_translate(translationStringId) { ' .
'if( typeof(piwik_translations[translationStringId]) != \'undefined\' ){ return piwik_translations[translationStringId]; }' .
- 'return "The string "+translationStringId+" was not loaded in javascript. Make sure it is suffixed with _js and that you called %7BloadJavascriptTranslations plugins=\'\$YOUR_PLUGIN_NAME\'%7D before your javascript code.";}';
+ 'return "The string "+translationStringId+" was not loaded in javascript. Make sure it is suffixed with _js.";}';
return $js;
}
diff --git a/core/Twig.php b/core/Twig.php
index 5f6550512e..09dbe27940 100644
--- a/core/Twig.php
+++ b/core/Twig.php
@@ -71,7 +71,6 @@ class Twig
$this->addFunction_includeAssets();
$this->addFunction_linkTo();
- $this->addFunction_loadJavascriptTranslations();
$this->addFunction_sparkline();
$this->addFunction_postEvent();
$this->addFunction_isPluginLoaded();
@@ -125,28 +124,6 @@ class Twig
$this->twig->addFunction($sparklineFunction);
}
- protected function addFunction_loadJavascriptTranslations()
- {
- $loadJsTranslationsFunction = new Twig_SimpleFunction('loadJavascriptTranslations', function (array $plugins, $disableScriptTag = false) {
- static $pluginTranslationsAlreadyLoaded = array();
- if (in_array($plugins, $pluginTranslationsAlreadyLoaded)) {
- return;
- }
- $pluginTranslationsAlreadyLoaded[] = $plugins;
- $jsTranslations = Translate::getInstance()->getJavascriptTranslations($plugins);
- $jsCode = '';
- if ($disableScriptTag) {
- $jsCode .= $jsTranslations;
- } else {
- $jsCode .= '<script type="text/javascript">';
- $jsCode .= $jsTranslations;
- $jsCode .= '</script>';
- }
- return $jsCode;
- }, array('is_safe' => array('html')));
- $this->twig->addFunction($loadJsTranslationsFunction);
- }
-
protected function addFunction_linkTo()
{
$urlFunction = new Twig_SimpleFunction('linkTo', function ($params) {