Skip to content

Commit

Permalink
Expand language codes
Browse files Browse the repository at this point in the history
  • Loading branch information
MarvNC committed Jul 12, 2024
1 parent f17ef49 commit 6288be5
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 8 deletions.
116 changes: 114 additions & 2 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
};

Expand Down
2 changes: 1 addition & 1 deletion src/util/downloadDumps.ts
Original file line number Diff line number Diff line change
@@ -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`;
Expand Down
10 changes: 5 additions & 5 deletions src/util/readArgs.ts
Original file line number Diff line number Diff line change
@@ -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({
Expand All @@ -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(
', '
)}`
);
}

Expand Down

0 comments on commit 6288be5

Please sign in to comment.