From ade74a4def787b234e6e79a1a6e0a055accfa6ba Mon Sep 17 00:00:00 2001
From: diosmosis <benaka@piwik.pro>
Date: Sat, 13 Sep 2014 19:04:25 -0700
Subject: [PATCH] Add new angularjs translation directive to aid in complex
 translations where HTML must be embedded in the translated string. Directive
 allows doing this safely and easily.

---
 plugins/CoreHome/CoreHome.php                 |  1 +
 .../angularjs/common/directives/translate.js  | 32 +++++++++++++++++++
 2 files changed, 33 insertions(+)
 create mode 100644 plugins/CoreHome/angularjs/common/directives/translate.js

diff --git a/plugins/CoreHome/CoreHome.php b/plugins/CoreHome/CoreHome.php
index 21974ccf87..64cead7bcd 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 0000000000..46c2f99ff1
--- /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);
+        }
+    };
+});
-- 
GitLab