Skip to content

Commit

Permalink
remove dependency on CLDR
Browse files Browse the repository at this point in the history
  • Loading branch information
k-toumura committed Sep 3, 2020
1 parent 24442a5 commit d940867
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 16 deletions.
40 changes: 25 additions & 15 deletions lib/wotutils.js
Expand Up @@ -18,7 +18,6 @@ const Ajv = require('ajv');
const url = require('url');
const fs = require('fs');
const path = require('path');
const cldr = require('cldr');

function validateTd(td) {
const TDSchema =
Expand All @@ -40,21 +39,32 @@ function isOpInForms(op, forms) {
.some(e=>e === op);
}

function textDirection(lang) {
let dir = 'auto';
try {
const ori = cldr.extractLayout(lang);
if (ori.characterOrder === 'left-to-right') {
dir = 'ltr'
} else if (ori.characterOrder === 'right-to-left') {
dir = 'rtl'
}
} catch (e) {
if (lang === "az-Arab") {
dir = 'rtl'
}
function textDirection(langid) {
// based on CLDR and other sources.
const rtlLangs = [
"ar-AE","ar-BH","ar-DJ","ar-DZ","ar-EG","ar-EH","ar-ER","ar-IL","ar-IQ",
"ar-JO","ar-KM","ar-KW","ar-LB","ar-LY","ar-MA","ar-MR","ar-OM","ar-PS",
"ar-QA","ar-SA","ar-SD","ar-SO","ar-SS","ar-SY","ar-TD","ar-TN","ar-YE","ar",
"az-Arab",
"ckb-IR","ckb",
"fa-AF","fa",
"he",
"ks",
"lrc-IQ","lrc",
"mzn",
"pa-Arab",
"ps-PK","ps",
"sd",
"ug",
"ur-IN","ur",
"uz-Arab",
"yi",
];
if (langid === undefined || langid === "") {
return 'auto';
} else {
return (rtlLangs.includes(langid) ? 'rtl' : 'ltr');
}
return dir;
}

function normalizeTd(td) {
Expand Down
1 change: 0 additions & 1 deletion package.json
Expand Up @@ -44,7 +44,6 @@
"dependencies": {
"ajv": "6.12.0",
"api-spec-converter": "2.11.0",
"cldr": "5.5.4",
"colors": "1.4.0",
"csv-string": "3.1.8",
"javascript-obfuscator": "0.28.1",
Expand Down

0 comments on commit d940867

Please sign in to comment.