-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhyphenatorLoader.ts
More file actions
115 lines (107 loc) · 2.6 KB
/
hyphenatorLoader.ts
File metadata and controls
115 lines (107 loc) · 2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import type hyphen from "npm:@types/hyphen";
import { createRequire } from "node:module";
const require = createRequire(import.meta.url);
export const supportedLanguages = {
afrikaans: "af",
assamese: "as",
belarusian: "be",
bulgarian: "bg",
bengali: "bn",
catalan: "ca",
coptic: "cop",
czech: "cs",
welsh: "cy",
church_slavonic: "cu",
danish: "da",
german_old: "de-1901",
german_new: "de-1996",
german_swiss: "de-CH-1901",
modern_greek_monotonic: "el-monoton",
modern_greek_polytonic: "hyphen/el-polyton",
british_english: "en-gb",
american_english: "en-us",
spanish: "es",
estonian: "et",
basque: "eu",
finnish: "fi",
french: "fr",
friulan: "fur",
irish: "ga",
galician: "gl",
ancient_greek: "grc",
gujarati: "gu",
hindi: "hi",
croatian: "hr",
upper_sorbian: "hsb",
hungarian: "hu",
armenian: "hy",
interlingua: "ia",
bahasa_indonesian: "id",
icelandic: "is",
italian: "it",
georgian: "ka",
kurmanji: "kmr",
kannada: "kn",
classic_latin: "la-x-classic",
liturgical_latin: "la-x-liturgic",
latin: "la",
lithuanian: "lt",
latvian: "lv",
malayalam: "ml",
mongolian: "mn-cyrl",
mongolian_alternative_patterns: "mn-cyrl-x-lmc",
marathi: "mr",
multi_language_ethiopic_scripts: "mul-ethi",
norwegian_bokmal: "nb",
dutch: "nl",
norwegian_norsk: "no",
occitan: "oc",
odia_oriya: "or",
panjabi_punjabi: "pa",
pali: "pi",
polish: "pl",
piedmontese: "pms",
portuguese: "pt",
romansh: "rm",
romanian: "ro",
russian: "ru",
sanskrit: "sa",
serbocroatian_cyrillic: "sh-cyrl",
serbocroatian_latin: "sh-latn",
slovak: "sk",
slovenian: "sl",
serbian: "sr-cyrl",
swedish: "sv",
tamil: "ta",
telugu: "te",
thai: "th",
turkmen: "tk",
turkish: "tr",
ukrainian: "uk",
mandarin_pinyin: "zh-latn-pinyin",
german_new_alias: "de",
modern_greek_alias: "el",
us_english_alias: "en",
multi_ethiopic_scripts_alias: "ethi",
mongolian_alias: "mn",
serbocroatian_alias: "sh",
serbian_alias: "sr",
mandarin_pinyin_alias: "zh",
} as const;
export type Hyphenator = hyphen.HyphenationFunctionAsync;
export async function loadHyphenator(languageCode: string) {
const codes = new Set(Object.values(supportedLanguages) as string[]);
if (!codes.has(languageCode)) {
throw new Error(
`"${languageCode}" is not a valid language code.\n${getSupportedLanguagesText()}`,
);
}
const { hyphenate } = require(`hyphen/${languageCode}`);
return hyphenate as Hyphenator;
}
export function getSupportedLanguagesText() {
const supportedLanguagesString = Object.entries(supportedLanguages).map((
[name, key],
) => `${name}: ${key}`).join("\n");
return `Supported languages:\n\n${supportedLanguagesString}`;
}