From 6288be58e4d46a974700bba2b1d13d6faeb66a64 Mon Sep 17 00:00:00 2001 From: MarvNC Date: Thu, 11 Jul 2024 20:56:54 -0700 Subject: [PATCH] Expand language codes --- src/constants.ts | 116 +++++++++++++++++++++++++++++++++++++- src/util/downloadDumps.ts | 2 +- src/util/readArgs.ts | 10 ++-- 3 files changed, 120 insertions(+), 8 deletions(-) diff --git a/src/constants.ts b/src/constants.ts index 85a0760..d1768c4 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -2,21 +2,133 @@ import * as path from 'path'; import { getReadingFromDefinition } from './parse/readingParse'; import { pinyin } from 'pinyin-pro'; -export const LANGUAGE_CODES = ['ja', 'zh'] as const; +export const LANGUAGE_CODES = [ + 'hu', + 'eu', + 'pt', + 'ga', + 'el', + 'de', + 'eo', + 'ar', + 'id', + 'pl', + 'cs', + 'ca', + 'sv', + 'ru', + 'nl', + 'uk', + 'en', + 'ko', + 'es', + 'ja', + 'zh', + 'fr', + 'it', +] as const; + export type LanguageCode = (typeof LANGUAGE_CODES)[number]; export const languageUtils: { - [key in LanguageCode]: { + [key: string]: { getReading: (definition: string, term: string) => string; + fullName: string; }; } = { + hu: { + getReading: (definition, term) => '', + fullName: 'Hungarian', + }, + eu: { + getReading: (definition, term) => '', + fullName: 'Basque', + }, + pt: { + getReading: (definition, term) => '', + fullName: 'Portuguese', + }, + ga: { + getReading: (definition, term) => '', + fullName: 'Irish', + }, + el: { + getReading: (definition, term) => '', + fullName: 'Greek', + }, + de: { + getReading: (definition, term) => '', + fullName: 'German', + }, + eo: { + getReading: (definition, term) => '', + fullName: 'Esperanto', + }, + ar: { + getReading: (definition, term) => '', + fullName: 'Arabic', + }, + id: { + getReading: (definition, term) => '', + fullName: 'Indonesian', + }, + pl: { + getReading: (definition, term) => '', + fullName: 'Polish', + }, + cs: { + getReading: (definition, term) => '', + fullName: 'Czech', + }, + ca: { + getReading: (definition, term) => '', + fullName: 'Catalan', + }, + sv: { + getReading: (definition, term) => '', + fullName: 'Swedish', + }, + ru: { + getReading: (definition, term) => '', + fullName: 'Russian', + }, + nl: { + getReading: (definition, term) => '', + fullName: 'Dutch', + }, + uk: { + getReading: (definition, term) => '', + fullName: 'Ukrainian', + }, + en: { + getReading: (definition, term) => '', + fullName: 'English', + }, + ko: { + getReading: (definition, term) => '', + fullName: 'Korean', + }, + es: { + getReading: (definition, term) => '', + fullName: 'Spanish', + }, ja: { getReading: (definition, term) => getReadingFromDefinition(definition, term), + fullName: 'Japanese', }, zh: { getReading: (definition, term) => pinyin(term, { mode: 'surname' }).replace(/ /g, ''), + fullName: 'Chinese', + }, + fr: { + getReading: (definition, term) => '', + fullName: 'French', + }, + it: { + getReading: (definition, term) => '', + fullName: 'Italian', }, }; diff --git a/src/util/downloadDumps.ts b/src/util/downloadDumps.ts index efc91cf..ece6582 100644 --- a/src/util/downloadDumps.ts +++ b/src/util/downloadDumps.ts @@ -1,7 +1,7 @@ import { $ } from 'bun'; import { exists } from 'node:fs/promises'; import { join } from 'path'; -import { LanguageCode, languageUtils } from '../constants'; +import { LanguageCode } from '../constants'; const ARCHIVE = (lang: string) => `short-abstracts_lang=${lang.toLowerCase()}.ttl.bz2`; diff --git a/src/util/readArgs.ts b/src/util/readArgs.ts index 9cc51e0..df34e42 100644 --- a/src/util/readArgs.ts +++ b/src/util/readArgs.ts @@ -1,5 +1,5 @@ import { parseArgs } from 'util'; -import { LanguageCode, languageUtils } from '../constants'; +import { LANGUAGE_CODES, LanguageCode, languageUtils } from '../constants'; export function readArgs() { const { values } = parseArgs({ @@ -21,11 +21,11 @@ export function readArgs() { const dateInput = values.date as string; // Assert language is valid - if (!langInput || !languageUtils[langInput]) { + if (!langInput || !LANGUAGE_CODES.includes(langInput)) { throw new Error( - `Language ${langInput} is not allowed or not provided. Allowed languages: ${Object.keys( - languageUtils - ).join(', ')}` + `Language ${langInput} is not allowed or not provided. Allowed languages: ${LANGUAGE_CODES.join( + ', ' + )}` ); }