Skip to content

Commit

Permalink
feat(locales): add slovenian language
Browse files Browse the repository at this point in the history
  • Loading branch information
rhahao committed Nov 9, 2024
1 parent 6416171 commit b86d1dd
Show file tree
Hide file tree
Showing 11 changed files with 786 additions and 24 deletions.
34 changes: 33 additions & 1 deletion src/browser/utils.browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import O from '../locales/nl-NL/text.json';
import P from '../locales/pl-PL/text.json';
import PGW from '../locales/wes-PGW/text.json';
import S from '../locales/es-ES/text.json';
import SV from '../locales/sl-SI/text.json';
import SW from '../locales/sw-KE/text.json';
import T from '../locales/pt-BR/text.json';
import TG from '../locales/tl-PH/text.json';
import TK from '../locales/tr-TR/text.json';
Expand All @@ -35,6 +37,36 @@ declare global {
}

window.jw_epub_parser = {
languages: { CH, CHS, E, F, FI, I, J, K, KO, M, MG, O, P, PGW, S, T, TG, TK, TND, TNK, TPO, TTM, TW, U, VZ, X, Z },
languages: {
CH,
CHS,
E,
F,
FI,
I,
J,
K,
KO,
M,
MG,
O,
P,
PGW,
S,
SV,
SW,
T,
TG,
TK,
TND,
TNK,
TPO,
TTM,
TW,
U,
VZ,
X,
Z,
},
path: path,
};
28 changes: 20 additions & 8 deletions src/common/date_parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ option2 = `(\\d{1,2}) de (${wordWithDiacritics}) a (?:\\d{1,2}) de (?:${wordWith
option3 = `(\\d{1,2}) de (${wordWithDiacritics}) de (\\d{4})`;
const mwbDatePatternTPO = `${option1}|${option2}|${option3}`;

// date like 1-) 4-10 de noviembre; or 2) 25 de noviembre a 1 de diciembre; or 3) 30 de diciembre de 2024 a 5 de enero de 2025
// date like 1-) 4.-10. de noviembre; or 2) 25. noviembre - 1. de diciembre; or 3) 30. diciembre 2024-5. enero 2025
option1 = `(\\d{1,2}).[-–](?:\\d{1,2}). (${wordWithDiacritics})`;
option2 = `(\\d{1,2}). (${wordWithDiacritics}) [-–] (?:\\d{1,2}). (?:${wordWithDiacritics})`;
option2 = `(\\d{1,2}). (${wordWithDiacritics}) ?[-–] ?(?:\\d{1,2}). (?:${wordWithDiacritics})`;
option3 = `(\\d{1,2}). (${wordWithDiacritics}) (\\d{4})`;
const mwbDatePatternX = `${option1}|${option2}|${option3}`;

Expand All @@ -75,6 +75,8 @@ const mwbDatePatterns: LangRegExp = {
P: new RegExp(mwbDatePatternP, 'giu'),
PGW: new RegExp(mwbDatePatternE, 'giu'),
S: new RegExp(mwbDatePatternS, 'giu'),
SV: new RegExp(mwbDatePatternX, 'giu'),
SW: new RegExp(mwbDatePatternE, 'giu'),
T: new RegExp(mwbDatePatternT, 'giu'),
TG: new RegExp(mwbDatePatternE, 'giu'),
TPO: new RegExp(mwbDatePatternTPO, 'giu'),
Expand Down Expand Up @@ -127,6 +129,7 @@ const mwbDateParsing: MWBDateParsing = {
J: mwbParsingE,
KO: mwbParsingE,
PGW: mwbParsingE,
SW: mwbParsingE,
TG: mwbParsingE,
TW: mwbParsingE,
};
Expand Down Expand Up @@ -181,8 +184,9 @@ const wDatePatternCommon = `${option1}|${option2}|${option3}`;

// date like 1-) December 16-22, 2024; or 2) December 30, 2024-January 5, 2025
option1 = `(${wordWithDiacritics}) (\\d{1,2})[-–](?:\\d{1,2})?, (\\d{4})`;
option2 = `(${wordWithDiacritics}) (\\d{1,2}), (\\d{4})`;
const wDatePatternE = `${option1}|${option2}`;
option2 = `(${wordWithDiacritics}) (\\d{1,2})[-–](?:${wordWithDiacritics}) (?:\\d{1,2}), (\\d{4})`;
option3 = `(${wordWithDiacritics}) (\\d{1,2}), (\\d{4})`;
const wDatePatternE = `${option1}|${option2}|${option3}`;

// date like 1-) 2024年12月16-22日; or 2) 2024年12月30日-2025年1月5日
option1 = `(\\d{4})年(?:nián)?(\\d{1,2})月(?:yuè)?(\\d{1,2})[-–~](\\d{1,2})日`;
Expand Down Expand Up @@ -229,9 +233,10 @@ option3 = `(${wordWithDiacritics}) (\\d{1,2}), (\\d{4})`;
const wDatePatternTW = `${option1}|${option2}|${option3}`;

// date like 1-) 40. Studienartikel: 9. bis 15. Dezember 2024; or 2) 43. Studienartikel: 30. Dezember 2024 bis 5. Januar 2025
option1 = `(\\d{1,2}). bis (?:\\d{1,2}).? (${wordWithDiacritics}) (\\d{4})`;
option2 = `(\\d{1,2}). (${wordWithDiacritics}) (\\d{4})`;
const wDatePatternX = `${option1}|${option2}`;
option1 = `(\\d{1,2}).(?:${dateRangeSeparator})(?:\\d{1,2}).? (${wordWithDiacritics}) (\\d{4})`;
option2 = `(\\d{1,2}). (${wordWithDiacritics})(?:${dateRangeSeparator})(?:\\d{1,2}).? (?:${wordWithDiacritics}) (\\d{4})`;
option3 = `(\\d{1,2}). (${wordWithDiacritics}) (\\d{4})`;
const wDatePatternX = `${option1}|${option2}|${option3}`;

// date like 1-) Tutkitaan 3.–9.2.2025 ; or 2) Tutkitaan 24.2.–2.3.2025. ; or 3) Tutkitaan 30.12.2024–5.1.2025.
option1 = '(\\d{1,2}).[–](?:\\d{1,2}).(\\d{1,2}).(\\d{4})';
Expand All @@ -250,6 +255,8 @@ const wDatePatterns: LangRegExp = {
P: new RegExp(wDatePatternP, 'giu'),
PGW: new RegExp(wDatePatternE, 'giu'),
S: new RegExp(wDatePatternS, 'giu'),
SV: new RegExp(wDatePatternX, 'giu'),
SW: new RegExp(wDatePatternE, 'giu'),
T: new RegExp(wDatePatternT, 'giu'),
TPO: new RegExp(wDatePatternTPO, 'giu'),
TG: new RegExp(wDatePatternE, 'giu'),
Expand Down Expand Up @@ -288,10 +295,14 @@ const wParsingE = (groups: string[]): WDateParsingResult => {
month = groups[1];
date = groups[2];
year = groups[3];
} else {
} else if (groups[4]) {
month = groups[4];
date = groups[5];
year = groups[6];
} else {
month = groups[7];
date = groups[8];
year = groups[9];
}

return [year, month, date];
Expand Down Expand Up @@ -341,6 +352,7 @@ const wDateParsing: WDateParsing = {
J: wParsingJ,
KO: wParsingJ,
PGW: wParsingE,
SW: wParsingE,
TG: wParsingE,
TW: wParsingTW,
};
Expand Down
1 change: 1 addition & 0 deletions src/common/parsing_rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export const extractSourceEnhanced = (src: string, lang: string) => {

const firstPattern: LangRegExp = {
common: firstPatternCommon,
SW: firstPatternTW,
TW: firstPatternTW,
};

Expand Down
2 changes: 2 additions & 0 deletions src/locales/languages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ export default [
{ locale: 'sv-SE', code: 'Z' },
{ locale: 'nl-NL', code: 'O' },
{ locale: 'wes-PGW', code: 'PGW' },
{ locale: 'sl-SI', code: 'SV' },
{ locale: 'sw-KE', code: 'SW' },
];
26 changes: 13 additions & 13 deletions src/locales/sl-SI/text.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"januaryVariations": "januar",
"februaryVariations": "februar",
"marchVariations": "marec",
"aprilVariations": "april",
"mayVariations": "maj",
"juneVariations": "junij",
"julyVariations": "julij",
"augustVariations": "avgust",
"septemberVariations": "september",
"octoberVariations": "oktober",
"novemberVariations": "november",
"decemberVariations": "december",
"partMinutesSeparatorVariations": "min."
"januaryVariations": "januar|januarja",
"februaryVariations": "februar|februarja",
"marchVariations": "marec|marca",
"aprilVariations": "april|aprila",
"mayVariations": "maj|maja",
"juneVariations": "junij|junija",
"julyVariations": "julij|julija",
"augustVariations": "avgust|avgusta",
"septemberVariations": "september|septembra",
"octoberVariations": "oktober|oktobra",
"novemberVariations": "november|novembra",
"decemberVariations": "december|decembra",
"partMinutesSeparatorVariations": "min."
}
34 changes: 33 additions & 1 deletion src/node/utils.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import O from '../locales/nl-NL/text.json' assert { type: 'json' };
import P from '../locales/pl-PL/text.json' assert { type: 'json' };
import PGW from '../locales/wes-PGW/text.json' assert { type: 'json' };
import S from '../locales/es-ES/text.json' assert { type: 'json' };
import SV from '../locales/sl-SI/text.json' assert { type: 'json' };
import SW from '../locales/sw-KE/text.json' assert { type: 'json' };
import T from '../locales/pt-BR/text.json' assert { type: 'json' };
import TG from '../locales/tl-PH/text.json' assert { type: 'json' };
import TK from '../locales/tr-TR/text.json' assert { type: 'json' };
Expand All @@ -34,7 +36,37 @@ declare global {
}

global.jw_epub_parser = {
languages: { CH, CHS, E, F, FI, I, J, K, KO, M, MG, O, P, PGW, S, T, TG, TK, TND, TNK, TPO, TTM, TW, U, VZ, X, Z },
languages: {
CH,
CHS,
E,
F,
FI,
I,
J,
K,
KO,
M,
MG,
O,
P,
PGW,
S,
SV,
SW,
T,
TG,
TK,
TND,
TNK,
TPO,
TTM,
TW,
U,
VZ,
X,
Z,
},
path: path,
readFile: readFile,
};
5 changes: 4 additions & 1 deletion test/enhancedParsing/list.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,8 @@
{ "language": "VZ", "issue": "202411" },
{ "language": "X", "issue": "202411" },
{ "language": "O", "issue": "202411" },
{ "language": "PGW", "issue": "202411" }
{ "language": "Z", "issue": "202411" },
{ "language": "PGW", "issue": "202411" },
{ "language": "SV", "issue": "202411" },
{ "language": "SW", "issue": "202411" }
]
Loading

0 comments on commit b86d1dd

Please sign in to comment.