diff --git a/core/Translate.php b/core/Translate.php index c36410f505c1ce280f085bd3a747228c95037e11..179cc1be315e8274c2e0c9e2fba5a4c00d679019 100644 --- a/core/Translate.php +++ b/core/Translate.php @@ -163,10 +163,6 @@ class Translate { $translations = &$GLOBALS['Piwik_translations']; - // Hack: common translations used in JS but not only, force them to be defined in JS - $translations['General']['Save_js'] = $translations['General']['Save']; - $translations['General']['OrCancel_js'] = $translations['General']['OrCancel']; - $clientSideTranslations = array(); foreach ($this->getClientSideTranslationKeys() as $key) { list($plugin, $stringName) = explode("_", $key, 2); @@ -178,7 +174,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.";}'; + 'return "The string "+translationStringId+" was not loaded in javascript. Make sure it is added in the Translate.getClientSideTranslationKeys hook.";}'; return $js; } @@ -194,15 +190,7 @@ class Translate Piwik_PostEvent(self::GET_CLIENT_SIDE_TRANSLATION_KEYS_EVENT, array(&$result)); - $translations = $GLOBALS['Piwik_translations']; - foreach ($translations as $module => $keys) { - foreach($keys as $key => $value) { - // Find keys ending with _js - if (preg_match($moduleRegex, $key)) { - $result[] = $module . '_' . $key; - } - } - } + $result = array_unique($result); return $result; } diff --git a/plugins/ExamplePlugin/Controller.php b/plugins/ExamplePlugin/Controller.php index 8b1c0625caab6b8b31b108e61c8155e427bfda42..05ee0a6928501ffaf4aac5e37caa307934e13338 100644 --- a/plugins/ExamplePlugin/Controller.php +++ b/plugins/ExamplePlugin/Controller.php @@ -123,8 +123,7 @@ class Controller extends \Piwik\Controller $out .= '<h3>i18n internationalization</h3>'; $out .= 'In order to translate strings within Javascript code, you can use the javascript function _pk_translate( token );. <ul><li>The "token" parameter is the string unique key found in the translation file. For this token string to be available in Javascript, you must - suffix your token by "_js" in the language file. For example, you can add <code>\'Goals_AddGoal_js\' => \'Add Goal\',</code> in the lang/en.php file</li> - <li>You can then print this string from your JS code by doing <code>_pk_translate(\'Goals_AddGoal_js\');</code>. + load it using the Translate.getClientSideTranslationKeys hook. </li></ul>'; $out .= '<h3>Reload a widget in the dashboard</h3>'; diff --git a/plugins/SitesManager/SitesManager.php b/plugins/SitesManager/SitesManager.php index b16d679375b894cbd161c863b91c72fab760914f..5e995026bf0e527d0f1192058b39c53b61a35a99 100644 --- a/plugins/SitesManager/SitesManager.php +++ b/plugins/SitesManager/SitesManager.php @@ -210,6 +210,8 @@ class SitesManager extends \Piwik\Plugin public function getClientSideTranslationKeys(&$translationKeys) { + $translationKeys[] = "General_Save"; + $translationKeys[] = "General_OrCancel"; $translationKeys[] = "SitesManager_OnlyOneSiteAtTime"; $translationKeys[] = "SitesManager_DeleteConfirm"; } diff --git a/plugins/SitesManager/javascripts/SitesManager.js b/plugins/SitesManager/javascripts/SitesManager.js index b783b764c380bc4740d3aabd0503892f459b5032..1fa55f7c5852e73265bf85baad453636c1c7dd54 100644 --- a/plugins/SitesManager/javascripts/SitesManager.js +++ b/plugins/SitesManager/javascripts/SitesManager.js @@ -166,7 +166,7 @@ function SitesManager(_timezones, _currencies, _defaultTimezone, _defaultCurrenc var numberOfRows = $('table#editSites')[0].rows.length; var newRowId = 'rowNew' + numberOfRows; - var submitButtonHtml = '<input type="submit" class="addsite submit" value="' + _pk_translate('General_Save_js') + '" />'; + var submitButtonHtml = '<input type="submit" class="addsite submit" value="' + _pk_translate('General_Save') + '" />'; $($.parseHTML(' <tr id="' + newRowId + '">\ <td> </td>\ <td><input id="name" value="Name" size="15" /><br/><br/><br/>' + submitButtonHtml + '</td>\ @@ -179,7 +179,7 @@ function SitesManager(_timezones, _currencies, _defaultTimezone, _defaultCurrenc <td>' + getCurrencySelector(defaultCurrency) + '<br />' + currencyHelp + '</td>\ <td>' + getEcommerceSelector(0) + '<br />' + ecommerceHelp + '</td>\ <td>' + submitButtonHtml + '</td>\ - <td><span class="cancel link_but">' + sprintf(_pk_translate('General_OrCancel_js'), "", "") + '</span></td>\ + <td><span class="cancel link_but">' + sprintf(_pk_translate('General_OrCancel'), "", "") + '</span></td>\ </tr>')) .appendTo('#editSites') ; @@ -237,9 +237,9 @@ function SitesManager(_timezones, _currencies, _defaultTimezone, _defaultCurrenc siteBeingEditedName = contentBefore; var contentAfter = '<input id="' + idName + '" value="' + contentBefore + '" size="15" />'; - var inputSave = $('<br/><input style="margin-top:50px" type="submit" class="submit" value="' + _pk_translate('General_Save_js') + '" />') + var inputSave = $('<br/><input style="margin-top:50px" type="submit" class="submit" value="' + _pk_translate('General_Save') + '" />') .click(function () { submitUpdateSite($(this).parent()); }); - var spanCancel = $('<div><br/>' + sprintf(_pk_translate('General_OrCancel_js'), "", "") + '</div>') + var spanCancel = $('<div><br/>' + sprintf(_pk_translate('General_OrCancel'), "", "") + '</div>') .click(function () { piwikHelper.refreshAfter(0); }); $(n) .html(contentAfter) @@ -293,7 +293,7 @@ function SitesManager(_timezones, _currencies, _defaultTimezone, _defaultCurrenc $(this) .toggle() .parent() - .prepend($('<input type="submit" class="updateSite submit" value="' + _pk_translate('General_Save_js') + '" />') + .prepend($('<input type="submit" class="updateSite submit" value="' + _pk_translate('General_Save') + '" />') .click(function () { sendUpdateSiteAJAX($('tr#' + idRow)); }) ); }); diff --git a/plugins/UsersManager/UsersManager.php b/plugins/UsersManager/UsersManager.php index 1591801c392e34bdcb9298247fe151f220fde1dd..ee2e8ff3d6de6a7007566ce3b0ca818d82139530 100644 --- a/plugins/UsersManager/UsersManager.php +++ b/plugins/UsersManager/UsersManager.php @@ -137,6 +137,8 @@ class UsersManager extends \Piwik\Plugin public function getClientSideTranslationKeys(&$translationKeys) { + $translationKeys[] = "General_OrCancel"; + $translationKeys[] = "General_Save"; $translationKeys[] = "UsersManager_DeleteConfirm"; } } diff --git a/plugins/UsersManager/javascripts/usersManager.js b/plugins/UsersManager/javascripts/usersManager.js index dbca1e34700851ca121830155dcfb30035dd9c8c..0cea74fb115e4a7208b3d1fc042dc22d1d8e4fea 100644 --- a/plugins/UsersManager/javascripts/usersManager.js +++ b/plugins/UsersManager/javascripts/usersManager.js @@ -171,7 +171,7 @@ $(document).ready(function () { $(this) .toggle() .parent() - .prepend($('<input type="submit" class="submit updateuser" value="' + _pk_translate('General_Save_js') + '" />') + .prepend($('<input type="submit" class="submit updateuser" value="' + _pk_translate('General_Save') + '" />') .click(function () { var onValidate = function () { sendUpdateUserAJAX($('tr#' + idRow)); @@ -215,8 +215,8 @@ $(document).ready(function () { <td><input id="useradd_email" value="email@domain.com" size="15" /></td>\ <td><input id="useradd_alias" value="alias" size="15" /></td>\ <td>-</td>\ - <td><input type="submit" class="submit adduser" value="' + _pk_translate('General_Save_js') + '" /></td>\ - <td><span class="cancel">' + sprintf(_pk_translate('General_OrCancel_js'), "", "") + '</span></td>\ + <td><input type="submit" class="submit adduser" value="' + _pk_translate('General_Save') + '" /></td>\ + <td><span class="cancel">' + sprintf(_pk_translate('General_OrCancel'), "", "") + '</span></td>\ </tr>')) .appendTo('#users') ;