Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(module): add support for swedish language #939

Merged
merged 3 commits into from
Oct 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ Korean
Malagasy
Polish, Portuguese Brazil
Romanian, Russian
Spanish
Spanish, Swedish
Tagalog, Tandroy, Tankarana, Turkish, Twin
Ukrainian
Vezo
Expand Down
4 changes: 3 additions & 1 deletion src/browser/utils.browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import CH from '../locales/cmn-Hant/text.json';
import CHS from '../locales/ch-CHS/text.json';
import E from '../locales/en/text.json';
import F from '../locales/fr-FR/text.json';
import FI from '../locales/fi-FI/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';
Expand All @@ -23,6 +24,7 @@ import TW from '../locales/tw-TW/text.json';
import U from '../locales/ru-RU/text.json';
import VZ from '../locales/mg-VZ/text.json';
import X from '../locales/de-DE/text.json';
import Z from '../locales/sv-SE/text.json';

declare global {
interface Window {
Expand All @@ -31,6 +33,6 @@ declare global {
}

window.jw_epub_parser = {
languages: { CH, CHS, E, F, I, J, K, KO, M, MG, P, S, T, TG, TK, TND, TNK, TPO, TTM, TW, U, VZ, X },
languages: { CH, CHS, E, F, FI, I, J, K, KO, M, MG, P, S, T, TG, TK, TND, TNK, TPO, TTM, TW, U, VZ, X, Z },
path: path,
};
8 changes: 8 additions & 0 deletions src/common/date_parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ const mwbDatePatterns: LangRegExp = {
CH: new RegExp(mwbDatePatternJ, 'giu'),
CHS: new RegExp(mwbDatePatternJ, 'giu'),
E: new RegExp(mwbDatePatternE, 'giu'),
FI: new RegExp(mwbDatePatternX, 'giu'),
J: new RegExp(mwbDatePatternJ, 'giu'),
KO: new RegExp(mwbDatePatternKO, 'giu'),
P: new RegExp(mwbDatePatternP, 'giu'),
Expand Down Expand Up @@ -230,11 +231,18 @@ option1 = `(\\d{1,2}). bis (?:\\d{1,2}).? (${wordWithDiacritics}) (\\d{4})`;
option2 = `(\\d{1,2}). (${wordWithDiacritics}) (\\d{4})`;
const wDatePatternX = `${option1}|${option2}`;

// 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})';
option2 = '(\\d{1,2}).(\\d{1,2}).[–](?:\\d{1,2}).(?:\\d{1,2}).(\\d{4})';
option3 = '(\\d{1,2}).(\\d{1,2}).(\\d{4})';
const wDatePatternFI = `${option1}|${option2}|${option3}`;

const wDatePatterns: LangRegExp = {
common: new RegExp(wDatePatternCommon, 'giu'),
CH: new RegExp(wDatePatternJ, 'giu'),
CHS: new RegExp(wDatePatternJ, 'giu'),
E: new RegExp(wDatePatternE, 'giu'),
FI: new RegExp(wDatePatternFI, 'giu'),
J: new RegExp(wDatePatternJ, 'giu'),
KO: new RegExp(wDatePatternKO, 'giu'),
P: new RegExp(wDatePatternP, 'giu'),
Expand Down
48 changes: 25 additions & 23 deletions src/locales/languages.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
export default [
{ locale: 'en', code: 'E' },
{ locale: 'fr-FR', code: 'F' },
{ 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' },
{ locale: 'es-ES', code: 'S' },
{ locale: 'pt-BR', code: 'T' },
{ locale: 'pt-PT', code: 'TPO'},
{ locale: 'tl-PH', code: 'TG' },
{ locale: 'tr-TR', code: 'TK' },
{ locale: 'mg-TND', code: 'TND' },
{ locale: 'mg-TNK', code: 'TNK' },
{ locale: 'mg-TTM', code: 'TTM' },
{ locale: 'tw-TW', code: 'TW' },
{ locale: 'uk-UA', code: 'U' },
{ locale: 'mg-VZ', code: 'VZ' },
{ locale: 'de-DE', code: 'X' },
{ locale: 'cmn-Hant', code: 'CH' },
{ locale: 'ch-CHS', code: 'CHS' },
{ locale: 'en', code: 'E' },
{ locale: 'fr-FR', code: 'F' },
{ 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' },
{ locale: 'es-ES', code: 'S' },
{ locale: 'pt-BR', code: 'T' },
{ locale: 'pt-PT', code: 'TPO' },
{ locale: 'tl-PH', code: 'TG' },
{ locale: 'tr-TR', code: 'TK' },
{ locale: 'mg-TND', code: 'TND' },
{ locale: 'mg-TNK', code: 'TNK' },
{ locale: 'mg-TTM', code: 'TTM' },
{ locale: 'tw-TW', code: 'TW' },
{ locale: 'uk-UA', code: 'U' },
{ locale: 'mg-VZ', code: 'VZ' },
{ locale: 'de-DE', code: 'X' },
{ locale: 'cmn-Hant', code: 'CH' },
{ locale: 'ch-CHS', code: 'CHS' },
{ locale: 'fi-FI', code: 'FI' },
{ locale: 'sv-SE', code: 'Z' },
];
4 changes: 3 additions & 1 deletion src/node/utils.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import CH from '../locales/cmn-Hant/text.json' assert { type: 'json' };
import CHS from '../locales/ch-CHS/text.json' assert { type: 'json' };
import E from '../locales/en/text.json' assert { type: 'json' };
import F from '../locales/fr-FR/text.json' assert { type: 'json' };
import FI from '../locales/fi-FI/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' };
Expand All @@ -24,13 +25,14 @@ import TW from '../locales/tw-TW/text.json' assert { type: 'json' };
import U from '../locales/ru-RU/text.json' assert { type: 'json' };
import VZ from '../locales/mg-VZ/text.json' assert { type: 'json' };
import X from '../locales/de-DE/text.json' assert { type: 'json' };
import Z from '../locales/sv-SE/text.json' assert { type: 'json' };

declare global {
var jw_epub_parser: any;
}

global.jw_epub_parser = {
languages: { CH, CHS, E, F, I, J, K, KO, M, MG, P, S, T, TG, TK, TND, TNK, TPO, TTM, TW, U, VZ, X },
languages: { CH, CHS, E, F, FI, I, J, K, KO, M, MG, P, S, T, TG, TK, TND, TNK, TPO, TTM, TW, U, VZ, X, Z },
path: path,
readFile: readFile,
};
Loading