From a0b02f4a79e2885ea185762fa6d6d6afdfd193ee Mon Sep 17 00:00:00 2001 From: lecosson Date: Fri, 28 May 2021 16:41:46 +0300 Subject: [PATCH 1/4] feature: TR-857 added helpers to determine RTL directions --- package-lock.json | 3 ++- src/util/locale.js | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/package-lock.json b/package-lock.json index 00f2ec1..405037e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4996,7 +4996,8 @@ "y18n": { "version": "4.0.3", "resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.3.tgz", - "integrity": "sha512-JKhqTOwSrqNA1NY5lSztJ1GrBiUodLMmIZuLiDaMRJ+itFd+ABVE8XBjOvIWL+rSqNDC74LCSFmlb/U4UZ4hJQ==" + "integrity": "sha512-JKhqTOwSrqNA1NY5lSztJ1GrBiUodLMmIZuLiDaMRJ+itFd+ABVE8XBjOvIWL+rSqNDC74LCSFmlb/U4UZ4hJQ==", + "dev": true }, "yallist": { "version": "2.1.2", diff --git a/src/util/locale.js b/src/util/locale.js index ecec6de..dfbdaf7 100644 --- a/src/util/locale.js +++ b/src/util/locale.js @@ -121,5 +121,25 @@ export default { */ formatDateTime: function(timestamp) { return moment(timestamp, 'X').format(this.getDateTimeFormat()); + }, + + /** + * Determine direction for language + * @param {String} locale + * @return boolean + */ + isLanguageRTL: function(locale) { + return [ ... this.getConfig().rtl || [] ].includes(locale); + }, + + /** + * Determine direction for language + * @param {String} locale + * @return String {rtl|ltr} + */ + getLanguageDirection: function(locale) { + return this.isLanguageRTL(locale) + ? 'rtl' + : 'ltr'; } }; From bbb82f7eee6f300873b2d8928969a621009689b4 Mon Sep 17 00:00:00 2001 From: lecosson Date: Mon, 31 May 2021 13:15:34 +0300 Subject: [PATCH 2/4] fix: TR-857 tests added for new helpers --- test/util/locale/test.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/test/util/locale/test.js b/test/util/locale/test.js index 121cd4b..af8f7cc 100644 --- a/test/util/locale/test.js +++ b/test/util/locale/test.js @@ -91,5 +91,27 @@ define(['module', 'util/locale'], function(module, locale) { 6, 'the valid integer value with dot as decimal separator and comma as thousands separator' ); + + }); + + // check RTL locales + QUnit.test('isLanguageRTL', function(assert) { + assert.expect(2); + + locale.setConfig({ + rtl: ['ar-arb'] + }); + assert.ok(!locale.isLanguageRTL('en-US'), 'LTR language recognized as RTL'); + assert.ok(locale.isLanguageRTL('ar-arb'), 'RTL language recognized as LTR'); }); + QUnit.test('getLanguageDirection', function(assert) { + assert.expect(2); + + locale.setConfig({ + rtl: ['ar-arb'] + }); + assert.equal(locale.getLanguageDirection('en-US'), 'ltr', 'LTR language is not recognized as LTR'); + assert.equal(locale.getLanguageDirection('ar-arb'), 'rtl', 'RTL language is notrecognized as RTL'); + }); + }); From 3319fba415d66174eca4f85db5036a5883c1c288 Mon Sep 17 00:00:00 2001 From: lecosson Date: Thu, 3 Jun 2021 16:47:33 +0300 Subject: [PATCH 3/4] fix: TR-857 locales made case insensitive, test fixed --- src/util/locale.js | 14 ++++++----- test/util/locale/test.js | 51 +++++++++++++++++++++++++++++++--------- 2 files changed, 48 insertions(+), 17 deletions(-) diff --git a/src/util/locale.js b/src/util/locale.js index dfbdaf7..5444a5c 100644 --- a/src/util/locale.js +++ b/src/util/locale.js @@ -125,20 +125,22 @@ export default { /** * Determine direction for language - * @param {String} locale + * @param {String} lang * @return boolean */ - isLanguageRTL: function(locale) { - return [ ... this.getConfig().rtl || [] ].includes(locale); + isLanguageRTL: function(lang) { + return (this.getConfig().rtl || []) + .map(lng => String(lng).toLowerCase()) + .indexOf(lang.toLowerCase()) >= 0; }, /** * Determine direction for language - * @param {String} locale + * @param {String} lang * @return String {rtl|ltr} */ - getLanguageDirection: function(locale) { - return this.isLanguageRTL(locale) + getLanguageDirection: function(lang) { + return this.isLanguageRTL(lang) ? 'rtl' : 'ltr'; } diff --git a/test/util/locale/test.js b/test/util/locale/test.js index af8f7cc..bc8b667 100644 --- a/test/util/locale/test.js +++ b/test/util/locale/test.js @@ -95,23 +95,52 @@ define(['module', 'util/locale'], function(module, locale) { }); // check RTL locales - QUnit.test('isLanguageRTL', function(assert) { - assert.expect(2); - + QUnit.cases.init([{ + title: 'LTR language', + config: ['ar-ARB'], + lang: 'en-US', + rtl: false + }, { + title: 'RTL language', + config: ['ar-ARB'], + lang: 'ar-ARB', + rtl: true + }, { + // check upper/lowercase + title: 'RTL language letter case', + config: ['ar-ARB'], + lang: 'ar-arb', + rtl: true + }]).test('isLanguageRTL', (data, assert) => { + assert.expect(1); locale.setConfig({ - rtl: ['ar-arb'] + rtl: data.config }); - assert.ok(!locale.isLanguageRTL('en-US'), 'LTR language recognized as RTL'); - assert.ok(locale.isLanguageRTL('ar-arb'), 'RTL language recognized as LTR'); + assert.equal(locale.isLanguageRTL(data.lang), data.rtl, 'Language is properly recognized as RTL or LTR'); }); - QUnit.test('getLanguageDirection', function(assert) { - assert.expect(2); + QUnit.cases.init([{ + title: 'LTR language', + config: ['ar-ARB'], + lang: 'en-US', + direction: 'ltr' + }, { + title: 'RTL language', + config: ['ar-ARB'], + lang: 'ar-ARB', + direction: 'rtl' + }, { + // check upper/lowercase + title: 'RTL language letter case', + config: ['ar-ARB'], + lang: 'ar-arb', + direction: 'rtl' + }]).test('getLanguageDirection', (data, assert) => { + assert.expect(1); locale.setConfig({ - rtl: ['ar-arb'] + rtl: data.config }); - assert.equal(locale.getLanguageDirection('en-US'), 'ltr', 'LTR language is not recognized as LTR'); - assert.equal(locale.getLanguageDirection('ar-arb'), 'rtl', 'RTL language is notrecognized as RTL'); + assert.equal(locale.getLanguageDirection(data.lang), data.direction, 'Language direction is properly recognized'); }); }); From c2dd46de045f9a2157cb4bf18794747670738349 Mon Sep 17 00:00:00 2001 From: lecosson Date: Fri, 4 Jun 2021 11:14:30 +0300 Subject: [PATCH 4/4] fix: TR-857 version bump --- package-lock.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 03e0631..bedc6a1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@oat-sa/tao-core-sdk", - "version": "1.14.0", + "version": "1.15.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 3a7de71..7b2f8ba 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@oat-sa/tao-core-sdk", - "version": "1.14.0", + "version": "1.15.0", "displayName": "TAO Core SDK", "description": "Core libraries of TAO", "homepage": "https://github.com/oat-sa/tao-core-sdk-fe#readme",