diff --git a/plugins/CoreHome/CoreHome.php b/plugins/CoreHome/CoreHome.php index 21974ccf87be47a9d57cbe5ce159e299a2ee2066..64cead7bcd4509307eae5a20564264b126c0299f 100644 --- a/plugins/CoreHome/CoreHome.php +++ b/plugins/CoreHome/CoreHome.php @@ -131,6 +131,7 @@ class CoreHome extends \Piwik\Plugin $jsFiles[] = "plugins/CoreHome/angularjs/common/directives/onenter.js"; $jsFiles[] = "plugins/CoreHome/angularjs/common/directives/focusif.js"; $jsFiles[] = "plugins/CoreHome/angularjs/common/directives/dialog.js"; + $jsFiles[] = "plugins/CoreHome/angularjs/common/directives/translate.js"; $jsFiles[] = "plugins/CoreHome/angularjs/piwikApp.js"; $jsFiles[] = "plugins/CoreHome/angularjs/anchorLinkFix.js"; diff --git a/plugins/CoreHome/angularjs/common/directives/translate.js b/plugins/CoreHome/angularjs/common/directives/translate.js new file mode 100644 index 0000000000000000000000000000000000000000..46c2f99ff1f7fd907cd76a1cf8255d449d6152db --- /dev/null +++ b/plugins/CoreHome/angularjs/common/directives/translate.js @@ -0,0 +1,32 @@ +/*! + * Piwik - free/libre analytics platform + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + */ + +/** + * Directive for easy & safe complex internationalization. This directive allows + * users to embed the sprintf arguments used in internationalization inside an HTML + * element. Since the HTML will eventually be sanitized by AngularJS, HTML can be used + * within the sprintf args. Using the filter, this is not possible w/o manually sanitizing + * and creating trusted HTML, which is not as safe. + * + * Usage: + * <span piwik-translate="Plugin_TranslationToken"> + * first arg:<strong>second arg</strong>:{{ unsafeDataThatWillBeSanitized }} + * </span> + */ +angular.module('piwikApp.directive').directive('piwikTranslate', function() { + return { + restrict: 'A', + scope: { + piwikTranslate: '@' + }, + compile: function(element, attrs) { + var parts = element.html().split(':'), + translated = _pk_translate(attrs.piwikTranslate, parts); + element.html(translated); + } + }; +});