From 93608a2c75d96b99b92a0b4490fe9a4050283c81 Mon Sep 17 00:00:00 2001 From: Edgar Zavala Date: Fri, 3 Jun 2016 16:46:21 -0500 Subject: [PATCH 1/2] Added multi-line support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Added support for multiple strings for localization, ex. …. "message" : [ "line 1 to", "line 2 of message", "line 3 of message" ], …. --- src/localization.js | 2 +- tests/unit/filterSpec.js | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/localization.js b/src/localization.js index e09c9c7..f8b34fe 100644 --- a/src/localization.js +++ b/src/localization.js @@ -201,7 +201,7 @@ angular.module('ngLocalize') } function applySubstitutions(text, subs) { - var res = text, + var res = (text instanceof Array ? text.join('') : text), firstOfKind = 0; if (subs) { diff --git a/tests/unit/filterSpec.js b/tests/unit/filterSpec.js index 540c53a..454e693 100644 --- a/tests/unit/filterSpec.js +++ b/tests/unit/filterSpec.js @@ -17,7 +17,10 @@ describe('filter', function () { versionAlt: 'v%major.%minor.%patch', fullNameAlt: 'My name is {1} {2}', 'key with whitespace': 'valuewithoutwhitespace', - 'fullNameDups': 'My full name is {firstName} {lastName} so my "good name" is {firstName}.' + 'fullNameDups': 'My full name is {firstName} {lastName} so my "good name" is {firstName}.', + 'multiline' : ['line1', + 'line2', + 'line3'] }); }); }); @@ -78,5 +81,10 @@ describe('filter', function () { lastName: 'Smith' })).toEqual('My full name is John Smith so my "good name" is John.'); })); + + it('should combine multiple lines in one line',inject(function(i18nFilter){ + expect(i18nFilter('common.multiline')) + .toEqual("line1line2line3"); + })); }); }); \ No newline at end of file From 4370330b7db18b5c84407907425f142831334464 Mon Sep 17 00:00:00 2001 From: Edgar Zavala Date: Fri, 3 Jun 2016 21:25:13 -0500 Subject: [PATCH 2/2] Change to angular.isArray Used angular.isArray instead of 'instanceof' --- src/localization.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/localization.js b/src/localization.js index f8b34fe..cee60b4 100644 --- a/src/localization.js +++ b/src/localization.js @@ -201,7 +201,7 @@ angular.module('ngLocalize') } function applySubstitutions(text, subs) { - var res = (text instanceof Array ? text.join('') : text), + var res = (angular.isArray(text) ? text.join('') : text), firstOfKind = 0; if (subs) {