Skip to content

Commit

Permalink
Move languages info to constants file
Browse files Browse the repository at this point in the history
  • Loading branch information
MarvNC committed Jan 19, 2024
1 parent d02a59b commit 0701a99
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 17 deletions.
63 changes: 63 additions & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/**
* @type {Record<string, { name: string, shortName: string }>}
*/
const languages = {
yue: {
name: '廣東話',
shortName: '粵',
},
eng: {
name: '英文',
shortName: '英',
},
zho: {
name: '中文',
shortName: '中',
},
jpn: {
name: '日文',
shortName: '日',
},
kor: {
name: '韓文',
shortName: '韓',
},
vie: {
name: '越南文',
shortName: '越',
},
lzh: {
name: '文言文',
shortName: '文',
},
por: {
name: '葡萄牙文',
shortName: '葡',
},
deu: {
name: '德文',
shortName: '德',
},
fra: {
name: '法文',
shortName: '法',
},
mnc: {
name: '滿文',
shortName: '滿',
},
lat: {
name: '拉丁文',
shortName: '拉',
},
tib: {
name: '藏文',
shortName: '藏',
},
量詞: {
name: '量詞',
shortName: '量詞',
},
};

export { languages };
19 changes: 2 additions & 17 deletions src/util/parseEntry.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,4 @@
const possibleLangs = [
'yue',
'eng',
'zho',
'jpn',
'kor',
'vie',
'lzh',
'por',
'deu',
'fra',
'mnc',
'lat',
'tib',
'量詞',
];
import { languages } from '../constants.js';

/**
*
Expand Down Expand Up @@ -173,7 +158,7 @@ function parseLanguageData(text) {
continue;
}
// Check if the language is a possible language
if (!possibleLangs.includes(matchedLang)) {
if (!languages[matchedLang]) {
throw new Error(`Invalid language: ${matchedLang}`);
}
// Else a language is found
Expand Down

0 comments on commit 0701a99

Please sign in to comment.