diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2022-12-07 07:35:40 -0400 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2022-12-07 07:35:40 -0400 |
commit | 2532ec9ef61146deadb2a49159b92ef50c5d8835 (patch) | |
tree | d14112ae88ebea310bf7094767fc1bfdb2ff04ec /src/data | |
parent | bf14c334235513c0188d71fdb53bd72f34e22e39 (diff) |
extract processLanguageFile from upd8.js, fix building
Diffstat (limited to 'src/data')
-rw-r--r-- | src/data/language.js | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/data/language.js b/src/data/language.js new file mode 100644 index 00000000..da9528f2 --- /dev/null +++ b/src/data/language.js @@ -0,0 +1,40 @@ +import {readFile} from 'fs/promises'; + +// It stands for "HTML Entities", apparently. Cursed. +import he from 'he'; + +import T from './things/index.js'; + +// TODO: define somewhere besides upd8.js obviously +export async function processLanguageFile(file) { + const contents = await readFile(file, 'utf-8'); + const json = JSON.parse(contents); + + const code = json['meta.languageCode']; + if (!code) { + throw new Error(`Missing language code (file: ${file})`); + } + delete json['meta.languageCode']; + + const intlCode = json['meta.languageIntlCode'] ?? null; + delete json['meta.languageIntlCode']; + + const name = json['meta.languageName']; + if (!name) { + throw new Error(`Missing language name (${code})`); + } + delete json['meta.languageName']; + + const hidden = json['meta.hidden'] ?? false; + delete json['meta.hidden']; + + const language = new T.Language(); + language.code = code; + language.intlCode = intlCode; + language.name = name; + language.hidden = hidden; + language.escapeHTML = (string) => + he.encode(string, {useNamedReferences: true}); + language.strings = json; + return language; +} |