Skip to content

Commit

Permalink
feat(module): add support for korean language
Browse files Browse the repository at this point in the history
  • Loading branch information
rhahao committed Oct 4, 2024
1 parent e8b8401 commit a007c88
Show file tree
Hide file tree
Showing 9 changed files with 354 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"recommendations": [
"esbenp.prettier-vscode"
]
}
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ French
German
Italian
Japanese
Madagascar Sign Language, Malagasy
Korean
Malagasy
Polish, Portuguese Brazil
Romanian, Russian
Spanish
Expand Down
3 changes: 2 additions & 1 deletion src/browser/utils.browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import F from '../locales/fr-FR/text.json';
import I from '../locales/it-IT/text.json';
import J from '../locales/ja-JP/text.json';
import K from '../locales/uk-UA/text.json';
import KO from '../locales/ko-KR/text.json';
import M from '../locales/ro-RO/text.json';
import MG from '../locales/mg-MG/text.json';
import P from '../locales/pl-PL/text.json';
Expand All @@ -30,6 +31,6 @@ declare global {
}

window.jw_epub_parser = {
languages: { CH, CHS, E, F, I, J, K, M, MG, P, S, T, TG, TK, TND, TNK, TPO, TTM, TW, U, VZ, X },
languages: { CH, CHS, E, F, I, J, K, KO, M, MG, P, S, T, TG, TK, TND, TNK, TPO, TTM, TW, U, VZ, X },
path: path,
};
15 changes: 15 additions & 0 deletions src/common/date_parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ option2 = `(\\d{1,2})月(\\d{1,2})日`;
option3 = `(?:\\d{4})年(\\d{1,2})月(\\d{1,2})日`;
const mwbDatePatternJ = `${option1}|${option2}|${option3}`;

// date like 1-) 11월 4-10일; or 2) 11월 25일–12월 1일; or 3) 2024년 12월 30일–2025년 1월 5일
option1 = `(\\d{1,2})월 (\\d{1,2})[-–](?:\\d{1,2})일`;
option2 = `(\\d{1,2})월 (\\d{1,2})일`;
option3 = `(?:\\d{4})년 (\\d{1,2})월 (\\d{1,2})일`;
const mwbDatePatternKO = `${option1}|${option2}|${option3}`;

// date like 1-) 4-10 listopada; or 2) 25 listopada do 1 grudnia; or 3) 30 grudnia 2024 do 5 stycznia 2025
option1 = `(\\d{1,2})[-–](?:\\d{1,2}) (${wordWithDiacritics})`;
option2 = `(\\d{1,2}) (${wordWithDiacritics}) do (?:\\d{1,2}) (?:${wordWithDiacritics})`;
Expand Down Expand Up @@ -64,6 +70,7 @@ const mwbDatePatterns: LangRegExp = {
CHS: new RegExp(mwbDatePatternJ, 'giu'),
E: new RegExp(mwbDatePatternE, 'giu'),
J: new RegExp(mwbDatePatternJ, 'giu'),
KO: new RegExp(mwbDatePatternKO, 'giu'),
P: new RegExp(mwbDatePatternP, 'giu'),
S: new RegExp(mwbDatePatternS, 'giu'),
T: new RegExp(mwbDatePatternT, 'giu'),
Expand Down Expand Up @@ -116,6 +123,7 @@ const mwbDateParsing: MWBDateParsing = {
CHS: mwbParsingE,
E: mwbParsingE,
J: mwbParsingE,
KO: mwbParsingE,
TG: mwbParsingE,
TW: mwbParsingE,
};
Expand Down Expand Up @@ -178,6 +186,11 @@ option1 = `(\\d{4})年(?:nián)?(\\d{1,2})月(?:yuè)?(\\d{1,2})[-–~](\\d{1,
option2 = `(\\d{4})年(?:nián)?(\\d{1,2})月(?:yuè)?(\\d{1,2})日`;
const wDatePatternJ = `${option1}|${option2}`;

// date like 1-) 2024년 10월 7-13일; or 2) 2024년 10월 28일–2024년 11월 3일
option1 = `(\\d{4})년 (\\d{1,2})월 (\\d{1,2})[-–](\\d{1,2})일`;
option2 = `(\\d{4})년 (\\d{1,2})월 (\\d{1,2})일`;
const wDatePatternKO = `${option1}|${option2}`;

// date like 1-) Artykuł do studium w tygodniu od 14 do 20 października 2024 roku; or 2) Artykuł do studium w tygodniu od 28 października do 3 listopada 2024 roku; or 3) Artykuł do studium w tygodniu od 30 grudnia 2024 roku do 5 stycznia 2025 roku.
option1 = `(\\d{1,2}) do (?:\\d{1,2})? (${wordWithDiacritics}) (\\d{4})`;
option2 = `(\\d{1,2}) (${wordWithDiacritics}) do (?:\\d{1,2}) (?:${wordWithDiacritics}) (\\d{4})`;
Expand Down Expand Up @@ -223,6 +236,7 @@ const wDatePatterns: LangRegExp = {
CHS: new RegExp(wDatePatternJ, 'giu'),
E: new RegExp(wDatePatternE, 'giu'),
J: new RegExp(wDatePatternJ, 'giu'),
KO: new RegExp(wDatePatternKO, 'giu'),
P: new RegExp(wDatePatternP, 'giu'),
S: new RegExp(wDatePatternS, 'giu'),
T: new RegExp(wDatePatternT, 'giu'),
Expand Down Expand Up @@ -314,6 +328,7 @@ const wDateParsing: WDateParsing = {
CHS: wParsingJ,
E: wParsingE,
J: wParsingJ,
KO: wParsingJ,
TG: wParsingE,
TW: wParsingTW,
};
Expand Down
1 change: 1 addition & 0 deletions src/locales/languages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export default [
{ locale: 'it-IT', code: 'I' },
{ locale: 'ja-JP', code: 'J' },
{ locale: 'uk-UA', code: 'K' },
{ locale: 'ko-KR', code: 'KO' },
{ locale: 'ro-RO', code: 'M' },
{ locale: 'mg-MG', code: 'MG' },
{ locale: 'pl-PL', code: 'P' },
Expand Down
3 changes: 2 additions & 1 deletion src/node/utils.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import F from '../locales/fr-FR/text.json' assert { type: 'json' };
import I from '../locales/it-IT/text.json' assert { type: 'json' };
import J from '../locales/ja-JP/text.json' assert { type: 'json' };
import K from '../locales/uk-UA/text.json' assert { type: 'json' };
import KO from '../locales/ko-KR/text.json' assert { type: 'json' };
import M from '../locales/ro-RO/text.json' assert { type: 'json' };
import MG from '../locales/mg-MG/text.json' assert { type: 'json' };
import P from '../locales/pl-PL/text.json' assert { type: 'json' };
Expand All @@ -29,7 +30,7 @@ declare global {
}

global.jw_epub_parser = {
languages: { CH, CHS, E, F, I, J, K, M, MG, P, S, T, TG, TK, TND, TNK, TPO, TTM, TW, U, VZ, X },
languages: { CH, CHS, E, F, I, J, K, KO, M, MG, P, S, T, TG, TK, TND, TNK, TPO, TTM, TW, U, VZ, X },
path: path,
readFile: readFile,
};
1 change: 1 addition & 0 deletions test/enhancedParsing/list.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
{ "language": "I", "issue": "202411" },
{ "language": "J", "issue": "202411" },
{ "language": "K", "issue": "202411" },
{ "language": "KO", "issue": "202411" },
{ "language": "M", "issue": "202411" },
{ "language": "MG", "issue": "202411" },
{ "language": "S", "issue": "202411" },
Expand Down
Loading

0 comments on commit a007c88

Please sign in to comment.