Skip to content

Commit

Permalink
Merge branch 'release-1.15.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
lecosson authored and lecosson committed Jun 4, 2021
2 parents d0d92b9 + a818ad4 commit f9c2159
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
22 changes: 22 additions & 0 deletions src/util/locale.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,5 +123,27 @@ export default {
formatDateTime(timestamp, utc = false) {
const datetime = utc ? moment.utc(timestamp, 'X') : moment(timestamp, 'X');
return datetime.format(this.getDateTimeFormat());
},

/**
* Determine direction for language
* @param {String} lang
* @return boolean
*/
isLanguageRTL: function(lang) {
return (this.getConfig().rtl || [])
.map(lng => String(lng).toLowerCase())
.indexOf(lang.toLowerCase()) >= 0;
},

/**
* Determine direction for language
* @param {String} lang
* @return String {rtl|ltr}
*/
getLanguageDirection: function(lang) {
return this.isLanguageRTL(lang)
? 'rtl'
: 'ltr';
}
};
50 changes: 50 additions & 0 deletions test/util/locale/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,56 @@ define([
);
});

// check RTL locales
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: data.config
});
assert.equal(locale.isLanguageRTL(data.lang), data.rtl, 'Language is properly recognized as RTL or LTR');
});

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: data.config
});
assert.equal(locale.getLanguageDirection(data.lang), data.direction, 'Language direction is properly recognized');
});


QUnit.test('util/formatDateTime', assert => {
const ready = assert.async();
const expectedTimestamp = 1621641600;
Expand Down

0 comments on commit f9c2159

Please sign in to comment.