Skip to content

Commit d940867

Browse files
committed
remove dependency on CLDR
1 parent 24442a5 commit d940867

File tree

2 files changed

+25
-16
lines changed

2 files changed

+25
-16
lines changed

lib/wotutils.js

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ const Ajv = require('ajv');
1818
const url = require('url');
1919
const fs = require('fs');
2020
const path = require('path');
21-
const cldr = require('cldr');
2221

2322
function validateTd(td) {
2423
const TDSchema =
@@ -40,21 +39,32 @@ function isOpInForms(op, forms) {
4039
.some(e=>e === op);
4140
}
4241

43-
function textDirection(lang) {
44-
let dir = 'auto';
45-
try {
46-
const ori = cldr.extractLayout(lang);
47-
if (ori.characterOrder === 'left-to-right') {
48-
dir = 'ltr'
49-
} else if (ori.characterOrder === 'right-to-left') {
50-
dir = 'rtl'
51-
}
52-
} catch (e) {
53-
if (lang === "az-Arab") {
54-
dir = 'rtl'
55-
}
42+
function textDirection(langid) {
43+
// based on CLDR and other sources.
44+
const rtlLangs = [
45+
"ar-AE","ar-BH","ar-DJ","ar-DZ","ar-EG","ar-EH","ar-ER","ar-IL","ar-IQ",
46+
"ar-JO","ar-KM","ar-KW","ar-LB","ar-LY","ar-MA","ar-MR","ar-OM","ar-PS",
47+
"ar-QA","ar-SA","ar-SD","ar-SO","ar-SS","ar-SY","ar-TD","ar-TN","ar-YE","ar",
48+
"az-Arab",
49+
"ckb-IR","ckb",
50+
"fa-AF","fa",
51+
"he",
52+
"ks",
53+
"lrc-IQ","lrc",
54+
"mzn",
55+
"pa-Arab",
56+
"ps-PK","ps",
57+
"sd",
58+
"ug",
59+
"ur-IN","ur",
60+
"uz-Arab",
61+
"yi",
62+
];
63+
if (langid === undefined || langid === "") {
64+
return 'auto';
65+
} else {
66+
return (rtlLangs.includes(langid) ? 'rtl' : 'ltr');
5667
}
57-
return dir;
5868
}
5969

6070
function normalizeTd(td) {

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
"dependencies": {
4545
"ajv": "6.12.0",
4646
"api-spec-converter": "2.11.0",
47-
"cldr": "5.5.4",
4847
"colors": "1.4.0",
4948
"csv-string": "3.1.8",
5049
"javascript-obfuscator": "0.28.1",

0 commit comments

Comments
 (0)