From 05ba885fd1facbe486e9d0fae059ae7bccffedea Mon Sep 17 00:00:00 2001 From: Richard DesLonde Date: Sat, 17 Mar 2018 18:41:35 -0700 Subject: [PATCH 01/14] Added rollback of overcorrections to keys --- src/catalog.js | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/catalog.js b/src/catalog.js index e24a865..e37b511 100644 --- a/src/catalog.js +++ b/src/catalog.js @@ -47,6 +47,31 @@ angular.module('gettext').factory('gettextCatalog', function (gettextPlurals, ge $rootScope.$broadcast('gettextLanguageChanged'); } + function rollBackOvercorrections (originalKey, key) { + var originalKeyParts = originalKey.split('&'); + var keyParts = key.split('&'); + + var re = /&/gi; //replacement match regex + + for (var i = 0, len = originalKeyParts.length; i < len; i++) { + //get the next part, which will start with "amp;" if this was an occurrence of an encoded & + var nextPart = (originalKeyParts.length-1 >= i+1) ? originalKeyParts[i+1] : ""; + + if (nextPart.length < 4 || nextPart.substring(0, 5) !== "amp;") { //unencoded & in original, needs to be rolled back in key + var nth = 0; + key = key.replace(re, function (match, a, original) { + nth++; + if(nth === i+1) { + return '&'; + } + return match; + }); + } + } + + return key; + } + catalog = { /** * @ngdoc property @@ -170,8 +195,15 @@ angular.module('gettext').factory('gettextCatalog', function (gettextPlurals, ge var val = strings[key]; if (isHTMLModified) { + + //keep a copy of the original key for comparison later + var originalKey = key; + // Use the DOM engine to render any HTML in the key (#131). key = angular.element('' + key + '').html(); + + //now that we have a "corrected" key, rollback the overcorrections for & character + key = rollBackOvercorrections(originalKey, key); } if (angular.isString(val) || angular.isArray(val)) { From 83ad5d3e0824b488d48387d798bbf365fa41f59c Mon Sep 17 00:00:00 2001 From: Richard DesLonde Date: Sat, 17 Mar 2018 23:21:17 -0700 Subject: [PATCH 02/14] Added rollback to directive --- src/catalog.js | 8 +++----- src/directive.js | 1 + 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/catalog.js b/src/catalog.js index e37b511..5171d13 100644 --- a/src/catalog.js +++ b/src/catalog.js @@ -177,6 +177,8 @@ angular.module('gettext').factory('gettextCatalog', function (gettextPlurals, ge return this.currentLanguage; }, + rollBackOvercorrections: rollBackOvercorrections, + /** * @ngdoc method * @name gettextCatalog#setStrings @@ -195,14 +197,10 @@ angular.module('gettext').factory('gettextCatalog', function (gettextPlurals, ge var val = strings[key]; if (isHTMLModified) { - - //keep a copy of the original key for comparison later + //save the original before we change it var originalKey = key; - // Use the DOM engine to render any HTML in the key (#131). key = angular.element('' + key + '').html(); - - //now that we have a "corrected" key, rollback the overcorrections for & character key = rollBackOvercorrections(originalKey, key); } diff --git a/src/directive.js b/src/directive.js index df4782b..2fc9f6c 100644 --- a/src/directive.js +++ b/src/directive.js @@ -97,6 +97,7 @@ angular.module('gettext').directive('translate', function (gettextCatalog, $pars gettextUtil.assert(!attrs.translateN || attrs.translatePlural, 'translate-plural', 'translate-n'); var msgid = gettextUtil.trim(element.html()); + msgid = gettextCatalog.rollBackOvercorrections(element.context.innerText, msgid); var translatePlural = attrs.translatePlural; var translateContext = attrs.translateContext; From b2abb821411bf647181bdb1a321103adfb372d84 Mon Sep 17 00:00:00 2001 From: Richard DesLonde Date: Sat, 17 Mar 2018 23:37:57 -0700 Subject: [PATCH 03/14] Fixed jshint errors --- src/catalog.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/catalog.js b/src/catalog.js index 5171d13..caee2b0 100644 --- a/src/catalog.js +++ b/src/catalog.js @@ -49,8 +49,6 @@ angular.module('gettext').factory('gettextCatalog', function (gettextPlurals, ge function rollBackOvercorrections (originalKey, key) { var originalKeyParts = originalKey.split('&'); - var keyParts = key.split('&'); - var re = /&/gi; //replacement match regex for (var i = 0, len = originalKeyParts.length; i < len; i++) { @@ -59,19 +57,21 @@ angular.module('gettext').factory('gettextCatalog', function (gettextPlurals, ge if (nextPart.length < 4 || nextPart.substring(0, 5) !== "amp;") { //unencoded & in original, needs to be rolled back in key var nth = 0; - key = key.replace(re, function (match, a, original) { - nth++; - if(nth === i+1) { - return '&'; - } - return match; - }); + key = key.replace(re, replaceNth); } } return key; } + function replaceNth (match) { + nth++; + if(nth === i+1) { + return '&'; + } + return match; + } + catalog = { /** * @ngdoc property From e66a632c31303982f501ac6884547692077f0205 Mon Sep 17 00:00:00 2001 From: Richard DesLonde Date: Sat, 17 Mar 2018 23:44:13 -0700 Subject: [PATCH 04/14] Fixed jshint errors --- src/catalog.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/catalog.js b/src/catalog.js index caee2b0..b296f81 100644 --- a/src/catalog.js +++ b/src/catalog.js @@ -51,12 +51,20 @@ angular.module('gettext').factory('gettextCatalog', function (gettextPlurals, ge var originalKeyParts = originalKey.split('&'); var re = /&/gi; //replacement match regex + var nth = 0; + function replaceNth (match) { + nth++; + if(nth === i+1) { + return '&'; + } + return match; + } + for (var i = 0, len = originalKeyParts.length; i < len; i++) { //get the next part, which will start with "amp;" if this was an occurrence of an encoded & var nextPart = (originalKeyParts.length-1 >= i+1) ? originalKeyParts[i+1] : ""; if (nextPart.length < 4 || nextPart.substring(0, 5) !== "amp;") { //unencoded & in original, needs to be rolled back in key - var nth = 0; key = key.replace(re, replaceNth); } } @@ -64,14 +72,6 @@ angular.module('gettext').factory('gettextCatalog', function (gettextPlurals, ge return key; } - function replaceNth (match) { - nth++; - if(nth === i+1) { - return '&'; - } - return match; - } - catalog = { /** * @ngdoc property From 34924b1f3c4a418c1986df04d3f030cf1978723f Mon Sep 17 00:00:00 2001 From: Richard DesLonde Date: Sat, 17 Mar 2018 23:50:04 -0700 Subject: [PATCH 05/14] Fixed jshint errors --- src/catalog.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/catalog.js b/src/catalog.js index b296f81..a4ffe69 100644 --- a/src/catalog.js +++ b/src/catalog.js @@ -60,7 +60,8 @@ angular.module('gettext').factory('gettextCatalog', function (gettextPlurals, ge return match; } - for (var i = 0, len = originalKeyParts.length; i < len; i++) { + var i = 0; + for (i = 0, len = originalKeyParts.length; i < len; i++) { //get the next part, which will start with "amp;" if this was an occurrence of an encoded & var nextPart = (originalKeyParts.length-1 >= i+1) ? originalKeyParts[i+1] : ""; From 6893de02d9fed9a45a288d42a3f738edc9834045 Mon Sep 17 00:00:00 2001 From: Richard DesLonde Date: Sat, 17 Mar 2018 23:56:25 -0700 Subject: [PATCH 06/14] Fixed jshint errors --- src/catalog.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/catalog.js b/src/catalog.js index a4ffe69..936e6bc 100644 --- a/src/catalog.js +++ b/src/catalog.js @@ -59,9 +59,8 @@ angular.module('gettext').factory('gettextCatalog', function (gettextPlurals, ge } return match; } - - var i = 0; - for (i = 0, len = originalKeyParts.length; i < len; i++) { + + for (var i = 0, var len = originalKeyParts.length; i < len; i++) { //get the next part, which will start with "amp;" if this was an occurrence of an encoded & var nextPart = (originalKeyParts.length-1 >= i+1) ? originalKeyParts[i+1] : ""; From 4e57579325cd996a35a46e486b17120f2d4428c9 Mon Sep 17 00:00:00 2001 From: Richard DesLonde Date: Sun, 18 Mar 2018 00:05:39 -0700 Subject: [PATCH 07/14] Fixed jshint errors --- src/catalog.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/catalog.js b/src/catalog.js index 936e6bc..1413199 100644 --- a/src/catalog.js +++ b/src/catalog.js @@ -59,8 +59,8 @@ angular.module('gettext').factory('gettextCatalog', function (gettextPlurals, ge } return match; } - - for (var i = 0, var len = originalKeyParts.length; i < len; i++) { + + for (var i = 0, len = originalKeyParts.length; i < len; i++;) { //get the next part, which will start with "amp;" if this was an occurrence of an encoded & var nextPart = (originalKeyParts.length-1 >= i+1) ? originalKeyParts[i+1] : ""; From 19ac8dd96bb113fd1810400f18c7a494a03bfc27 Mon Sep 17 00:00:00 2001 From: Richard DesLonde Date: Sun, 18 Mar 2018 00:19:11 -0700 Subject: [PATCH 08/14] Fixed jshint errors --- src/catalog.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/catalog.js b/src/catalog.js index 1413199..82c2bf1 100644 --- a/src/catalog.js +++ b/src/catalog.js @@ -60,7 +60,7 @@ angular.module('gettext').factory('gettextCatalog', function (gettextPlurals, ge return match; } - for (var i = 0, len = originalKeyParts.length; i < len; i++;) { + for (var i = 0; i < originalKeyParts.length; i++) { //get the next part, which will start with "amp;" if this was an occurrence of an encoded & var nextPart = (originalKeyParts.length-1 >= i+1) ? originalKeyParts[i+1] : ""; From 05ad2afa4281bdffdab9179c7638f2e32021297c Mon Sep 17 00:00:00 2001 From: Richard DesLonde Date: Sun, 18 Mar 2018 00:22:32 -0700 Subject: [PATCH 09/14] Fixed jshint errors --- src/catalog.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/catalog.js b/src/catalog.js index 82c2bf1..c5fce19 100644 --- a/src/catalog.js +++ b/src/catalog.js @@ -60,7 +60,9 @@ angular.module('gettext').factory('gettextCatalog', function (gettextPlurals, ge return match; } - for (var i = 0; i < originalKeyParts.length; i++) { + var i = 0; + + for (i = 0; i < originalKeyParts.length; i++) { //get the next part, which will start with "amp;" if this was an occurrence of an encoded & var nextPart = (originalKeyParts.length-1 >= i+1) ? originalKeyParts[i+1] : ""; From 0dad1e52dda612140f8e7cc0ee64a91b569264f0 Mon Sep 17 00:00:00 2001 From: Richard DesLonde Date: Sun, 18 Mar 2018 00:25:21 -0700 Subject: [PATCH 10/14] Fixed jshint errors --- src/catalog.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/catalog.js b/src/catalog.js index c5fce19..3ad42d1 100644 --- a/src/catalog.js +++ b/src/catalog.js @@ -52,6 +52,8 @@ angular.module('gettext').factory('gettextCatalog', function (gettextPlurals, ge var re = /&/gi; //replacement match regex var nth = 0; + var i = 0; + function replaceNth (match) { nth++; if(nth === i+1) { @@ -60,8 +62,6 @@ angular.module('gettext').factory('gettextCatalog', function (gettextPlurals, ge return match; } - var i = 0; - for (i = 0; i < originalKeyParts.length; i++) { //get the next part, which will start with "amp;" if this was an occurrence of an encoded & var nextPart = (originalKeyParts.length-1 >= i+1) ? originalKeyParts[i+1] : ""; From 53cfc717c71dc8fdf8c41c733a96f8a67ea97460 Mon Sep 17 00:00:00 2001 From: Richard DesLonde Date: Sun, 18 Mar 2018 00:33:34 -0700 Subject: [PATCH 11/14] Fixed jshint errors --- src/catalog.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/catalog.js b/src/catalog.js index 3ad42d1..41b8233 100644 --- a/src/catalog.js +++ b/src/catalog.js @@ -47,16 +47,16 @@ angular.module('gettext').factory('gettextCatalog', function (gettextPlurals, ge $rootScope.$broadcast('gettextLanguageChanged'); } - function rollBackOvercorrections (originalKey, key) { + function rollBackOvercorrections(originalKey, key) { var originalKeyParts = originalKey.split('&'); - var re = /&/gi; //replacement match regex + var re = /&/gi;//replacement match regex var nth = 0; var i = 0; - - function replaceNth (match) { + + function replaceNth(match) { nth++; - if(nth === i+1) { + if (nth === i + 1) { return '&'; } return match; @@ -64,9 +64,9 @@ angular.module('gettext').factory('gettextCatalog', function (gettextPlurals, ge for (i = 0; i < originalKeyParts.length; i++) { //get the next part, which will start with "amp;" if this was an occurrence of an encoded & - var nextPart = (originalKeyParts.length-1 >= i+1) ? originalKeyParts[i+1] : ""; + var nextPart = (originalKeyParts.length-1 >= i + 1) ? originalKeyParts[i + 1] : ''; - if (nextPart.length < 4 || nextPart.substring(0, 5) !== "amp;") { //unencoded & in original, needs to be rolled back in key + if (nextPart.length < 4 || nextPart.substring(0, 5) !== 'amp;') { //unencoded & in original, needs to be rolled back in key key = key.replace(re, replaceNth); } } From d47c65007426575c67bd5521da95efcd41573c59 Mon Sep 17 00:00:00 2001 From: Richard DesLonde Date: Sun, 18 Mar 2018 00:36:36 -0700 Subject: [PATCH 12/14] Fixed jshint errors --- src/catalog.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/catalog.js b/src/catalog.js index 41b8233..3cbbc56 100644 --- a/src/catalog.js +++ b/src/catalog.js @@ -64,7 +64,7 @@ angular.module('gettext').factory('gettextCatalog', function (gettextPlurals, ge for (i = 0; i < originalKeyParts.length; i++) { //get the next part, which will start with "amp;" if this was an occurrence of an encoded & - var nextPart = (originalKeyParts.length-1 >= i + 1) ? originalKeyParts[i + 1] : ''; + var nextPart = (originalKeyParts.length - 1 >= i + 1) ? originalKeyParts[i + 1] : ''; if (nextPart.length < 4 || nextPart.substring(0, 5) !== 'amp;') { //unencoded & in original, needs to be rolled back in key key = key.replace(re, replaceNth); From a52694015184d24a3463bc5cb7448ba2c42851a3 Mon Sep 17 00:00:00 2001 From: Richard DesLonde Date: Sun, 18 Mar 2018 00:46:59 -0700 Subject: [PATCH 13/14] Fixed jshint errors --- src/directive.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/directive.js b/src/directive.js index 2fc9f6c..d1f75c4 100644 --- a/src/directive.js +++ b/src/directive.js @@ -97,7 +97,8 @@ angular.module('gettext').directive('translate', function (gettextCatalog, $pars gettextUtil.assert(!attrs.translateN || attrs.translatePlural, 'translate-plural', 'translate-n'); var msgid = gettextUtil.trim(element.html()); - msgid = gettextCatalog.rollBackOvercorrections(element.context.innerText, msgid); + var originalText = element.context && element.context.innerText ? element.context.innerText : element.html(); + msgid = gettextCatalog.rollBackOvercorrections(originalText, msgid); var translatePlural = attrs.translatePlural; var translateContext = attrs.translateContext; From 437c794ccc43a20312900bf254b492af53f6bc03 Mon Sep 17 00:00:00 2001 From: Richard DesLonde Date: Sun, 18 Mar 2018 01:06:23 -0700 Subject: [PATCH 14/14] Fixed jshint errors --- src/catalog.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/catalog.js b/src/catalog.js index 3cbbc56..cb7c4d5 100644 --- a/src/catalog.js +++ b/src/catalog.js @@ -50,7 +50,6 @@ angular.module('gettext').factory('gettextCatalog', function (gettextPlurals, ge function rollBackOvercorrections(originalKey, key) { var originalKeyParts = originalKey.split('&'); var re = /&/gi;//replacement match regex - var nth = 0; var i = 0;