@cherrystudio/file-preview 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +661 -0
- package/README.md +247 -2
- package/dist/Combination-BLg27FvF.js +1044 -0
- package/dist/EchartsChartRenderer-e2b5JysX.js +39859 -0
- package/dist/FilePreviewTooLarge-DkHa6toZ.js +27 -0
- package/dist/ImageFilePreview-BO8rLRZv.js +2171 -0
- package/dist/PdfFilePreview-D3Ie0_mm.js +29747 -0
- package/dist/PowerPointFilePreview-BLfF0zcm.js +58032 -0
- package/dist/SpreadsheetFilePreview-DJdoyeis.js +3217 -0
- package/dist/WordFilePreview-DSqt7Uq2.js +4137 -0
- package/dist/assets/cmaps/78-EUC-H.bcmap +0 -0
- package/dist/assets/cmaps/78-EUC-V.bcmap +0 -0
- package/dist/assets/cmaps/78-H.bcmap +0 -0
- package/dist/assets/cmaps/78-RKSJ-H.bcmap +0 -0
- package/dist/assets/cmaps/78-RKSJ-V.bcmap +0 -0
- package/dist/assets/cmaps/78-V.bcmap +0 -0
- package/dist/assets/cmaps/78ms-RKSJ-H.bcmap +0 -0
- package/dist/assets/cmaps/78ms-RKSJ-V.bcmap +0 -0
- package/dist/assets/cmaps/83pv-RKSJ-H.bcmap +0 -0
- package/dist/assets/cmaps/90ms-RKSJ-H.bcmap +0 -0
- package/dist/assets/cmaps/90ms-RKSJ-V.bcmap +0 -0
- package/dist/assets/cmaps/90msp-RKSJ-H.bcmap +0 -0
- package/dist/assets/cmaps/90msp-RKSJ-V.bcmap +0 -0
- package/dist/assets/cmaps/90pv-RKSJ-H.bcmap +0 -0
- package/dist/assets/cmaps/90pv-RKSJ-V.bcmap +0 -0
- package/dist/assets/cmaps/Add-H.bcmap +0 -0
- package/dist/assets/cmaps/Add-RKSJ-H.bcmap +0 -0
- package/dist/assets/cmaps/Add-RKSJ-V.bcmap +0 -0
- package/dist/assets/cmaps/Add-V.bcmap +0 -0
- package/dist/assets/cmaps/Adobe-CNS1-0.bcmap +0 -0
- package/dist/assets/cmaps/Adobe-CNS1-1.bcmap +0 -0
- package/dist/assets/cmaps/Adobe-CNS1-2.bcmap +0 -0
- package/dist/assets/cmaps/Adobe-CNS1-3.bcmap +0 -0
- package/dist/assets/cmaps/Adobe-CNS1-4.bcmap +0 -0
- package/dist/assets/cmaps/Adobe-CNS1-5.bcmap +0 -0
- package/dist/assets/cmaps/Adobe-CNS1-6.bcmap +0 -0
- package/dist/assets/cmaps/Adobe-CNS1-UCS2.bcmap +0 -0
- package/dist/assets/cmaps/Adobe-GB1-0.bcmap +0 -0
- package/dist/assets/cmaps/Adobe-GB1-1.bcmap +0 -0
- package/dist/assets/cmaps/Adobe-GB1-2.bcmap +0 -0
- package/dist/assets/cmaps/Adobe-GB1-3.bcmap +0 -0
- package/dist/assets/cmaps/Adobe-GB1-4.bcmap +0 -0
- package/dist/assets/cmaps/Adobe-GB1-5.bcmap +0 -0
- package/dist/assets/cmaps/Adobe-GB1-UCS2.bcmap +0 -0
- package/dist/assets/cmaps/Adobe-Japan1-0.bcmap +0 -0
- package/dist/assets/cmaps/Adobe-Japan1-1.bcmap +0 -0
- package/dist/assets/cmaps/Adobe-Japan1-2.bcmap +0 -0
- package/dist/assets/cmaps/Adobe-Japan1-3.bcmap +0 -0
- package/dist/assets/cmaps/Adobe-Japan1-4.bcmap +0 -0
- package/dist/assets/cmaps/Adobe-Japan1-5.bcmap +0 -0
- package/dist/assets/cmaps/Adobe-Japan1-6.bcmap +0 -0
- package/dist/assets/cmaps/Adobe-Japan1-UCS2.bcmap +0 -0
- package/dist/assets/cmaps/Adobe-Korea1-0.bcmap +0 -0
- package/dist/assets/cmaps/Adobe-Korea1-1.bcmap +0 -0
- package/dist/assets/cmaps/Adobe-Korea1-2.bcmap +0 -0
- package/dist/assets/cmaps/Adobe-Korea1-UCS2.bcmap +0 -0
- package/dist/assets/cmaps/B5-H.bcmap +0 -0
- package/dist/assets/cmaps/B5-V.bcmap +0 -0
- package/dist/assets/cmaps/B5pc-H.bcmap +0 -0
- package/dist/assets/cmaps/B5pc-V.bcmap +0 -0
- package/dist/assets/cmaps/CNS-EUC-H.bcmap +0 -0
- package/dist/assets/cmaps/CNS-EUC-V.bcmap +0 -0
- package/dist/assets/cmaps/CNS1-H.bcmap +0 -0
- package/dist/assets/cmaps/CNS1-V.bcmap +0 -0
- package/dist/assets/cmaps/CNS2-H.bcmap +0 -0
- package/dist/assets/cmaps/CNS2-V.bcmap +3 -0
- package/dist/assets/cmaps/ETHK-B5-H.bcmap +0 -0
- package/dist/assets/cmaps/ETHK-B5-V.bcmap +0 -0
- package/dist/assets/cmaps/ETen-B5-H.bcmap +0 -0
- package/dist/assets/cmaps/ETen-B5-V.bcmap +0 -0
- package/dist/assets/cmaps/ETenms-B5-H.bcmap +3 -0
- package/dist/assets/cmaps/ETenms-B5-V.bcmap +0 -0
- package/dist/assets/cmaps/EUC-H.bcmap +0 -0
- package/dist/assets/cmaps/EUC-V.bcmap +0 -0
- package/dist/assets/cmaps/Ext-H.bcmap +0 -0
- package/dist/assets/cmaps/Ext-RKSJ-H.bcmap +0 -0
- package/dist/assets/cmaps/Ext-RKSJ-V.bcmap +0 -0
- package/dist/assets/cmaps/Ext-V.bcmap +0 -0
- package/dist/assets/cmaps/GB-EUC-H.bcmap +0 -0
- package/dist/assets/cmaps/GB-EUC-V.bcmap +0 -0
- package/dist/assets/cmaps/GB-H.bcmap +4 -0
- package/dist/assets/cmaps/GB-V.bcmap +0 -0
- package/dist/assets/cmaps/GBK-EUC-H.bcmap +0 -0
- package/dist/assets/cmaps/GBK-EUC-V.bcmap +0 -0
- package/dist/assets/cmaps/GBK2K-H.bcmap +0 -0
- package/dist/assets/cmaps/GBK2K-V.bcmap +0 -0
- package/dist/assets/cmaps/GBKp-EUC-H.bcmap +0 -0
- package/dist/assets/cmaps/GBKp-EUC-V.bcmap +0 -0
- package/dist/assets/cmaps/GBT-EUC-H.bcmap +0 -0
- package/dist/assets/cmaps/GBT-EUC-V.bcmap +0 -0
- package/dist/assets/cmaps/GBT-H.bcmap +0 -0
- package/dist/assets/cmaps/GBT-V.bcmap +0 -0
- package/dist/assets/cmaps/GBTpc-EUC-H.bcmap +0 -0
- package/dist/assets/cmaps/GBTpc-EUC-V.bcmap +0 -0
- package/dist/assets/cmaps/GBpc-EUC-H.bcmap +0 -0
- package/dist/assets/cmaps/GBpc-EUC-V.bcmap +0 -0
- package/dist/assets/cmaps/H.bcmap +0 -0
- package/dist/assets/cmaps/HKdla-B5-H.bcmap +0 -0
- package/dist/assets/cmaps/HKdla-B5-V.bcmap +0 -0
- package/dist/assets/cmaps/HKdlb-B5-H.bcmap +0 -0
- package/dist/assets/cmaps/HKdlb-B5-V.bcmap +0 -0
- package/dist/assets/cmaps/HKgccs-B5-H.bcmap +0 -0
- package/dist/assets/cmaps/HKgccs-B5-V.bcmap +0 -0
- package/dist/assets/cmaps/HKm314-B5-H.bcmap +0 -0
- package/dist/assets/cmaps/HKm314-B5-V.bcmap +0 -0
- package/dist/assets/cmaps/HKm471-B5-H.bcmap +0 -0
- package/dist/assets/cmaps/HKm471-B5-V.bcmap +0 -0
- package/dist/assets/cmaps/HKscs-B5-H.bcmap +0 -0
- package/dist/assets/cmaps/HKscs-B5-V.bcmap +0 -0
- package/dist/assets/cmaps/Hankaku.bcmap +0 -0
- package/dist/assets/cmaps/Hiragana.bcmap +0 -0
- package/dist/assets/cmaps/KSC-EUC-H.bcmap +0 -0
- package/dist/assets/cmaps/KSC-EUC-V.bcmap +0 -0
- package/dist/assets/cmaps/KSC-H.bcmap +0 -0
- package/dist/assets/cmaps/KSC-Johab-H.bcmap +0 -0
- package/dist/assets/cmaps/KSC-Johab-V.bcmap +0 -0
- package/dist/assets/cmaps/KSC-V.bcmap +0 -0
- package/dist/assets/cmaps/KSCms-UHC-H.bcmap +0 -0
- package/dist/assets/cmaps/KSCms-UHC-HW-H.bcmap +0 -0
- package/dist/assets/cmaps/KSCms-UHC-HW-V.bcmap +0 -0
- package/dist/assets/cmaps/KSCms-UHC-V.bcmap +0 -0
- package/dist/assets/cmaps/KSCpc-EUC-H.bcmap +0 -0
- package/dist/assets/cmaps/KSCpc-EUC-V.bcmap +0 -0
- package/dist/assets/cmaps/Katakana.bcmap +0 -0
- package/dist/assets/cmaps/LICENSE +36 -0
- package/dist/assets/cmaps/NWP-H.bcmap +0 -0
- package/dist/assets/cmaps/NWP-V.bcmap +0 -0
- package/dist/assets/cmaps/RKSJ-H.bcmap +0 -0
- package/dist/assets/cmaps/RKSJ-V.bcmap +0 -0
- package/dist/assets/cmaps/Roman.bcmap +0 -0
- package/dist/assets/cmaps/UniCNS-UCS2-H.bcmap +0 -0
- package/dist/assets/cmaps/UniCNS-UCS2-V.bcmap +0 -0
- package/dist/assets/cmaps/UniCNS-UTF16-H.bcmap +0 -0
- package/dist/assets/cmaps/UniCNS-UTF16-V.bcmap +0 -0
- package/dist/assets/cmaps/UniCNS-UTF32-H.bcmap +0 -0
- package/dist/assets/cmaps/UniCNS-UTF32-V.bcmap +0 -0
- package/dist/assets/cmaps/UniCNS-UTF8-H.bcmap +0 -0
- package/dist/assets/cmaps/UniCNS-UTF8-V.bcmap +0 -0
- package/dist/assets/cmaps/UniGB-UCS2-H.bcmap +0 -0
- package/dist/assets/cmaps/UniGB-UCS2-V.bcmap +0 -0
- package/dist/assets/cmaps/UniGB-UTF16-H.bcmap +0 -0
- package/dist/assets/cmaps/UniGB-UTF16-V.bcmap +0 -0
- package/dist/assets/cmaps/UniGB-UTF32-H.bcmap +0 -0
- package/dist/assets/cmaps/UniGB-UTF32-V.bcmap +0 -0
- package/dist/assets/cmaps/UniGB-UTF8-H.bcmap +0 -0
- package/dist/assets/cmaps/UniGB-UTF8-V.bcmap +0 -0
- package/dist/assets/cmaps/UniJIS-UCS2-H.bcmap +0 -0
- package/dist/assets/cmaps/UniJIS-UCS2-HW-H.bcmap +0 -0
- package/dist/assets/cmaps/UniJIS-UCS2-HW-V.bcmap +0 -0
- package/dist/assets/cmaps/UniJIS-UCS2-V.bcmap +0 -0
- package/dist/assets/cmaps/UniJIS-UTF16-H.bcmap +0 -0
- package/dist/assets/cmaps/UniJIS-UTF16-V.bcmap +0 -0
- package/dist/assets/cmaps/UniJIS-UTF32-H.bcmap +0 -0
- package/dist/assets/cmaps/UniJIS-UTF32-V.bcmap +0 -0
- package/dist/assets/cmaps/UniJIS-UTF8-H.bcmap +0 -0
- package/dist/assets/cmaps/UniJIS-UTF8-V.bcmap +0 -0
- package/dist/assets/cmaps/UniJIS2004-UTF16-H.bcmap +0 -0
- package/dist/assets/cmaps/UniJIS2004-UTF16-V.bcmap +0 -0
- package/dist/assets/cmaps/UniJIS2004-UTF32-H.bcmap +0 -0
- package/dist/assets/cmaps/UniJIS2004-UTF32-V.bcmap +0 -0
- package/dist/assets/cmaps/UniJIS2004-UTF8-H.bcmap +0 -0
- package/dist/assets/cmaps/UniJIS2004-UTF8-V.bcmap +0 -0
- package/dist/assets/cmaps/UniJISPro-UCS2-HW-V.bcmap +0 -0
- package/dist/assets/cmaps/UniJISPro-UCS2-V.bcmap +0 -0
- package/dist/assets/cmaps/UniJISPro-UTF8-V.bcmap +0 -0
- package/dist/assets/cmaps/UniJISX0213-UTF32-H.bcmap +0 -0
- package/dist/assets/cmaps/UniJISX0213-UTF32-V.bcmap +0 -0
- package/dist/assets/cmaps/UniJISX02132004-UTF32-H.bcmap +0 -0
- package/dist/assets/cmaps/UniJISX02132004-UTF32-V.bcmap +0 -0
- package/dist/assets/cmaps/UniKS-UCS2-H.bcmap +0 -0
- package/dist/assets/cmaps/UniKS-UCS2-V.bcmap +0 -0
- package/dist/assets/cmaps/UniKS-UTF16-H.bcmap +0 -0
- package/dist/assets/cmaps/UniKS-UTF16-V.bcmap +0 -0
- package/dist/assets/cmaps/UniKS-UTF32-H.bcmap +0 -0
- package/dist/assets/cmaps/UniKS-UTF32-V.bcmap +0 -0
- package/dist/assets/cmaps/UniKS-UTF8-H.bcmap +0 -0
- package/dist/assets/cmaps/UniKS-UTF8-V.bcmap +0 -0
- package/dist/assets/cmaps/V.bcmap +0 -0
- package/dist/assets/cmaps/WP-Symbol.bcmap +0 -0
- package/dist/assets/pdf.worker.js +77187 -0
- package/dist/assets/standard_fonts/FoxitDingbats.pfb +0 -0
- package/dist/assets/standard_fonts/FoxitFixed.pfb +0 -0
- package/dist/assets/standard_fonts/FoxitFixedBold.pfb +0 -0
- package/dist/assets/standard_fonts/FoxitFixedBoldItalic.pfb +0 -0
- package/dist/assets/standard_fonts/FoxitFixedItalic.pfb +0 -0
- package/dist/assets/standard_fonts/FoxitSerif.pfb +0 -0
- package/dist/assets/standard_fonts/FoxitSerifBold.pfb +0 -0
- package/dist/assets/standard_fonts/FoxitSerifBoldItalic.pfb +0 -0
- package/dist/assets/standard_fonts/FoxitSerifItalic.pfb +0 -0
- package/dist/assets/standard_fonts/FoxitSymbol.pfb +0 -0
- package/dist/assets/standard_fonts/LICENSE_FOXIT +27 -0
- package/dist/assets/standard_fonts/LICENSE_LIBERATION +102 -0
- package/dist/assets/standard_fonts/LiberationSans-Bold.ttf +0 -0
- package/dist/assets/standard_fonts/LiberationSans-BoldItalic.ttf +0 -0
- package/dist/assets/standard_fonts/LiberationSans-Italic.ttf +0 -0
- package/dist/assets/standard_fonts/LiberationSans-Regular.ttf +0 -0
- package/dist/assets/xlsx.worker.js +61444 -0
- package/dist/core.d.ts +2 -0
- package/dist/core.js +3 -0
- package/dist/documentAnchor-J7GGLU15.js +69 -0
- package/dist/imageFilePreviewPlugin-CxIUlEmg.js +29 -0
- package/dist/jszip.min-uwqlc4KL.js +3108 -0
- package/dist/react.d.ts +105 -0
- package/dist/react.js +3114 -0
- package/dist/rolldown-runtime-B-lAHAz2.js +37 -0
- package/dist/rotate-ccw-YWx7RzY9.js +36 -0
- package/dist/selection-CQPD5a6C.js +47 -0
- package/dist/source-DjjzeN4t.d.ts +58 -0
- package/dist/source-Rx3etU3y.js +28 -0
- package/dist/styles.css +8778 -0
- package/dist/styles.js +0 -0
- package/dist/touchPinch-C4fl-9fg.js +34 -0
- package/dist/useTranslation-DMhY277o.js +7056 -0
- package/dist/zoom-out-DLOQGt1e.js +66 -0
- package/package.json +69 -3
package/dist/react.js
ADDED
|
@@ -0,0 +1,3114 @@
|
|
|
1
|
+
import { n as assertPreviewRange, t as PreviewError } from "./source-Rx3etU3y.js";
|
|
2
|
+
import { F as cn, I as LoaderCircle, L as FileWarning, N as EmptyState, R as createLucideIcon, a as PreviewHostContext, c as FilePreviewToolbar, f as DialogPortalContainerProvider, i as FilePreviewLayout, l as FilePreviewToolbarPortalHost, n as I18nContext, o as usePreviewHost, p as PortalContainerProvider, r as FilePreviewToolbarButton, t as useTranslation, u as FilePreviewToolbarPortalProvider } from "./useTranslation-DMhY277o.js";
|
|
3
|
+
import { t as imageFilePreviewPlugin } from "./imageFilePreviewPlugin-CxIUlEmg.js";
|
|
4
|
+
import { Component, Suspense, createContext, createElement, lazy, useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
5
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
+
/**
|
|
7
|
+
* @license lucide-react v0.545.0 - ISC
|
|
8
|
+
*
|
|
9
|
+
* This source code is licensed under the ISC license.
|
|
10
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
11
|
+
*/
|
|
12
|
+
var FileQuestionMark = createLucideIcon("file-question-mark", [
|
|
13
|
+
["path", {
|
|
14
|
+
d: "M12 17h.01",
|
|
15
|
+
key: "p32p05"
|
|
16
|
+
}],
|
|
17
|
+
["path", {
|
|
18
|
+
d: "M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7z",
|
|
19
|
+
key: "1mlx9k"
|
|
20
|
+
}],
|
|
21
|
+
["path", {
|
|
22
|
+
d: "M9.1 9a3 3 0 0 1 5.82 1c0 2-3 3-3 3",
|
|
23
|
+
key: "mhlwft"
|
|
24
|
+
}]
|
|
25
|
+
]);
|
|
26
|
+
//#endregion
|
|
27
|
+
//#region src/filePreviewRegistry.ts
|
|
28
|
+
var plugins = [
|
|
29
|
+
imageFilePreviewPlugin,
|
|
30
|
+
{
|
|
31
|
+
id: "pdf",
|
|
32
|
+
extensions: ["pdf"],
|
|
33
|
+
mediaTypes: ["application/pdf"],
|
|
34
|
+
load: () => import("./PdfFilePreview-D3Ie0_mm.js"),
|
|
35
|
+
supportsSelectionReference: true
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
id: "powerpoint",
|
|
39
|
+
extensions: ["pptx"],
|
|
40
|
+
mediaTypes: ["application/vnd.openxmlformats-officedocument.presentationml.presentation"],
|
|
41
|
+
load: () => import("./PowerPointFilePreview-BLfF0zcm.js"),
|
|
42
|
+
supportsSelectionReference: true
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
id: "spreadsheet",
|
|
46
|
+
extensions: ["xlsx"],
|
|
47
|
+
mediaTypes: ["application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"],
|
|
48
|
+
load: () => import("./SpreadsheetFilePreview-DJdoyeis.js"),
|
|
49
|
+
supportsSelectionReference: true
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
id: "word",
|
|
53
|
+
extensions: ["docx"],
|
|
54
|
+
mediaTypes: ["application/vnd.openxmlformats-officedocument.wordprocessingml.document"],
|
|
55
|
+
load: () => import("./WordFilePreview-DSqt7Uq2.js"),
|
|
56
|
+
supportsSelectionReference: true
|
|
57
|
+
}
|
|
58
|
+
];
|
|
59
|
+
var previewFormats = plugins.map(({ id, extensions, supportsSelectionReference }) => ({
|
|
60
|
+
id,
|
|
61
|
+
extensions,
|
|
62
|
+
supportsSelectionReference: supportsSelectionReference === true
|
|
63
|
+
}));
|
|
64
|
+
function resolvePreviewPlugin(name, mediaType) {
|
|
65
|
+
const normalizedMediaType = mediaType?.split(";", 1)[0].trim().toLowerCase();
|
|
66
|
+
const mediaTypePlugin = plugins.find((plugin) => plugin.mediaTypes.includes(normalizedMediaType ?? ""));
|
|
67
|
+
if (mediaTypePlugin) return mediaTypePlugin;
|
|
68
|
+
const extension = name.split(/[\\/]/).at(-1)?.match(/\.([^.]+)$/)?.[1].toLowerCase();
|
|
69
|
+
return plugins.find((plugin) => plugin.extensions.includes(extension ?? "")) ?? null;
|
|
70
|
+
}
|
|
71
|
+
function supportsPreview(name, mediaType) {
|
|
72
|
+
return resolvePreviewPlugin(name, mediaType) !== null;
|
|
73
|
+
}
|
|
74
|
+
function canSelectPreview(name, mediaType) {
|
|
75
|
+
return resolvePreviewPlugin(name, mediaType)?.supportsSelectionReference === true;
|
|
76
|
+
}
|
|
77
|
+
//#endregion
|
|
78
|
+
//#region ../../node_modules/.pnpm/react-error-boundary@6.0.1_react-dom@19.2.3_react@19.2.3__react@19.2.3/node_modules/react-error-boundary/dist/react-error-boundary.js
|
|
79
|
+
var h = createContext(null);
|
|
80
|
+
var c = {
|
|
81
|
+
didCatch: !1,
|
|
82
|
+
error: null
|
|
83
|
+
};
|
|
84
|
+
var m = class extends Component {
|
|
85
|
+
constructor(t) {
|
|
86
|
+
super(t), this.resetErrorBoundary = this.resetErrorBoundary.bind(this), this.state = c;
|
|
87
|
+
}
|
|
88
|
+
static getDerivedStateFromError(t) {
|
|
89
|
+
return {
|
|
90
|
+
didCatch: !0,
|
|
91
|
+
error: t
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
resetErrorBoundary(...t) {
|
|
95
|
+
const { error: e } = this.state;
|
|
96
|
+
e !== null && (this.props.onReset?.({
|
|
97
|
+
args: t,
|
|
98
|
+
reason: "imperative-api"
|
|
99
|
+
}), this.setState(c));
|
|
100
|
+
}
|
|
101
|
+
componentDidCatch(t, e) {
|
|
102
|
+
this.props.onError?.(t, e);
|
|
103
|
+
}
|
|
104
|
+
componentDidUpdate(t, e) {
|
|
105
|
+
const { didCatch: o } = this.state, { resetKeys: n } = this.props;
|
|
106
|
+
o && e.error !== null && C(t.resetKeys, n) && (this.props.onReset?.({
|
|
107
|
+
next: n,
|
|
108
|
+
prev: t.resetKeys,
|
|
109
|
+
reason: "keys"
|
|
110
|
+
}), this.setState(c));
|
|
111
|
+
}
|
|
112
|
+
render() {
|
|
113
|
+
const { children: t, fallbackRender: e, FallbackComponent: o, fallback: n } = this.props, { didCatch: s, error: a } = this.state;
|
|
114
|
+
let i = t;
|
|
115
|
+
if (s) {
|
|
116
|
+
const u = {
|
|
117
|
+
error: a,
|
|
118
|
+
resetErrorBoundary: this.resetErrorBoundary
|
|
119
|
+
};
|
|
120
|
+
if (typeof e == "function") i = e(u);
|
|
121
|
+
else if (o) i = createElement(o, u);
|
|
122
|
+
else if (n !== void 0) i = n;
|
|
123
|
+
else throw a;
|
|
124
|
+
}
|
|
125
|
+
return createElement(h.Provider, { value: {
|
|
126
|
+
didCatch: s,
|
|
127
|
+
error: a,
|
|
128
|
+
resetErrorBoundary: this.resetErrorBoundary
|
|
129
|
+
} }, i);
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
function C(r = [], t = []) {
|
|
133
|
+
return r.length !== t.length || r.some((e, o) => !Object.is(e, t[o]));
|
|
134
|
+
}
|
|
135
|
+
//#endregion
|
|
136
|
+
//#region ../../node_modules/.pnpm/react-i18next@14.1.3_i18next@23.16.8_react-dom@19.2.3_react@19.2.3__react@19.2.3/node_modules/react-i18next/dist/es/I18nextProvider.js
|
|
137
|
+
function I18nextProvider(_ref) {
|
|
138
|
+
let { i18n, defaultNS, children } = _ref;
|
|
139
|
+
const value = useMemo(() => ({
|
|
140
|
+
i18n,
|
|
141
|
+
defaultNS
|
|
142
|
+
}), [i18n, defaultNS]);
|
|
143
|
+
return createElement(I18nContext.Provider, { value }, children);
|
|
144
|
+
}
|
|
145
|
+
//#endregion
|
|
146
|
+
//#region ../../node_modules/.pnpm/i18next@23.16.8/node_modules/i18next/dist/esm/i18next.js
|
|
147
|
+
var isString = (obj) => typeof obj === "string";
|
|
148
|
+
var defer = () => {
|
|
149
|
+
let res;
|
|
150
|
+
let rej;
|
|
151
|
+
const promise = new Promise((resolve, reject) => {
|
|
152
|
+
res = resolve;
|
|
153
|
+
rej = reject;
|
|
154
|
+
});
|
|
155
|
+
promise.resolve = res;
|
|
156
|
+
promise.reject = rej;
|
|
157
|
+
return promise;
|
|
158
|
+
};
|
|
159
|
+
var makeString = (object) => {
|
|
160
|
+
if (object == null) return "";
|
|
161
|
+
return "" + object;
|
|
162
|
+
};
|
|
163
|
+
var copy = (a, s, t) => {
|
|
164
|
+
a.forEach((m) => {
|
|
165
|
+
if (s[m]) t[m] = s[m];
|
|
166
|
+
});
|
|
167
|
+
};
|
|
168
|
+
var lastOfPathSeparatorRegExp = /###/g;
|
|
169
|
+
var cleanKey = (key) => key && key.indexOf("###") > -1 ? key.replace(lastOfPathSeparatorRegExp, ".") : key;
|
|
170
|
+
var canNotTraverseDeeper = (object) => !object || isString(object);
|
|
171
|
+
var getLastOfPath = (object, path, Empty) => {
|
|
172
|
+
const stack = !isString(path) ? path : path.split(".");
|
|
173
|
+
let stackIndex = 0;
|
|
174
|
+
while (stackIndex < stack.length - 1) {
|
|
175
|
+
if (canNotTraverseDeeper(object)) return {};
|
|
176
|
+
const key = cleanKey(stack[stackIndex]);
|
|
177
|
+
if (!object[key] && Empty) object[key] = new Empty();
|
|
178
|
+
if (Object.prototype.hasOwnProperty.call(object, key)) object = object[key];
|
|
179
|
+
else object = {};
|
|
180
|
+
++stackIndex;
|
|
181
|
+
}
|
|
182
|
+
if (canNotTraverseDeeper(object)) return {};
|
|
183
|
+
return {
|
|
184
|
+
obj: object,
|
|
185
|
+
k: cleanKey(stack[stackIndex])
|
|
186
|
+
};
|
|
187
|
+
};
|
|
188
|
+
var setPath = (object, path, newValue) => {
|
|
189
|
+
const { obj, k } = getLastOfPath(object, path, Object);
|
|
190
|
+
if (obj !== void 0 || path.length === 1) {
|
|
191
|
+
obj[k] = newValue;
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
let e = path[path.length - 1];
|
|
195
|
+
let p = path.slice(0, path.length - 1);
|
|
196
|
+
let last = getLastOfPath(object, p, Object);
|
|
197
|
+
while (last.obj === void 0 && p.length) {
|
|
198
|
+
e = `${p[p.length - 1]}.${e}`;
|
|
199
|
+
p = p.slice(0, p.length - 1);
|
|
200
|
+
last = getLastOfPath(object, p, Object);
|
|
201
|
+
if (last && last.obj && typeof last.obj[`${last.k}.${e}`] !== "undefined") last.obj = void 0;
|
|
202
|
+
}
|
|
203
|
+
last.obj[`${last.k}.${e}`] = newValue;
|
|
204
|
+
};
|
|
205
|
+
var pushPath = (object, path, newValue, concat) => {
|
|
206
|
+
const { obj, k } = getLastOfPath(object, path, Object);
|
|
207
|
+
obj[k] = obj[k] || [];
|
|
208
|
+
obj[k].push(newValue);
|
|
209
|
+
};
|
|
210
|
+
var getPath = (object, path) => {
|
|
211
|
+
const { obj, k } = getLastOfPath(object, path);
|
|
212
|
+
if (!obj) return void 0;
|
|
213
|
+
return obj[k];
|
|
214
|
+
};
|
|
215
|
+
var getPathWithDefaults = (data, defaultData, key) => {
|
|
216
|
+
const value = getPath(data, key);
|
|
217
|
+
if (value !== void 0) return value;
|
|
218
|
+
return getPath(defaultData, key);
|
|
219
|
+
};
|
|
220
|
+
var deepExtend = (target, source, overwrite) => {
|
|
221
|
+
for (const prop in source) if (prop !== "__proto__" && prop !== "constructor") {
|
|
222
|
+
if (prop in target) {
|
|
223
|
+
if (isString(target[prop]) || target[prop] instanceof String || isString(source[prop]) || source[prop] instanceof String) {
|
|
224
|
+
if (overwrite) target[prop] = source[prop];
|
|
225
|
+
} else deepExtend(target[prop], source[prop], overwrite);
|
|
226
|
+
} else target[prop] = source[prop];
|
|
227
|
+
}
|
|
228
|
+
return target;
|
|
229
|
+
};
|
|
230
|
+
var regexEscape = (str) => str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
|
|
231
|
+
var _entityMap = {
|
|
232
|
+
"&": "&",
|
|
233
|
+
"<": "<",
|
|
234
|
+
">": ">",
|
|
235
|
+
"\"": """,
|
|
236
|
+
"'": "'",
|
|
237
|
+
"/": "/"
|
|
238
|
+
};
|
|
239
|
+
var escape = (data) => {
|
|
240
|
+
if (isString(data)) return data.replace(/[&<>"'\/]/g, (s) => _entityMap[s]);
|
|
241
|
+
return data;
|
|
242
|
+
};
|
|
243
|
+
var RegExpCache = class {
|
|
244
|
+
constructor(capacity) {
|
|
245
|
+
this.capacity = capacity;
|
|
246
|
+
this.regExpMap = /* @__PURE__ */ new Map();
|
|
247
|
+
this.regExpQueue = [];
|
|
248
|
+
}
|
|
249
|
+
getRegExp(pattern) {
|
|
250
|
+
const regExpFromCache = this.regExpMap.get(pattern);
|
|
251
|
+
if (regExpFromCache !== void 0) return regExpFromCache;
|
|
252
|
+
const regExpNew = new RegExp(pattern);
|
|
253
|
+
if (this.regExpQueue.length === this.capacity) this.regExpMap.delete(this.regExpQueue.shift());
|
|
254
|
+
this.regExpMap.set(pattern, regExpNew);
|
|
255
|
+
this.regExpQueue.push(pattern);
|
|
256
|
+
return regExpNew;
|
|
257
|
+
}
|
|
258
|
+
};
|
|
259
|
+
var chars = [
|
|
260
|
+
" ",
|
|
261
|
+
",",
|
|
262
|
+
"?",
|
|
263
|
+
"!",
|
|
264
|
+
";"
|
|
265
|
+
];
|
|
266
|
+
var looksLikeObjectPathRegExpCache = new RegExpCache(20);
|
|
267
|
+
var looksLikeObjectPath = (key, nsSeparator, keySeparator) => {
|
|
268
|
+
nsSeparator = nsSeparator || "";
|
|
269
|
+
keySeparator = keySeparator || "";
|
|
270
|
+
const possibleChars = chars.filter((c) => nsSeparator.indexOf(c) < 0 && keySeparator.indexOf(c) < 0);
|
|
271
|
+
if (possibleChars.length === 0) return true;
|
|
272
|
+
const r = looksLikeObjectPathRegExpCache.getRegExp(`(${possibleChars.map((c) => c === "?" ? "\\?" : c).join("|")})`);
|
|
273
|
+
let matched = !r.test(key);
|
|
274
|
+
if (!matched) {
|
|
275
|
+
const ki = key.indexOf(keySeparator);
|
|
276
|
+
if (ki > 0 && !r.test(key.substring(0, ki))) matched = true;
|
|
277
|
+
}
|
|
278
|
+
return matched;
|
|
279
|
+
};
|
|
280
|
+
var deepFind = function(obj, path) {
|
|
281
|
+
let keySeparator = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : ".";
|
|
282
|
+
if (!obj) return void 0;
|
|
283
|
+
if (obj[path]) return obj[path];
|
|
284
|
+
const tokens = path.split(keySeparator);
|
|
285
|
+
let current = obj;
|
|
286
|
+
for (let i = 0; i < tokens.length;) {
|
|
287
|
+
if (!current || typeof current !== "object") return;
|
|
288
|
+
let next;
|
|
289
|
+
let nextPath = "";
|
|
290
|
+
for (let j = i; j < tokens.length; ++j) {
|
|
291
|
+
if (j !== i) nextPath += keySeparator;
|
|
292
|
+
nextPath += tokens[j];
|
|
293
|
+
next = current[nextPath];
|
|
294
|
+
if (next !== void 0) {
|
|
295
|
+
if ([
|
|
296
|
+
"string",
|
|
297
|
+
"number",
|
|
298
|
+
"boolean"
|
|
299
|
+
].indexOf(typeof next) > -1 && j < tokens.length - 1) continue;
|
|
300
|
+
i += j - i + 1;
|
|
301
|
+
break;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
current = next;
|
|
305
|
+
}
|
|
306
|
+
return current;
|
|
307
|
+
};
|
|
308
|
+
var getCleanedCode = (code) => code && code.replace("_", "-");
|
|
309
|
+
var consoleLogger = {
|
|
310
|
+
type: "logger",
|
|
311
|
+
log(args) {
|
|
312
|
+
this.output("log", args);
|
|
313
|
+
},
|
|
314
|
+
warn(args) {
|
|
315
|
+
this.output("warn", args);
|
|
316
|
+
},
|
|
317
|
+
error(args) {
|
|
318
|
+
this.output("error", args);
|
|
319
|
+
},
|
|
320
|
+
output(type, args) {
|
|
321
|
+
if (console && console[type]) console[type].apply(console, args);
|
|
322
|
+
}
|
|
323
|
+
};
|
|
324
|
+
var baseLogger = new class Logger {
|
|
325
|
+
constructor(concreteLogger) {
|
|
326
|
+
let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
327
|
+
this.init(concreteLogger, options);
|
|
328
|
+
}
|
|
329
|
+
init(concreteLogger) {
|
|
330
|
+
let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
331
|
+
this.prefix = options.prefix || "i18next:";
|
|
332
|
+
this.logger = concreteLogger || consoleLogger;
|
|
333
|
+
this.options = options;
|
|
334
|
+
this.debug = options.debug;
|
|
335
|
+
}
|
|
336
|
+
log() {
|
|
337
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) args[_key] = arguments[_key];
|
|
338
|
+
return this.forward(args, "log", "", true);
|
|
339
|
+
}
|
|
340
|
+
warn() {
|
|
341
|
+
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) args[_key2] = arguments[_key2];
|
|
342
|
+
return this.forward(args, "warn", "", true);
|
|
343
|
+
}
|
|
344
|
+
error() {
|
|
345
|
+
for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) args[_key3] = arguments[_key3];
|
|
346
|
+
return this.forward(args, "error", "");
|
|
347
|
+
}
|
|
348
|
+
deprecate() {
|
|
349
|
+
for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) args[_key4] = arguments[_key4];
|
|
350
|
+
return this.forward(args, "warn", "WARNING DEPRECATED: ", true);
|
|
351
|
+
}
|
|
352
|
+
forward(args, lvl, prefix, debugOnly) {
|
|
353
|
+
if (debugOnly && !this.debug) return null;
|
|
354
|
+
if (isString(args[0])) args[0] = `${prefix}${this.prefix} ${args[0]}`;
|
|
355
|
+
return this.logger[lvl](args);
|
|
356
|
+
}
|
|
357
|
+
create(moduleName) {
|
|
358
|
+
return new Logger(this.logger, {
|
|
359
|
+
prefix: `${this.prefix}:${moduleName}:`,
|
|
360
|
+
...this.options
|
|
361
|
+
});
|
|
362
|
+
}
|
|
363
|
+
clone(options) {
|
|
364
|
+
options = options || this.options;
|
|
365
|
+
options.prefix = options.prefix || this.prefix;
|
|
366
|
+
return new Logger(this.logger, options);
|
|
367
|
+
}
|
|
368
|
+
}();
|
|
369
|
+
var EventEmitter = class {
|
|
370
|
+
constructor() {
|
|
371
|
+
this.observers = {};
|
|
372
|
+
}
|
|
373
|
+
on(events, listener) {
|
|
374
|
+
events.split(" ").forEach((event) => {
|
|
375
|
+
if (!this.observers[event]) this.observers[event] = /* @__PURE__ */ new Map();
|
|
376
|
+
const numListeners = this.observers[event].get(listener) || 0;
|
|
377
|
+
this.observers[event].set(listener, numListeners + 1);
|
|
378
|
+
});
|
|
379
|
+
return this;
|
|
380
|
+
}
|
|
381
|
+
off(event, listener) {
|
|
382
|
+
if (!this.observers[event]) return;
|
|
383
|
+
if (!listener) {
|
|
384
|
+
delete this.observers[event];
|
|
385
|
+
return;
|
|
386
|
+
}
|
|
387
|
+
this.observers[event].delete(listener);
|
|
388
|
+
}
|
|
389
|
+
emit(event) {
|
|
390
|
+
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) args[_key - 1] = arguments[_key];
|
|
391
|
+
if (this.observers[event]) Array.from(this.observers[event].entries()).forEach((_ref) => {
|
|
392
|
+
let [observer, numTimesAdded] = _ref;
|
|
393
|
+
for (let i = 0; i < numTimesAdded; i++) observer(...args);
|
|
394
|
+
});
|
|
395
|
+
if (this.observers["*"]) Array.from(this.observers["*"].entries()).forEach((_ref2) => {
|
|
396
|
+
let [observer, numTimesAdded] = _ref2;
|
|
397
|
+
for (let i = 0; i < numTimesAdded; i++) observer.apply(observer, [event, ...args]);
|
|
398
|
+
});
|
|
399
|
+
}
|
|
400
|
+
};
|
|
401
|
+
var ResourceStore = class extends EventEmitter {
|
|
402
|
+
constructor(data) {
|
|
403
|
+
let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {
|
|
404
|
+
ns: ["translation"],
|
|
405
|
+
defaultNS: "translation"
|
|
406
|
+
};
|
|
407
|
+
super();
|
|
408
|
+
this.data = data || {};
|
|
409
|
+
this.options = options;
|
|
410
|
+
if (this.options.keySeparator === void 0) this.options.keySeparator = ".";
|
|
411
|
+
if (this.options.ignoreJSONStructure === void 0) this.options.ignoreJSONStructure = true;
|
|
412
|
+
}
|
|
413
|
+
addNamespaces(ns) {
|
|
414
|
+
if (this.options.ns.indexOf(ns) < 0) this.options.ns.push(ns);
|
|
415
|
+
}
|
|
416
|
+
removeNamespaces(ns) {
|
|
417
|
+
const index = this.options.ns.indexOf(ns);
|
|
418
|
+
if (index > -1) this.options.ns.splice(index, 1);
|
|
419
|
+
}
|
|
420
|
+
getResource(lng, ns, key) {
|
|
421
|
+
let options = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : {};
|
|
422
|
+
const keySeparator = options.keySeparator !== void 0 ? options.keySeparator : this.options.keySeparator;
|
|
423
|
+
const ignoreJSONStructure = options.ignoreJSONStructure !== void 0 ? options.ignoreJSONStructure : this.options.ignoreJSONStructure;
|
|
424
|
+
let path;
|
|
425
|
+
if (lng.indexOf(".") > -1) path = lng.split(".");
|
|
426
|
+
else {
|
|
427
|
+
path = [lng, ns];
|
|
428
|
+
if (key) {
|
|
429
|
+
if (Array.isArray(key)) path.push(...key);
|
|
430
|
+
else if (isString(key) && keySeparator) path.push(...key.split(keySeparator));
|
|
431
|
+
else path.push(key);
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
const result = getPath(this.data, path);
|
|
435
|
+
if (!result && !ns && !key && lng.indexOf(".") > -1) {
|
|
436
|
+
lng = path[0];
|
|
437
|
+
ns = path[1];
|
|
438
|
+
key = path.slice(2).join(".");
|
|
439
|
+
}
|
|
440
|
+
if (result || !ignoreJSONStructure || !isString(key)) return result;
|
|
441
|
+
return deepFind(this.data && this.data[lng] && this.data[lng][ns], key, keySeparator);
|
|
442
|
+
}
|
|
443
|
+
addResource(lng, ns, key, value) {
|
|
444
|
+
let options = arguments.length > 4 && arguments[4] !== void 0 ? arguments[4] : { silent: false };
|
|
445
|
+
const keySeparator = options.keySeparator !== void 0 ? options.keySeparator : this.options.keySeparator;
|
|
446
|
+
let path = [lng, ns];
|
|
447
|
+
if (key) path = path.concat(keySeparator ? key.split(keySeparator) : key);
|
|
448
|
+
if (lng.indexOf(".") > -1) {
|
|
449
|
+
path = lng.split(".");
|
|
450
|
+
value = ns;
|
|
451
|
+
ns = path[1];
|
|
452
|
+
}
|
|
453
|
+
this.addNamespaces(ns);
|
|
454
|
+
setPath(this.data, path, value);
|
|
455
|
+
if (!options.silent) this.emit("added", lng, ns, key, value);
|
|
456
|
+
}
|
|
457
|
+
addResources(lng, ns, resources) {
|
|
458
|
+
let options = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : { silent: false };
|
|
459
|
+
for (const m in resources) if (isString(resources[m]) || Array.isArray(resources[m])) this.addResource(lng, ns, m, resources[m], { silent: true });
|
|
460
|
+
if (!options.silent) this.emit("added", lng, ns, resources);
|
|
461
|
+
}
|
|
462
|
+
addResourceBundle(lng, ns, resources, deep, overwrite) {
|
|
463
|
+
let options = arguments.length > 5 && arguments[5] !== void 0 ? arguments[5] : {
|
|
464
|
+
silent: false,
|
|
465
|
+
skipCopy: false
|
|
466
|
+
};
|
|
467
|
+
let path = [lng, ns];
|
|
468
|
+
if (lng.indexOf(".") > -1) {
|
|
469
|
+
path = lng.split(".");
|
|
470
|
+
deep = resources;
|
|
471
|
+
resources = ns;
|
|
472
|
+
ns = path[1];
|
|
473
|
+
}
|
|
474
|
+
this.addNamespaces(ns);
|
|
475
|
+
let pack = getPath(this.data, path) || {};
|
|
476
|
+
if (!options.skipCopy) resources = JSON.parse(JSON.stringify(resources));
|
|
477
|
+
if (deep) deepExtend(pack, resources, overwrite);
|
|
478
|
+
else pack = {
|
|
479
|
+
...pack,
|
|
480
|
+
...resources
|
|
481
|
+
};
|
|
482
|
+
setPath(this.data, path, pack);
|
|
483
|
+
if (!options.silent) this.emit("added", lng, ns, resources);
|
|
484
|
+
}
|
|
485
|
+
removeResourceBundle(lng, ns) {
|
|
486
|
+
if (this.hasResourceBundle(lng, ns)) delete this.data[lng][ns];
|
|
487
|
+
this.removeNamespaces(ns);
|
|
488
|
+
this.emit("removed", lng, ns);
|
|
489
|
+
}
|
|
490
|
+
hasResourceBundle(lng, ns) {
|
|
491
|
+
return this.getResource(lng, ns) !== void 0;
|
|
492
|
+
}
|
|
493
|
+
getResourceBundle(lng, ns) {
|
|
494
|
+
if (!ns) ns = this.options.defaultNS;
|
|
495
|
+
if (this.options.compatibilityAPI === "v1") return { ...this.getResource(lng, ns) };
|
|
496
|
+
return this.getResource(lng, ns);
|
|
497
|
+
}
|
|
498
|
+
getDataByLanguage(lng) {
|
|
499
|
+
return this.data[lng];
|
|
500
|
+
}
|
|
501
|
+
hasLanguageSomeTranslations(lng) {
|
|
502
|
+
const data = this.getDataByLanguage(lng);
|
|
503
|
+
return !!(data && Object.keys(data) || []).find((v) => data[v] && Object.keys(data[v]).length > 0);
|
|
504
|
+
}
|
|
505
|
+
toJSON() {
|
|
506
|
+
return this.data;
|
|
507
|
+
}
|
|
508
|
+
};
|
|
509
|
+
var postProcessor = {
|
|
510
|
+
processors: {},
|
|
511
|
+
addPostProcessor(module) {
|
|
512
|
+
this.processors[module.name] = module;
|
|
513
|
+
},
|
|
514
|
+
handle(processors, value, key, options, translator) {
|
|
515
|
+
processors.forEach((processor) => {
|
|
516
|
+
if (this.processors[processor]) value = this.processors[processor].process(value, key, options, translator);
|
|
517
|
+
});
|
|
518
|
+
return value;
|
|
519
|
+
}
|
|
520
|
+
};
|
|
521
|
+
var checkedLoadedFor = {};
|
|
522
|
+
var Translator = class Translator extends EventEmitter {
|
|
523
|
+
constructor(services) {
|
|
524
|
+
let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
525
|
+
super();
|
|
526
|
+
copy([
|
|
527
|
+
"resourceStore",
|
|
528
|
+
"languageUtils",
|
|
529
|
+
"pluralResolver",
|
|
530
|
+
"interpolator",
|
|
531
|
+
"backendConnector",
|
|
532
|
+
"i18nFormat",
|
|
533
|
+
"utils"
|
|
534
|
+
], services, this);
|
|
535
|
+
this.options = options;
|
|
536
|
+
if (this.options.keySeparator === void 0) this.options.keySeparator = ".";
|
|
537
|
+
this.logger = baseLogger.create("translator");
|
|
538
|
+
}
|
|
539
|
+
changeLanguage(lng) {
|
|
540
|
+
if (lng) this.language = lng;
|
|
541
|
+
}
|
|
542
|
+
exists(key) {
|
|
543
|
+
let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : { interpolation: {} };
|
|
544
|
+
if (key === void 0 || key === null) return false;
|
|
545
|
+
const resolved = this.resolve(key, options);
|
|
546
|
+
return resolved && resolved.res !== void 0;
|
|
547
|
+
}
|
|
548
|
+
extractFromKey(key, options) {
|
|
549
|
+
let nsSeparator = options.nsSeparator !== void 0 ? options.nsSeparator : this.options.nsSeparator;
|
|
550
|
+
if (nsSeparator === void 0) nsSeparator = ":";
|
|
551
|
+
const keySeparator = options.keySeparator !== void 0 ? options.keySeparator : this.options.keySeparator;
|
|
552
|
+
let namespaces = options.ns || this.options.defaultNS || [];
|
|
553
|
+
const wouldCheckForNsInKey = nsSeparator && key.indexOf(nsSeparator) > -1;
|
|
554
|
+
const seemsNaturalLanguage = !this.options.userDefinedKeySeparator && !options.keySeparator && !this.options.userDefinedNsSeparator && !options.nsSeparator && !looksLikeObjectPath(key, nsSeparator, keySeparator);
|
|
555
|
+
if (wouldCheckForNsInKey && !seemsNaturalLanguage) {
|
|
556
|
+
const m = key.match(this.interpolator.nestingRegexp);
|
|
557
|
+
if (m && m.length > 0) return {
|
|
558
|
+
key,
|
|
559
|
+
namespaces: isString(namespaces) ? [namespaces] : namespaces
|
|
560
|
+
};
|
|
561
|
+
const parts = key.split(nsSeparator);
|
|
562
|
+
if (nsSeparator !== keySeparator || nsSeparator === keySeparator && this.options.ns.indexOf(parts[0]) > -1) namespaces = parts.shift();
|
|
563
|
+
key = parts.join(keySeparator);
|
|
564
|
+
}
|
|
565
|
+
return {
|
|
566
|
+
key,
|
|
567
|
+
namespaces: isString(namespaces) ? [namespaces] : namespaces
|
|
568
|
+
};
|
|
569
|
+
}
|
|
570
|
+
translate(keys, options, lastKey) {
|
|
571
|
+
if (typeof options !== "object" && this.options.overloadTranslationOptionHandler) options = this.options.overloadTranslationOptionHandler(arguments);
|
|
572
|
+
if (typeof options === "object") options = { ...options };
|
|
573
|
+
if (!options) options = {};
|
|
574
|
+
if (keys === void 0 || keys === null) return "";
|
|
575
|
+
if (!Array.isArray(keys)) keys = [String(keys)];
|
|
576
|
+
const returnDetails = options.returnDetails !== void 0 ? options.returnDetails : this.options.returnDetails;
|
|
577
|
+
const keySeparator = options.keySeparator !== void 0 ? options.keySeparator : this.options.keySeparator;
|
|
578
|
+
const { key, namespaces } = this.extractFromKey(keys[keys.length - 1], options);
|
|
579
|
+
const namespace = namespaces[namespaces.length - 1];
|
|
580
|
+
const lng = options.lng || this.language;
|
|
581
|
+
const appendNamespaceToCIMode = options.appendNamespaceToCIMode || this.options.appendNamespaceToCIMode;
|
|
582
|
+
if (lng && lng.toLowerCase() === "cimode") {
|
|
583
|
+
if (appendNamespaceToCIMode) {
|
|
584
|
+
const nsSeparator = options.nsSeparator || this.options.nsSeparator;
|
|
585
|
+
if (returnDetails) return {
|
|
586
|
+
res: `${namespace}${nsSeparator}${key}`,
|
|
587
|
+
usedKey: key,
|
|
588
|
+
exactUsedKey: key,
|
|
589
|
+
usedLng: lng,
|
|
590
|
+
usedNS: namespace,
|
|
591
|
+
usedParams: this.getUsedParamsDetails(options)
|
|
592
|
+
};
|
|
593
|
+
return `${namespace}${nsSeparator}${key}`;
|
|
594
|
+
}
|
|
595
|
+
if (returnDetails) return {
|
|
596
|
+
res: key,
|
|
597
|
+
usedKey: key,
|
|
598
|
+
exactUsedKey: key,
|
|
599
|
+
usedLng: lng,
|
|
600
|
+
usedNS: namespace,
|
|
601
|
+
usedParams: this.getUsedParamsDetails(options)
|
|
602
|
+
};
|
|
603
|
+
return key;
|
|
604
|
+
}
|
|
605
|
+
const resolved = this.resolve(keys, options);
|
|
606
|
+
let res = resolved && resolved.res;
|
|
607
|
+
const resUsedKey = resolved && resolved.usedKey || key;
|
|
608
|
+
const resExactUsedKey = resolved && resolved.exactUsedKey || key;
|
|
609
|
+
const resType = Object.prototype.toString.apply(res);
|
|
610
|
+
const noObject = [
|
|
611
|
+
"[object Number]",
|
|
612
|
+
"[object Function]",
|
|
613
|
+
"[object RegExp]"
|
|
614
|
+
];
|
|
615
|
+
const joinArrays = options.joinArrays !== void 0 ? options.joinArrays : this.options.joinArrays;
|
|
616
|
+
const handleAsObjectInI18nFormat = !this.i18nFormat || this.i18nFormat.handleAsObject;
|
|
617
|
+
const handleAsObject = !isString(res) && typeof res !== "boolean" && typeof res !== "number";
|
|
618
|
+
if (handleAsObjectInI18nFormat && res && handleAsObject && noObject.indexOf(resType) < 0 && !(isString(joinArrays) && Array.isArray(res))) {
|
|
619
|
+
if (!options.returnObjects && !this.options.returnObjects) {
|
|
620
|
+
if (!this.options.returnedObjectHandler) this.logger.warn("accessing an object - but returnObjects options is not enabled!");
|
|
621
|
+
const r = this.options.returnedObjectHandler ? this.options.returnedObjectHandler(resUsedKey, res, {
|
|
622
|
+
...options,
|
|
623
|
+
ns: namespaces
|
|
624
|
+
}) : `key '${key} (${this.language})' returned an object instead of string.`;
|
|
625
|
+
if (returnDetails) {
|
|
626
|
+
resolved.res = r;
|
|
627
|
+
resolved.usedParams = this.getUsedParamsDetails(options);
|
|
628
|
+
return resolved;
|
|
629
|
+
}
|
|
630
|
+
return r;
|
|
631
|
+
}
|
|
632
|
+
if (keySeparator) {
|
|
633
|
+
const resTypeIsArray = Array.isArray(res);
|
|
634
|
+
const copy = resTypeIsArray ? [] : {};
|
|
635
|
+
const newKeyToUse = resTypeIsArray ? resExactUsedKey : resUsedKey;
|
|
636
|
+
for (const m in res) if (Object.prototype.hasOwnProperty.call(res, m)) {
|
|
637
|
+
const deepKey = `${newKeyToUse}${keySeparator}${m}`;
|
|
638
|
+
copy[m] = this.translate(deepKey, {
|
|
639
|
+
...options,
|
|
640
|
+
joinArrays: false,
|
|
641
|
+
ns: namespaces
|
|
642
|
+
});
|
|
643
|
+
if (copy[m] === deepKey) copy[m] = res[m];
|
|
644
|
+
}
|
|
645
|
+
res = copy;
|
|
646
|
+
}
|
|
647
|
+
} else if (handleAsObjectInI18nFormat && isString(joinArrays) && Array.isArray(res)) {
|
|
648
|
+
res = res.join(joinArrays);
|
|
649
|
+
if (res) res = this.extendTranslation(res, keys, options, lastKey);
|
|
650
|
+
} else {
|
|
651
|
+
let usedDefault = false;
|
|
652
|
+
let usedKey = false;
|
|
653
|
+
const needsPluralHandling = options.count !== void 0 && !isString(options.count);
|
|
654
|
+
const hasDefaultValue = Translator.hasDefaultValue(options);
|
|
655
|
+
const defaultValueSuffix = needsPluralHandling ? this.pluralResolver.getSuffix(lng, options.count, options) : "";
|
|
656
|
+
const defaultValueSuffixOrdinalFallback = options.ordinal && needsPluralHandling ? this.pluralResolver.getSuffix(lng, options.count, { ordinal: false }) : "";
|
|
657
|
+
const needsZeroSuffixLookup = needsPluralHandling && !options.ordinal && options.count === 0 && this.pluralResolver.shouldUseIntlApi();
|
|
658
|
+
const defaultValue = needsZeroSuffixLookup && options[`defaultValue${this.options.pluralSeparator}zero`] || options[`defaultValue${defaultValueSuffix}`] || options[`defaultValue${defaultValueSuffixOrdinalFallback}`] || options.defaultValue;
|
|
659
|
+
if (!this.isValidLookup(res) && hasDefaultValue) {
|
|
660
|
+
usedDefault = true;
|
|
661
|
+
res = defaultValue;
|
|
662
|
+
}
|
|
663
|
+
if (!this.isValidLookup(res)) {
|
|
664
|
+
usedKey = true;
|
|
665
|
+
res = key;
|
|
666
|
+
}
|
|
667
|
+
const resForMissing = (options.missingKeyNoValueFallbackToKey || this.options.missingKeyNoValueFallbackToKey) && usedKey ? void 0 : res;
|
|
668
|
+
const updateMissing = hasDefaultValue && defaultValue !== res && this.options.updateMissing;
|
|
669
|
+
if (usedKey || usedDefault || updateMissing) {
|
|
670
|
+
this.logger.log(updateMissing ? "updateKey" : "missingKey", lng, namespace, key, updateMissing ? defaultValue : res);
|
|
671
|
+
if (keySeparator) {
|
|
672
|
+
const fk = this.resolve(key, {
|
|
673
|
+
...options,
|
|
674
|
+
keySeparator: false
|
|
675
|
+
});
|
|
676
|
+
if (fk && fk.res) this.logger.warn("Seems the loaded translations were in flat JSON format instead of nested. Either set keySeparator: false on init or make sure your translations are published in nested format.");
|
|
677
|
+
}
|
|
678
|
+
let lngs = [];
|
|
679
|
+
const fallbackLngs = this.languageUtils.getFallbackCodes(this.options.fallbackLng, options.lng || this.language);
|
|
680
|
+
if (this.options.saveMissingTo === "fallback" && fallbackLngs && fallbackLngs[0]) for (let i = 0; i < fallbackLngs.length; i++) lngs.push(fallbackLngs[i]);
|
|
681
|
+
else if (this.options.saveMissingTo === "all") lngs = this.languageUtils.toResolveHierarchy(options.lng || this.language);
|
|
682
|
+
else lngs.push(options.lng || this.language);
|
|
683
|
+
const send = (l, k, specificDefaultValue) => {
|
|
684
|
+
const defaultForMissing = hasDefaultValue && specificDefaultValue !== res ? specificDefaultValue : resForMissing;
|
|
685
|
+
if (this.options.missingKeyHandler) this.options.missingKeyHandler(l, namespace, k, defaultForMissing, updateMissing, options);
|
|
686
|
+
else if (this.backendConnector && this.backendConnector.saveMissing) this.backendConnector.saveMissing(l, namespace, k, defaultForMissing, updateMissing, options);
|
|
687
|
+
this.emit("missingKey", l, namespace, k, res);
|
|
688
|
+
};
|
|
689
|
+
if (this.options.saveMissing) {
|
|
690
|
+
if (this.options.saveMissingPlurals && needsPluralHandling) lngs.forEach((language) => {
|
|
691
|
+
const suffixes = this.pluralResolver.getSuffixes(language, options);
|
|
692
|
+
if (needsZeroSuffixLookup && options[`defaultValue${this.options.pluralSeparator}zero`] && suffixes.indexOf(`${this.options.pluralSeparator}zero`) < 0) suffixes.push(`${this.options.pluralSeparator}zero`);
|
|
693
|
+
suffixes.forEach((suffix) => {
|
|
694
|
+
send([language], key + suffix, options[`defaultValue${suffix}`] || defaultValue);
|
|
695
|
+
});
|
|
696
|
+
});
|
|
697
|
+
else send(lngs, key, defaultValue);
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
res = this.extendTranslation(res, keys, options, resolved, lastKey);
|
|
701
|
+
if (usedKey && res === key && this.options.appendNamespaceToMissingKey) res = `${namespace}:${key}`;
|
|
702
|
+
if ((usedKey || usedDefault) && this.options.parseMissingKeyHandler) {
|
|
703
|
+
if (this.options.compatibilityAPI !== "v1") res = this.options.parseMissingKeyHandler(this.options.appendNamespaceToMissingKey ? `${namespace}:${key}` : key, usedDefault ? res : void 0);
|
|
704
|
+
else res = this.options.parseMissingKeyHandler(res);
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
if (returnDetails) {
|
|
708
|
+
resolved.res = res;
|
|
709
|
+
resolved.usedParams = this.getUsedParamsDetails(options);
|
|
710
|
+
return resolved;
|
|
711
|
+
}
|
|
712
|
+
return res;
|
|
713
|
+
}
|
|
714
|
+
extendTranslation(res, key, options, resolved, lastKey) {
|
|
715
|
+
var _this = this;
|
|
716
|
+
if (this.i18nFormat && this.i18nFormat.parse) res = this.i18nFormat.parse(res, {
|
|
717
|
+
...this.options.interpolation.defaultVariables,
|
|
718
|
+
...options
|
|
719
|
+
}, options.lng || this.language || resolved.usedLng, resolved.usedNS, resolved.usedKey, { resolved });
|
|
720
|
+
else if (!options.skipInterpolation) {
|
|
721
|
+
if (options.interpolation) this.interpolator.init({
|
|
722
|
+
...options,
|
|
723
|
+
interpolation: {
|
|
724
|
+
...this.options.interpolation,
|
|
725
|
+
...options.interpolation
|
|
726
|
+
}
|
|
727
|
+
});
|
|
728
|
+
const skipOnVariables = isString(res) && (options && options.interpolation && options.interpolation.skipOnVariables !== void 0 ? options.interpolation.skipOnVariables : this.options.interpolation.skipOnVariables);
|
|
729
|
+
let nestBef;
|
|
730
|
+
if (skipOnVariables) {
|
|
731
|
+
const nb = res.match(this.interpolator.nestingRegexp);
|
|
732
|
+
nestBef = nb && nb.length;
|
|
733
|
+
}
|
|
734
|
+
let data = options.replace && !isString(options.replace) ? options.replace : options;
|
|
735
|
+
if (this.options.interpolation.defaultVariables) data = {
|
|
736
|
+
...this.options.interpolation.defaultVariables,
|
|
737
|
+
...data
|
|
738
|
+
};
|
|
739
|
+
res = this.interpolator.interpolate(res, data, options.lng || this.language || resolved.usedLng, options);
|
|
740
|
+
if (skipOnVariables) {
|
|
741
|
+
const na = res.match(this.interpolator.nestingRegexp);
|
|
742
|
+
const nestAft = na && na.length;
|
|
743
|
+
if (nestBef < nestAft) options.nest = false;
|
|
744
|
+
}
|
|
745
|
+
if (!options.lng && this.options.compatibilityAPI !== "v1" && resolved && resolved.res) options.lng = this.language || resolved.usedLng;
|
|
746
|
+
if (options.nest !== false) res = this.interpolator.nest(res, function() {
|
|
747
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) args[_key] = arguments[_key];
|
|
748
|
+
if (lastKey && lastKey[0] === args[0] && !options.context) {
|
|
749
|
+
_this.logger.warn(`It seems you are nesting recursively key: ${args[0]} in key: ${key[0]}`);
|
|
750
|
+
return null;
|
|
751
|
+
}
|
|
752
|
+
return _this.translate(...args, key);
|
|
753
|
+
}, options);
|
|
754
|
+
if (options.interpolation) this.interpolator.reset();
|
|
755
|
+
}
|
|
756
|
+
const postProcess = options.postProcess || this.options.postProcess;
|
|
757
|
+
const postProcessorNames = isString(postProcess) ? [postProcess] : postProcess;
|
|
758
|
+
if (res !== void 0 && res !== null && postProcessorNames && postProcessorNames.length && options.applyPostProcessor !== false) res = postProcessor.handle(postProcessorNames, res, key, this.options && this.options.postProcessPassResolved ? {
|
|
759
|
+
i18nResolved: {
|
|
760
|
+
...resolved,
|
|
761
|
+
usedParams: this.getUsedParamsDetails(options)
|
|
762
|
+
},
|
|
763
|
+
...options
|
|
764
|
+
} : options, this);
|
|
765
|
+
return res;
|
|
766
|
+
}
|
|
767
|
+
resolve(keys) {
|
|
768
|
+
let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
769
|
+
let found;
|
|
770
|
+
let usedKey;
|
|
771
|
+
let exactUsedKey;
|
|
772
|
+
let usedLng;
|
|
773
|
+
let usedNS;
|
|
774
|
+
if (isString(keys)) keys = [keys];
|
|
775
|
+
keys.forEach((k) => {
|
|
776
|
+
if (this.isValidLookup(found)) return;
|
|
777
|
+
const extracted = this.extractFromKey(k, options);
|
|
778
|
+
const key = extracted.key;
|
|
779
|
+
usedKey = key;
|
|
780
|
+
let namespaces = extracted.namespaces;
|
|
781
|
+
if (this.options.fallbackNS) namespaces = namespaces.concat(this.options.fallbackNS);
|
|
782
|
+
const needsPluralHandling = options.count !== void 0 && !isString(options.count);
|
|
783
|
+
const needsZeroSuffixLookup = needsPluralHandling && !options.ordinal && options.count === 0 && this.pluralResolver.shouldUseIntlApi();
|
|
784
|
+
const needsContextHandling = options.context !== void 0 && (isString(options.context) || typeof options.context === "number") && options.context !== "";
|
|
785
|
+
const codes = options.lngs ? options.lngs : this.languageUtils.toResolveHierarchy(options.lng || this.language, options.fallbackLng);
|
|
786
|
+
namespaces.forEach((ns) => {
|
|
787
|
+
if (this.isValidLookup(found)) return;
|
|
788
|
+
usedNS = ns;
|
|
789
|
+
if (!checkedLoadedFor[`${codes[0]}-${ns}`] && this.utils && this.utils.hasLoadedNamespace && !this.utils.hasLoadedNamespace(usedNS)) {
|
|
790
|
+
checkedLoadedFor[`${codes[0]}-${ns}`] = true;
|
|
791
|
+
this.logger.warn(`key "${usedKey}" for languages "${codes.join(", ")}" won't get resolved as namespace "${usedNS}" was not yet loaded`, "This means something IS WRONG in your setup. You access the t function before i18next.init / i18next.loadNamespace / i18next.changeLanguage was done. Wait for the callback or Promise to resolve before accessing it!!!");
|
|
792
|
+
}
|
|
793
|
+
codes.forEach((code) => {
|
|
794
|
+
if (this.isValidLookup(found)) return;
|
|
795
|
+
usedLng = code;
|
|
796
|
+
const finalKeys = [key];
|
|
797
|
+
if (this.i18nFormat && this.i18nFormat.addLookupKeys) this.i18nFormat.addLookupKeys(finalKeys, key, code, ns, options);
|
|
798
|
+
else {
|
|
799
|
+
let pluralSuffix;
|
|
800
|
+
if (needsPluralHandling) pluralSuffix = this.pluralResolver.getSuffix(code, options.count, options);
|
|
801
|
+
const zeroSuffix = `${this.options.pluralSeparator}zero`;
|
|
802
|
+
const ordinalPrefix = `${this.options.pluralSeparator}ordinal${this.options.pluralSeparator}`;
|
|
803
|
+
if (needsPluralHandling) {
|
|
804
|
+
finalKeys.push(key + pluralSuffix);
|
|
805
|
+
if (options.ordinal && pluralSuffix.indexOf(ordinalPrefix) === 0) finalKeys.push(key + pluralSuffix.replace(ordinalPrefix, this.options.pluralSeparator));
|
|
806
|
+
if (needsZeroSuffixLookup) finalKeys.push(key + zeroSuffix);
|
|
807
|
+
}
|
|
808
|
+
if (needsContextHandling) {
|
|
809
|
+
const contextKey = `${key}${this.options.contextSeparator}${options.context}`;
|
|
810
|
+
finalKeys.push(contextKey);
|
|
811
|
+
if (needsPluralHandling) {
|
|
812
|
+
finalKeys.push(contextKey + pluralSuffix);
|
|
813
|
+
if (options.ordinal && pluralSuffix.indexOf(ordinalPrefix) === 0) finalKeys.push(contextKey + pluralSuffix.replace(ordinalPrefix, this.options.pluralSeparator));
|
|
814
|
+
if (needsZeroSuffixLookup) finalKeys.push(contextKey + zeroSuffix);
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
}
|
|
818
|
+
let possibleKey;
|
|
819
|
+
while (possibleKey = finalKeys.pop()) if (!this.isValidLookup(found)) {
|
|
820
|
+
exactUsedKey = possibleKey;
|
|
821
|
+
found = this.getResource(code, ns, possibleKey, options);
|
|
822
|
+
}
|
|
823
|
+
});
|
|
824
|
+
});
|
|
825
|
+
});
|
|
826
|
+
return {
|
|
827
|
+
res: found,
|
|
828
|
+
usedKey,
|
|
829
|
+
exactUsedKey,
|
|
830
|
+
usedLng,
|
|
831
|
+
usedNS
|
|
832
|
+
};
|
|
833
|
+
}
|
|
834
|
+
isValidLookup(res) {
|
|
835
|
+
return res !== void 0 && !(!this.options.returnNull && res === null) && !(!this.options.returnEmptyString && res === "");
|
|
836
|
+
}
|
|
837
|
+
getResource(code, ns, key) {
|
|
838
|
+
let options = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : {};
|
|
839
|
+
if (this.i18nFormat && this.i18nFormat.getResource) return this.i18nFormat.getResource(code, ns, key, options);
|
|
840
|
+
return this.resourceStore.getResource(code, ns, key, options);
|
|
841
|
+
}
|
|
842
|
+
getUsedParamsDetails() {
|
|
843
|
+
let options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
844
|
+
const optionsKeys = [
|
|
845
|
+
"defaultValue",
|
|
846
|
+
"ordinal",
|
|
847
|
+
"context",
|
|
848
|
+
"replace",
|
|
849
|
+
"lng",
|
|
850
|
+
"lngs",
|
|
851
|
+
"fallbackLng",
|
|
852
|
+
"ns",
|
|
853
|
+
"keySeparator",
|
|
854
|
+
"nsSeparator",
|
|
855
|
+
"returnObjects",
|
|
856
|
+
"returnDetails",
|
|
857
|
+
"joinArrays",
|
|
858
|
+
"postProcess",
|
|
859
|
+
"interpolation"
|
|
860
|
+
];
|
|
861
|
+
const useOptionsReplaceForData = options.replace && !isString(options.replace);
|
|
862
|
+
let data = useOptionsReplaceForData ? options.replace : options;
|
|
863
|
+
if (useOptionsReplaceForData && typeof options.count !== "undefined") data.count = options.count;
|
|
864
|
+
if (this.options.interpolation.defaultVariables) data = {
|
|
865
|
+
...this.options.interpolation.defaultVariables,
|
|
866
|
+
...data
|
|
867
|
+
};
|
|
868
|
+
if (!useOptionsReplaceForData) {
|
|
869
|
+
data = { ...data };
|
|
870
|
+
for (const key of optionsKeys) delete data[key];
|
|
871
|
+
}
|
|
872
|
+
return data;
|
|
873
|
+
}
|
|
874
|
+
static hasDefaultValue(options) {
|
|
875
|
+
const prefix = "defaultValue";
|
|
876
|
+
for (const option in options) if (Object.prototype.hasOwnProperty.call(options, option) && prefix === option.substring(0, 12) && void 0 !== options[option]) return true;
|
|
877
|
+
return false;
|
|
878
|
+
}
|
|
879
|
+
};
|
|
880
|
+
var capitalize = (string) => string.charAt(0).toUpperCase() + string.slice(1);
|
|
881
|
+
var LanguageUtil = class {
|
|
882
|
+
constructor(options) {
|
|
883
|
+
this.options = options;
|
|
884
|
+
this.supportedLngs = this.options.supportedLngs || false;
|
|
885
|
+
this.logger = baseLogger.create("languageUtils");
|
|
886
|
+
}
|
|
887
|
+
getScriptPartFromCode(code) {
|
|
888
|
+
code = getCleanedCode(code);
|
|
889
|
+
if (!code || code.indexOf("-") < 0) return null;
|
|
890
|
+
const p = code.split("-");
|
|
891
|
+
if (p.length === 2) return null;
|
|
892
|
+
p.pop();
|
|
893
|
+
if (p[p.length - 1].toLowerCase() === "x") return null;
|
|
894
|
+
return this.formatLanguageCode(p.join("-"));
|
|
895
|
+
}
|
|
896
|
+
getLanguagePartFromCode(code) {
|
|
897
|
+
code = getCleanedCode(code);
|
|
898
|
+
if (!code || code.indexOf("-") < 0) return code;
|
|
899
|
+
const p = code.split("-");
|
|
900
|
+
return this.formatLanguageCode(p[0]);
|
|
901
|
+
}
|
|
902
|
+
formatLanguageCode(code) {
|
|
903
|
+
if (isString(code) && code.indexOf("-") > -1) {
|
|
904
|
+
if (typeof Intl !== "undefined" && typeof Intl.getCanonicalLocales !== "undefined") try {
|
|
905
|
+
let formattedCode = Intl.getCanonicalLocales(code)[0];
|
|
906
|
+
if (formattedCode && this.options.lowerCaseLng) formattedCode = formattedCode.toLowerCase();
|
|
907
|
+
if (formattedCode) return formattedCode;
|
|
908
|
+
} catch (e) {}
|
|
909
|
+
const specialCases = [
|
|
910
|
+
"hans",
|
|
911
|
+
"hant",
|
|
912
|
+
"latn",
|
|
913
|
+
"cyrl",
|
|
914
|
+
"cans",
|
|
915
|
+
"mong",
|
|
916
|
+
"arab"
|
|
917
|
+
];
|
|
918
|
+
let p = code.split("-");
|
|
919
|
+
if (this.options.lowerCaseLng) p = p.map((part) => part.toLowerCase());
|
|
920
|
+
else if (p.length === 2) {
|
|
921
|
+
p[0] = p[0].toLowerCase();
|
|
922
|
+
p[1] = p[1].toUpperCase();
|
|
923
|
+
if (specialCases.indexOf(p[1].toLowerCase()) > -1) p[1] = capitalize(p[1].toLowerCase());
|
|
924
|
+
} else if (p.length === 3) {
|
|
925
|
+
p[0] = p[0].toLowerCase();
|
|
926
|
+
if (p[1].length === 2) p[1] = p[1].toUpperCase();
|
|
927
|
+
if (p[0] !== "sgn" && p[2].length === 2) p[2] = p[2].toUpperCase();
|
|
928
|
+
if (specialCases.indexOf(p[1].toLowerCase()) > -1) p[1] = capitalize(p[1].toLowerCase());
|
|
929
|
+
if (specialCases.indexOf(p[2].toLowerCase()) > -1) p[2] = capitalize(p[2].toLowerCase());
|
|
930
|
+
}
|
|
931
|
+
return p.join("-");
|
|
932
|
+
}
|
|
933
|
+
return this.options.cleanCode || this.options.lowerCaseLng ? code.toLowerCase() : code;
|
|
934
|
+
}
|
|
935
|
+
isSupportedCode(code) {
|
|
936
|
+
if (this.options.load === "languageOnly" || this.options.nonExplicitSupportedLngs) code = this.getLanguagePartFromCode(code);
|
|
937
|
+
return !this.supportedLngs || !this.supportedLngs.length || this.supportedLngs.indexOf(code) > -1;
|
|
938
|
+
}
|
|
939
|
+
getBestMatchFromCodes(codes) {
|
|
940
|
+
if (!codes) return null;
|
|
941
|
+
let found;
|
|
942
|
+
codes.forEach((code) => {
|
|
943
|
+
if (found) return;
|
|
944
|
+
const cleanedLng = this.formatLanguageCode(code);
|
|
945
|
+
if (!this.options.supportedLngs || this.isSupportedCode(cleanedLng)) found = cleanedLng;
|
|
946
|
+
});
|
|
947
|
+
if (!found && this.options.supportedLngs) codes.forEach((code) => {
|
|
948
|
+
if (found) return;
|
|
949
|
+
const lngOnly = this.getLanguagePartFromCode(code);
|
|
950
|
+
if (this.isSupportedCode(lngOnly)) return found = lngOnly;
|
|
951
|
+
found = this.options.supportedLngs.find((supportedLng) => {
|
|
952
|
+
if (supportedLng === lngOnly) return supportedLng;
|
|
953
|
+
if (supportedLng.indexOf("-") < 0 && lngOnly.indexOf("-") < 0) return;
|
|
954
|
+
if (supportedLng.indexOf("-") > 0 && lngOnly.indexOf("-") < 0 && supportedLng.substring(0, supportedLng.indexOf("-")) === lngOnly) return supportedLng;
|
|
955
|
+
if (supportedLng.indexOf(lngOnly) === 0 && lngOnly.length > 1) return supportedLng;
|
|
956
|
+
});
|
|
957
|
+
});
|
|
958
|
+
if (!found) found = this.getFallbackCodes(this.options.fallbackLng)[0];
|
|
959
|
+
return found;
|
|
960
|
+
}
|
|
961
|
+
getFallbackCodes(fallbacks, code) {
|
|
962
|
+
if (!fallbacks) return [];
|
|
963
|
+
if (typeof fallbacks === "function") fallbacks = fallbacks(code);
|
|
964
|
+
if (isString(fallbacks)) fallbacks = [fallbacks];
|
|
965
|
+
if (Array.isArray(fallbacks)) return fallbacks;
|
|
966
|
+
if (!code) return fallbacks.default || [];
|
|
967
|
+
let found = fallbacks[code];
|
|
968
|
+
if (!found) found = fallbacks[this.getScriptPartFromCode(code)];
|
|
969
|
+
if (!found) found = fallbacks[this.formatLanguageCode(code)];
|
|
970
|
+
if (!found) found = fallbacks[this.getLanguagePartFromCode(code)];
|
|
971
|
+
if (!found) found = fallbacks.default;
|
|
972
|
+
return found || [];
|
|
973
|
+
}
|
|
974
|
+
toResolveHierarchy(code, fallbackCode) {
|
|
975
|
+
const fallbackCodes = this.getFallbackCodes(fallbackCode || this.options.fallbackLng || [], code);
|
|
976
|
+
const codes = [];
|
|
977
|
+
const addCode = (c) => {
|
|
978
|
+
if (!c) return;
|
|
979
|
+
if (this.isSupportedCode(c)) codes.push(c);
|
|
980
|
+
else this.logger.warn(`rejecting language code not found in supportedLngs: ${c}`);
|
|
981
|
+
};
|
|
982
|
+
if (isString(code) && (code.indexOf("-") > -1 || code.indexOf("_") > -1)) {
|
|
983
|
+
if (this.options.load !== "languageOnly") addCode(this.formatLanguageCode(code));
|
|
984
|
+
if (this.options.load !== "languageOnly" && this.options.load !== "currentOnly") addCode(this.getScriptPartFromCode(code));
|
|
985
|
+
if (this.options.load !== "currentOnly") addCode(this.getLanguagePartFromCode(code));
|
|
986
|
+
} else if (isString(code)) addCode(this.formatLanguageCode(code));
|
|
987
|
+
fallbackCodes.forEach((fc) => {
|
|
988
|
+
if (codes.indexOf(fc) < 0) addCode(this.formatLanguageCode(fc));
|
|
989
|
+
});
|
|
990
|
+
return codes;
|
|
991
|
+
}
|
|
992
|
+
};
|
|
993
|
+
var sets = [
|
|
994
|
+
{
|
|
995
|
+
lngs: [
|
|
996
|
+
"ach",
|
|
997
|
+
"ak",
|
|
998
|
+
"am",
|
|
999
|
+
"arn",
|
|
1000
|
+
"br",
|
|
1001
|
+
"fil",
|
|
1002
|
+
"gun",
|
|
1003
|
+
"ln",
|
|
1004
|
+
"mfe",
|
|
1005
|
+
"mg",
|
|
1006
|
+
"mi",
|
|
1007
|
+
"oc",
|
|
1008
|
+
"pt",
|
|
1009
|
+
"pt-BR",
|
|
1010
|
+
"tg",
|
|
1011
|
+
"tl",
|
|
1012
|
+
"ti",
|
|
1013
|
+
"tr",
|
|
1014
|
+
"uz",
|
|
1015
|
+
"wa"
|
|
1016
|
+
],
|
|
1017
|
+
nr: [1, 2],
|
|
1018
|
+
fc: 1
|
|
1019
|
+
},
|
|
1020
|
+
{
|
|
1021
|
+
lngs: [
|
|
1022
|
+
"af",
|
|
1023
|
+
"an",
|
|
1024
|
+
"ast",
|
|
1025
|
+
"az",
|
|
1026
|
+
"bg",
|
|
1027
|
+
"bn",
|
|
1028
|
+
"ca",
|
|
1029
|
+
"da",
|
|
1030
|
+
"de",
|
|
1031
|
+
"dev",
|
|
1032
|
+
"el",
|
|
1033
|
+
"en",
|
|
1034
|
+
"eo",
|
|
1035
|
+
"es",
|
|
1036
|
+
"et",
|
|
1037
|
+
"eu",
|
|
1038
|
+
"fi",
|
|
1039
|
+
"fo",
|
|
1040
|
+
"fur",
|
|
1041
|
+
"fy",
|
|
1042
|
+
"gl",
|
|
1043
|
+
"gu",
|
|
1044
|
+
"ha",
|
|
1045
|
+
"hi",
|
|
1046
|
+
"hu",
|
|
1047
|
+
"hy",
|
|
1048
|
+
"ia",
|
|
1049
|
+
"it",
|
|
1050
|
+
"kk",
|
|
1051
|
+
"kn",
|
|
1052
|
+
"ku",
|
|
1053
|
+
"lb",
|
|
1054
|
+
"mai",
|
|
1055
|
+
"ml",
|
|
1056
|
+
"mn",
|
|
1057
|
+
"mr",
|
|
1058
|
+
"nah",
|
|
1059
|
+
"nap",
|
|
1060
|
+
"nb",
|
|
1061
|
+
"ne",
|
|
1062
|
+
"nl",
|
|
1063
|
+
"nn",
|
|
1064
|
+
"no",
|
|
1065
|
+
"nso",
|
|
1066
|
+
"pa",
|
|
1067
|
+
"pap",
|
|
1068
|
+
"pms",
|
|
1069
|
+
"ps",
|
|
1070
|
+
"pt-PT",
|
|
1071
|
+
"rm",
|
|
1072
|
+
"sco",
|
|
1073
|
+
"se",
|
|
1074
|
+
"si",
|
|
1075
|
+
"so",
|
|
1076
|
+
"son",
|
|
1077
|
+
"sq",
|
|
1078
|
+
"sv",
|
|
1079
|
+
"sw",
|
|
1080
|
+
"ta",
|
|
1081
|
+
"te",
|
|
1082
|
+
"tk",
|
|
1083
|
+
"ur",
|
|
1084
|
+
"yo"
|
|
1085
|
+
],
|
|
1086
|
+
nr: [1, 2],
|
|
1087
|
+
fc: 2
|
|
1088
|
+
},
|
|
1089
|
+
{
|
|
1090
|
+
lngs: [
|
|
1091
|
+
"ay",
|
|
1092
|
+
"bo",
|
|
1093
|
+
"cgg",
|
|
1094
|
+
"fa",
|
|
1095
|
+
"ht",
|
|
1096
|
+
"id",
|
|
1097
|
+
"ja",
|
|
1098
|
+
"jbo",
|
|
1099
|
+
"ka",
|
|
1100
|
+
"km",
|
|
1101
|
+
"ko",
|
|
1102
|
+
"ky",
|
|
1103
|
+
"lo",
|
|
1104
|
+
"ms",
|
|
1105
|
+
"sah",
|
|
1106
|
+
"su",
|
|
1107
|
+
"th",
|
|
1108
|
+
"tt",
|
|
1109
|
+
"ug",
|
|
1110
|
+
"vi",
|
|
1111
|
+
"wo",
|
|
1112
|
+
"zh"
|
|
1113
|
+
],
|
|
1114
|
+
nr: [1],
|
|
1115
|
+
fc: 3
|
|
1116
|
+
},
|
|
1117
|
+
{
|
|
1118
|
+
lngs: [
|
|
1119
|
+
"be",
|
|
1120
|
+
"bs",
|
|
1121
|
+
"cnr",
|
|
1122
|
+
"dz",
|
|
1123
|
+
"hr",
|
|
1124
|
+
"ru",
|
|
1125
|
+
"sr",
|
|
1126
|
+
"uk"
|
|
1127
|
+
],
|
|
1128
|
+
nr: [
|
|
1129
|
+
1,
|
|
1130
|
+
2,
|
|
1131
|
+
5
|
|
1132
|
+
],
|
|
1133
|
+
fc: 4
|
|
1134
|
+
},
|
|
1135
|
+
{
|
|
1136
|
+
lngs: ["ar"],
|
|
1137
|
+
nr: [
|
|
1138
|
+
0,
|
|
1139
|
+
1,
|
|
1140
|
+
2,
|
|
1141
|
+
3,
|
|
1142
|
+
11,
|
|
1143
|
+
100
|
|
1144
|
+
],
|
|
1145
|
+
fc: 5
|
|
1146
|
+
},
|
|
1147
|
+
{
|
|
1148
|
+
lngs: ["cs", "sk"],
|
|
1149
|
+
nr: [
|
|
1150
|
+
1,
|
|
1151
|
+
2,
|
|
1152
|
+
5
|
|
1153
|
+
],
|
|
1154
|
+
fc: 6
|
|
1155
|
+
},
|
|
1156
|
+
{
|
|
1157
|
+
lngs: ["csb", "pl"],
|
|
1158
|
+
nr: [
|
|
1159
|
+
1,
|
|
1160
|
+
2,
|
|
1161
|
+
5
|
|
1162
|
+
],
|
|
1163
|
+
fc: 7
|
|
1164
|
+
},
|
|
1165
|
+
{
|
|
1166
|
+
lngs: ["cy"],
|
|
1167
|
+
nr: [
|
|
1168
|
+
1,
|
|
1169
|
+
2,
|
|
1170
|
+
3,
|
|
1171
|
+
8
|
|
1172
|
+
],
|
|
1173
|
+
fc: 8
|
|
1174
|
+
},
|
|
1175
|
+
{
|
|
1176
|
+
lngs: ["fr"],
|
|
1177
|
+
nr: [1, 2],
|
|
1178
|
+
fc: 9
|
|
1179
|
+
},
|
|
1180
|
+
{
|
|
1181
|
+
lngs: ["ga"],
|
|
1182
|
+
nr: [
|
|
1183
|
+
1,
|
|
1184
|
+
2,
|
|
1185
|
+
3,
|
|
1186
|
+
7,
|
|
1187
|
+
11
|
|
1188
|
+
],
|
|
1189
|
+
fc: 10
|
|
1190
|
+
},
|
|
1191
|
+
{
|
|
1192
|
+
lngs: ["gd"],
|
|
1193
|
+
nr: [
|
|
1194
|
+
1,
|
|
1195
|
+
2,
|
|
1196
|
+
3,
|
|
1197
|
+
20
|
|
1198
|
+
],
|
|
1199
|
+
fc: 11
|
|
1200
|
+
},
|
|
1201
|
+
{
|
|
1202
|
+
lngs: ["is"],
|
|
1203
|
+
nr: [1, 2],
|
|
1204
|
+
fc: 12
|
|
1205
|
+
},
|
|
1206
|
+
{
|
|
1207
|
+
lngs: ["jv"],
|
|
1208
|
+
nr: [0, 1],
|
|
1209
|
+
fc: 13
|
|
1210
|
+
},
|
|
1211
|
+
{
|
|
1212
|
+
lngs: ["kw"],
|
|
1213
|
+
nr: [
|
|
1214
|
+
1,
|
|
1215
|
+
2,
|
|
1216
|
+
3,
|
|
1217
|
+
4
|
|
1218
|
+
],
|
|
1219
|
+
fc: 14
|
|
1220
|
+
},
|
|
1221
|
+
{
|
|
1222
|
+
lngs: ["lt"],
|
|
1223
|
+
nr: [
|
|
1224
|
+
1,
|
|
1225
|
+
2,
|
|
1226
|
+
10
|
|
1227
|
+
],
|
|
1228
|
+
fc: 15
|
|
1229
|
+
},
|
|
1230
|
+
{
|
|
1231
|
+
lngs: ["lv"],
|
|
1232
|
+
nr: [
|
|
1233
|
+
1,
|
|
1234
|
+
2,
|
|
1235
|
+
0
|
|
1236
|
+
],
|
|
1237
|
+
fc: 16
|
|
1238
|
+
},
|
|
1239
|
+
{
|
|
1240
|
+
lngs: ["mk"],
|
|
1241
|
+
nr: [1, 2],
|
|
1242
|
+
fc: 17
|
|
1243
|
+
},
|
|
1244
|
+
{
|
|
1245
|
+
lngs: ["mnk"],
|
|
1246
|
+
nr: [
|
|
1247
|
+
0,
|
|
1248
|
+
1,
|
|
1249
|
+
2
|
|
1250
|
+
],
|
|
1251
|
+
fc: 18
|
|
1252
|
+
},
|
|
1253
|
+
{
|
|
1254
|
+
lngs: ["mt"],
|
|
1255
|
+
nr: [
|
|
1256
|
+
1,
|
|
1257
|
+
2,
|
|
1258
|
+
11,
|
|
1259
|
+
20
|
|
1260
|
+
],
|
|
1261
|
+
fc: 19
|
|
1262
|
+
},
|
|
1263
|
+
{
|
|
1264
|
+
lngs: ["or"],
|
|
1265
|
+
nr: [2, 1],
|
|
1266
|
+
fc: 2
|
|
1267
|
+
},
|
|
1268
|
+
{
|
|
1269
|
+
lngs: ["ro"],
|
|
1270
|
+
nr: [
|
|
1271
|
+
1,
|
|
1272
|
+
2,
|
|
1273
|
+
20
|
|
1274
|
+
],
|
|
1275
|
+
fc: 20
|
|
1276
|
+
},
|
|
1277
|
+
{
|
|
1278
|
+
lngs: ["sl"],
|
|
1279
|
+
nr: [
|
|
1280
|
+
5,
|
|
1281
|
+
1,
|
|
1282
|
+
2,
|
|
1283
|
+
3
|
|
1284
|
+
],
|
|
1285
|
+
fc: 21
|
|
1286
|
+
},
|
|
1287
|
+
{
|
|
1288
|
+
lngs: ["he", "iw"],
|
|
1289
|
+
nr: [
|
|
1290
|
+
1,
|
|
1291
|
+
2,
|
|
1292
|
+
20,
|
|
1293
|
+
21
|
|
1294
|
+
],
|
|
1295
|
+
fc: 22
|
|
1296
|
+
}
|
|
1297
|
+
];
|
|
1298
|
+
var _rulesPluralsTypes = {
|
|
1299
|
+
1: (n) => Number(n > 1),
|
|
1300
|
+
2: (n) => Number(n != 1),
|
|
1301
|
+
3: (n) => 0,
|
|
1302
|
+
4: (n) => Number(n % 10 == 1 && n % 100 != 11 ? 0 : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2),
|
|
1303
|
+
5: (n) => Number(n == 0 ? 0 : n == 1 ? 1 : n == 2 ? 2 : n % 100 >= 3 && n % 100 <= 10 ? 3 : n % 100 >= 11 ? 4 : 5),
|
|
1304
|
+
6: (n) => Number(n == 1 ? 0 : n >= 2 && n <= 4 ? 1 : 2),
|
|
1305
|
+
7: (n) => Number(n == 1 ? 0 : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2),
|
|
1306
|
+
8: (n) => Number(n == 1 ? 0 : n == 2 ? 1 : n != 8 && n != 11 ? 2 : 3),
|
|
1307
|
+
9: (n) => Number(n >= 2),
|
|
1308
|
+
10: (n) => Number(n == 1 ? 0 : n == 2 ? 1 : n < 7 ? 2 : n < 11 ? 3 : 4),
|
|
1309
|
+
11: (n) => Number(n == 1 || n == 11 ? 0 : n == 2 || n == 12 ? 1 : n > 2 && n < 20 ? 2 : 3),
|
|
1310
|
+
12: (n) => Number(n % 10 != 1 || n % 100 == 11),
|
|
1311
|
+
13: (n) => Number(n !== 0),
|
|
1312
|
+
14: (n) => Number(n == 1 ? 0 : n == 2 ? 1 : n == 3 ? 2 : 3),
|
|
1313
|
+
15: (n) => Number(n % 10 == 1 && n % 100 != 11 ? 0 : n % 10 >= 2 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2),
|
|
1314
|
+
16: (n) => Number(n % 10 == 1 && n % 100 != 11 ? 0 : n !== 0 ? 1 : 2),
|
|
1315
|
+
17: (n) => Number(n == 1 || n % 10 == 1 && n % 100 != 11 ? 0 : 1),
|
|
1316
|
+
18: (n) => Number(n == 0 ? 0 : n == 1 ? 1 : 2),
|
|
1317
|
+
19: (n) => Number(n == 1 ? 0 : n == 0 || n % 100 > 1 && n % 100 < 11 ? 1 : n % 100 > 10 && n % 100 < 20 ? 2 : 3),
|
|
1318
|
+
20: (n) => Number(n == 1 ? 0 : n == 0 || n % 100 > 0 && n % 100 < 20 ? 1 : 2),
|
|
1319
|
+
21: (n) => Number(n % 100 == 1 ? 1 : n % 100 == 2 ? 2 : n % 100 == 3 || n % 100 == 4 ? 3 : 0),
|
|
1320
|
+
22: (n) => Number(n == 1 ? 0 : n == 2 ? 1 : (n < 0 || n > 10) && n % 10 == 0 ? 2 : 3)
|
|
1321
|
+
};
|
|
1322
|
+
var nonIntlVersions = [
|
|
1323
|
+
"v1",
|
|
1324
|
+
"v2",
|
|
1325
|
+
"v3"
|
|
1326
|
+
];
|
|
1327
|
+
var intlVersions = ["v4"];
|
|
1328
|
+
var suffixesOrder = {
|
|
1329
|
+
zero: 0,
|
|
1330
|
+
one: 1,
|
|
1331
|
+
two: 2,
|
|
1332
|
+
few: 3,
|
|
1333
|
+
many: 4,
|
|
1334
|
+
other: 5
|
|
1335
|
+
};
|
|
1336
|
+
var createRules = () => {
|
|
1337
|
+
const rules = {};
|
|
1338
|
+
sets.forEach((set) => {
|
|
1339
|
+
set.lngs.forEach((l) => {
|
|
1340
|
+
rules[l] = {
|
|
1341
|
+
numbers: set.nr,
|
|
1342
|
+
plurals: _rulesPluralsTypes[set.fc]
|
|
1343
|
+
};
|
|
1344
|
+
});
|
|
1345
|
+
});
|
|
1346
|
+
return rules;
|
|
1347
|
+
};
|
|
1348
|
+
var PluralResolver = class {
|
|
1349
|
+
constructor(languageUtils) {
|
|
1350
|
+
let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
1351
|
+
this.languageUtils = languageUtils;
|
|
1352
|
+
this.options = options;
|
|
1353
|
+
this.logger = baseLogger.create("pluralResolver");
|
|
1354
|
+
if ((!this.options.compatibilityJSON || intlVersions.includes(this.options.compatibilityJSON)) && (typeof Intl === "undefined" || !Intl.PluralRules)) {
|
|
1355
|
+
this.options.compatibilityJSON = "v3";
|
|
1356
|
+
this.logger.error("Your environment seems not to be Intl API compatible, use an Intl.PluralRules polyfill. Will fallback to the compatibilityJSON v3 format handling.");
|
|
1357
|
+
}
|
|
1358
|
+
this.rules = createRules();
|
|
1359
|
+
this.pluralRulesCache = {};
|
|
1360
|
+
}
|
|
1361
|
+
addRule(lng, obj) {
|
|
1362
|
+
this.rules[lng] = obj;
|
|
1363
|
+
}
|
|
1364
|
+
clearCache() {
|
|
1365
|
+
this.pluralRulesCache = {};
|
|
1366
|
+
}
|
|
1367
|
+
getRule(code) {
|
|
1368
|
+
let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
1369
|
+
if (this.shouldUseIntlApi()) {
|
|
1370
|
+
const cleanedCode = getCleanedCode(code === "dev" ? "en" : code);
|
|
1371
|
+
const type = options.ordinal ? "ordinal" : "cardinal";
|
|
1372
|
+
const cacheKey = JSON.stringify({
|
|
1373
|
+
cleanedCode,
|
|
1374
|
+
type
|
|
1375
|
+
});
|
|
1376
|
+
if (cacheKey in this.pluralRulesCache) return this.pluralRulesCache[cacheKey];
|
|
1377
|
+
let rule;
|
|
1378
|
+
try {
|
|
1379
|
+
rule = new Intl.PluralRules(cleanedCode, { type });
|
|
1380
|
+
} catch (err) {
|
|
1381
|
+
if (!code.match(/-|_/)) return;
|
|
1382
|
+
const lngPart = this.languageUtils.getLanguagePartFromCode(code);
|
|
1383
|
+
rule = this.getRule(lngPart, options);
|
|
1384
|
+
}
|
|
1385
|
+
this.pluralRulesCache[cacheKey] = rule;
|
|
1386
|
+
return rule;
|
|
1387
|
+
}
|
|
1388
|
+
return this.rules[code] || this.rules[this.languageUtils.getLanguagePartFromCode(code)];
|
|
1389
|
+
}
|
|
1390
|
+
needsPlural(code) {
|
|
1391
|
+
let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
1392
|
+
const rule = this.getRule(code, options);
|
|
1393
|
+
if (this.shouldUseIntlApi()) return rule && rule.resolvedOptions().pluralCategories.length > 1;
|
|
1394
|
+
return rule && rule.numbers.length > 1;
|
|
1395
|
+
}
|
|
1396
|
+
getPluralFormsOfKey(code, key) {
|
|
1397
|
+
let options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
|
|
1398
|
+
return this.getSuffixes(code, options).map((suffix) => `${key}${suffix}`);
|
|
1399
|
+
}
|
|
1400
|
+
getSuffixes(code) {
|
|
1401
|
+
let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
1402
|
+
const rule = this.getRule(code, options);
|
|
1403
|
+
if (!rule) return [];
|
|
1404
|
+
if (this.shouldUseIntlApi()) return rule.resolvedOptions().pluralCategories.sort((pluralCategory1, pluralCategory2) => suffixesOrder[pluralCategory1] - suffixesOrder[pluralCategory2]).map((pluralCategory) => `${this.options.prepend}${options.ordinal ? `ordinal${this.options.prepend}` : ""}${pluralCategory}`);
|
|
1405
|
+
return rule.numbers.map((number) => this.getSuffix(code, number, options));
|
|
1406
|
+
}
|
|
1407
|
+
getSuffix(code, count) {
|
|
1408
|
+
let options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
|
|
1409
|
+
const rule = this.getRule(code, options);
|
|
1410
|
+
if (rule) {
|
|
1411
|
+
if (this.shouldUseIntlApi()) return `${this.options.prepend}${options.ordinal ? `ordinal${this.options.prepend}` : ""}${rule.select(count)}`;
|
|
1412
|
+
return this.getSuffixRetroCompatible(rule, count);
|
|
1413
|
+
}
|
|
1414
|
+
this.logger.warn(`no plural rule found for: ${code}`);
|
|
1415
|
+
return "";
|
|
1416
|
+
}
|
|
1417
|
+
getSuffixRetroCompatible(rule, count) {
|
|
1418
|
+
const idx = rule.noAbs ? rule.plurals(count) : rule.plurals(Math.abs(count));
|
|
1419
|
+
let suffix = rule.numbers[idx];
|
|
1420
|
+
if (this.options.simplifyPluralSuffix && rule.numbers.length === 2 && rule.numbers[0] === 1) {
|
|
1421
|
+
if (suffix === 2) suffix = "plural";
|
|
1422
|
+
else if (suffix === 1) suffix = "";
|
|
1423
|
+
}
|
|
1424
|
+
const returnSuffix = () => this.options.prepend && suffix.toString() ? this.options.prepend + suffix.toString() : suffix.toString();
|
|
1425
|
+
if (this.options.compatibilityJSON === "v1") {
|
|
1426
|
+
if (suffix === 1) return "";
|
|
1427
|
+
if (typeof suffix === "number") return `_plural_${suffix.toString()}`;
|
|
1428
|
+
return returnSuffix();
|
|
1429
|
+
} else if (this.options.compatibilityJSON === "v2") return returnSuffix();
|
|
1430
|
+
else if (this.options.simplifyPluralSuffix && rule.numbers.length === 2 && rule.numbers[0] === 1) return returnSuffix();
|
|
1431
|
+
return this.options.prepend && idx.toString() ? this.options.prepend + idx.toString() : idx.toString();
|
|
1432
|
+
}
|
|
1433
|
+
shouldUseIntlApi() {
|
|
1434
|
+
return !nonIntlVersions.includes(this.options.compatibilityJSON);
|
|
1435
|
+
}
|
|
1436
|
+
};
|
|
1437
|
+
var deepFindWithDefaults = function(data, defaultData, key) {
|
|
1438
|
+
let keySeparator = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : ".";
|
|
1439
|
+
let ignoreJSONStructure = arguments.length > 4 && arguments[4] !== void 0 ? arguments[4] : true;
|
|
1440
|
+
let path = getPathWithDefaults(data, defaultData, key);
|
|
1441
|
+
if (!path && ignoreJSONStructure && isString(key)) {
|
|
1442
|
+
path = deepFind(data, key, keySeparator);
|
|
1443
|
+
if (path === void 0) path = deepFind(defaultData, key, keySeparator);
|
|
1444
|
+
}
|
|
1445
|
+
return path;
|
|
1446
|
+
};
|
|
1447
|
+
var regexSafe = (val) => val.replace(/\$/g, "$$$$");
|
|
1448
|
+
var Interpolator = class {
|
|
1449
|
+
constructor() {
|
|
1450
|
+
let options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
1451
|
+
this.logger = baseLogger.create("interpolator");
|
|
1452
|
+
this.options = options;
|
|
1453
|
+
this.format = options.interpolation && options.interpolation.format || ((value) => value);
|
|
1454
|
+
this.init(options);
|
|
1455
|
+
}
|
|
1456
|
+
init() {
|
|
1457
|
+
let options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
1458
|
+
if (!options.interpolation) options.interpolation = { escapeValue: true };
|
|
1459
|
+
const { escape: escape$1, escapeValue, useRawValueToEscape, prefix, prefixEscaped, suffix, suffixEscaped, formatSeparator, unescapeSuffix, unescapePrefix, nestingPrefix, nestingPrefixEscaped, nestingSuffix, nestingSuffixEscaped, nestingOptionsSeparator, maxReplaces, alwaysFormat } = options.interpolation;
|
|
1460
|
+
this.escape = escape$1 !== void 0 ? escape$1 : escape;
|
|
1461
|
+
this.escapeValue = escapeValue !== void 0 ? escapeValue : true;
|
|
1462
|
+
this.useRawValueToEscape = useRawValueToEscape !== void 0 ? useRawValueToEscape : false;
|
|
1463
|
+
this.prefix = prefix ? regexEscape(prefix) : prefixEscaped || "{{";
|
|
1464
|
+
this.suffix = suffix ? regexEscape(suffix) : suffixEscaped || "}}";
|
|
1465
|
+
this.formatSeparator = formatSeparator || ",";
|
|
1466
|
+
this.unescapePrefix = unescapeSuffix ? "" : unescapePrefix || "-";
|
|
1467
|
+
this.unescapeSuffix = this.unescapePrefix ? "" : unescapeSuffix || "";
|
|
1468
|
+
this.nestingPrefix = nestingPrefix ? regexEscape(nestingPrefix) : nestingPrefixEscaped || regexEscape("$t(");
|
|
1469
|
+
this.nestingSuffix = nestingSuffix ? regexEscape(nestingSuffix) : nestingSuffixEscaped || regexEscape(")");
|
|
1470
|
+
this.nestingOptionsSeparator = nestingOptionsSeparator || ",";
|
|
1471
|
+
this.maxReplaces = maxReplaces || 1e3;
|
|
1472
|
+
this.alwaysFormat = alwaysFormat !== void 0 ? alwaysFormat : false;
|
|
1473
|
+
this.resetRegExp();
|
|
1474
|
+
}
|
|
1475
|
+
reset() {
|
|
1476
|
+
if (this.options) this.init(this.options);
|
|
1477
|
+
}
|
|
1478
|
+
resetRegExp() {
|
|
1479
|
+
const getOrResetRegExp = (existingRegExp, pattern) => {
|
|
1480
|
+
if (existingRegExp && existingRegExp.source === pattern) {
|
|
1481
|
+
existingRegExp.lastIndex = 0;
|
|
1482
|
+
return existingRegExp;
|
|
1483
|
+
}
|
|
1484
|
+
return new RegExp(pattern, "g");
|
|
1485
|
+
};
|
|
1486
|
+
this.regexp = getOrResetRegExp(this.regexp, `${this.prefix}(.+?)${this.suffix}`);
|
|
1487
|
+
this.regexpUnescape = getOrResetRegExp(this.regexpUnescape, `${this.prefix}${this.unescapePrefix}(.+?)${this.unescapeSuffix}${this.suffix}`);
|
|
1488
|
+
this.nestingRegexp = getOrResetRegExp(this.nestingRegexp, `${this.nestingPrefix}(.+?)${this.nestingSuffix}`);
|
|
1489
|
+
}
|
|
1490
|
+
interpolate(str, data, lng, options) {
|
|
1491
|
+
let match;
|
|
1492
|
+
let value;
|
|
1493
|
+
let replaces;
|
|
1494
|
+
const defaultData = this.options && this.options.interpolation && this.options.interpolation.defaultVariables || {};
|
|
1495
|
+
const handleFormat = (key) => {
|
|
1496
|
+
if (key.indexOf(this.formatSeparator) < 0) {
|
|
1497
|
+
const path = deepFindWithDefaults(data, defaultData, key, this.options.keySeparator, this.options.ignoreJSONStructure);
|
|
1498
|
+
return this.alwaysFormat ? this.format(path, void 0, lng, {
|
|
1499
|
+
...options,
|
|
1500
|
+
...data,
|
|
1501
|
+
interpolationkey: key
|
|
1502
|
+
}) : path;
|
|
1503
|
+
}
|
|
1504
|
+
const p = key.split(this.formatSeparator);
|
|
1505
|
+
const k = p.shift().trim();
|
|
1506
|
+
const f = p.join(this.formatSeparator).trim();
|
|
1507
|
+
return this.format(deepFindWithDefaults(data, defaultData, k, this.options.keySeparator, this.options.ignoreJSONStructure), f, lng, {
|
|
1508
|
+
...options,
|
|
1509
|
+
...data,
|
|
1510
|
+
interpolationkey: k
|
|
1511
|
+
});
|
|
1512
|
+
};
|
|
1513
|
+
this.resetRegExp();
|
|
1514
|
+
const missingInterpolationHandler = options && options.missingInterpolationHandler || this.options.missingInterpolationHandler;
|
|
1515
|
+
const skipOnVariables = options && options.interpolation && options.interpolation.skipOnVariables !== void 0 ? options.interpolation.skipOnVariables : this.options.interpolation.skipOnVariables;
|
|
1516
|
+
[{
|
|
1517
|
+
regex: this.regexpUnescape,
|
|
1518
|
+
safeValue: (val) => regexSafe(val)
|
|
1519
|
+
}, {
|
|
1520
|
+
regex: this.regexp,
|
|
1521
|
+
safeValue: (val) => this.escapeValue ? regexSafe(this.escape(val)) : regexSafe(val)
|
|
1522
|
+
}].forEach((todo) => {
|
|
1523
|
+
replaces = 0;
|
|
1524
|
+
while (match = todo.regex.exec(str)) {
|
|
1525
|
+
const matchedVar = match[1].trim();
|
|
1526
|
+
value = handleFormat(matchedVar);
|
|
1527
|
+
if (value === void 0) {
|
|
1528
|
+
if (typeof missingInterpolationHandler === "function") {
|
|
1529
|
+
const temp = missingInterpolationHandler(str, match, options);
|
|
1530
|
+
value = isString(temp) ? temp : "";
|
|
1531
|
+
} else if (options && Object.prototype.hasOwnProperty.call(options, matchedVar)) value = "";
|
|
1532
|
+
else if (skipOnVariables) {
|
|
1533
|
+
value = match[0];
|
|
1534
|
+
continue;
|
|
1535
|
+
} else {
|
|
1536
|
+
this.logger.warn(`missed to pass in variable ${matchedVar} for interpolating ${str}`);
|
|
1537
|
+
value = "";
|
|
1538
|
+
}
|
|
1539
|
+
} else if (!isString(value) && !this.useRawValueToEscape) value = makeString(value);
|
|
1540
|
+
const safeValue = todo.safeValue(value);
|
|
1541
|
+
str = str.replace(match[0], safeValue);
|
|
1542
|
+
if (skipOnVariables) {
|
|
1543
|
+
todo.regex.lastIndex += value.length;
|
|
1544
|
+
todo.regex.lastIndex -= match[0].length;
|
|
1545
|
+
} else todo.regex.lastIndex = 0;
|
|
1546
|
+
replaces++;
|
|
1547
|
+
if (replaces >= this.maxReplaces) break;
|
|
1548
|
+
}
|
|
1549
|
+
});
|
|
1550
|
+
return str;
|
|
1551
|
+
}
|
|
1552
|
+
nest(str, fc) {
|
|
1553
|
+
let options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
|
|
1554
|
+
let match;
|
|
1555
|
+
let value;
|
|
1556
|
+
let clonedOptions;
|
|
1557
|
+
const handleHasOptions = (key, inheritedOptions) => {
|
|
1558
|
+
const sep = this.nestingOptionsSeparator;
|
|
1559
|
+
if (key.indexOf(sep) < 0) return key;
|
|
1560
|
+
const c = key.split(new RegExp(`${sep}[ ]*{`));
|
|
1561
|
+
let optionsString = `{${c[1]}`;
|
|
1562
|
+
key = c[0];
|
|
1563
|
+
optionsString = this.interpolate(optionsString, clonedOptions);
|
|
1564
|
+
const matchedSingleQuotes = optionsString.match(/'/g);
|
|
1565
|
+
const matchedDoubleQuotes = optionsString.match(/"/g);
|
|
1566
|
+
if (matchedSingleQuotes && matchedSingleQuotes.length % 2 === 0 && !matchedDoubleQuotes || matchedDoubleQuotes.length % 2 !== 0) optionsString = optionsString.replace(/'/g, "\"");
|
|
1567
|
+
try {
|
|
1568
|
+
clonedOptions = JSON.parse(optionsString);
|
|
1569
|
+
if (inheritedOptions) clonedOptions = {
|
|
1570
|
+
...inheritedOptions,
|
|
1571
|
+
...clonedOptions
|
|
1572
|
+
};
|
|
1573
|
+
} catch (e) {
|
|
1574
|
+
this.logger.warn(`failed parsing options string in nesting for key ${key}`, e);
|
|
1575
|
+
return `${key}${sep}${optionsString}`;
|
|
1576
|
+
}
|
|
1577
|
+
if (clonedOptions.defaultValue && clonedOptions.defaultValue.indexOf(this.prefix) > -1) delete clonedOptions.defaultValue;
|
|
1578
|
+
return key;
|
|
1579
|
+
};
|
|
1580
|
+
while (match = this.nestingRegexp.exec(str)) {
|
|
1581
|
+
let formatters = [];
|
|
1582
|
+
clonedOptions = { ...options };
|
|
1583
|
+
clonedOptions = clonedOptions.replace && !isString(clonedOptions.replace) ? clonedOptions.replace : clonedOptions;
|
|
1584
|
+
clonedOptions.applyPostProcessor = false;
|
|
1585
|
+
delete clonedOptions.defaultValue;
|
|
1586
|
+
let doReduce = false;
|
|
1587
|
+
if (match[0].indexOf(this.formatSeparator) !== -1 && !/{.*}/.test(match[1])) {
|
|
1588
|
+
const r = match[1].split(this.formatSeparator).map((elem) => elem.trim());
|
|
1589
|
+
match[1] = r.shift();
|
|
1590
|
+
formatters = r;
|
|
1591
|
+
doReduce = true;
|
|
1592
|
+
}
|
|
1593
|
+
value = fc(handleHasOptions.call(this, match[1].trim(), clonedOptions), clonedOptions);
|
|
1594
|
+
if (value && match[0] === str && !isString(value)) return value;
|
|
1595
|
+
if (!isString(value)) value = makeString(value);
|
|
1596
|
+
if (!value) {
|
|
1597
|
+
this.logger.warn(`missed to resolve ${match[1]} for nesting ${str}`);
|
|
1598
|
+
value = "";
|
|
1599
|
+
}
|
|
1600
|
+
if (doReduce) value = formatters.reduce((v, f) => this.format(v, f, options.lng, {
|
|
1601
|
+
...options,
|
|
1602
|
+
interpolationkey: match[1].trim()
|
|
1603
|
+
}), value.trim());
|
|
1604
|
+
str = str.replace(match[0], value);
|
|
1605
|
+
this.regexp.lastIndex = 0;
|
|
1606
|
+
}
|
|
1607
|
+
return str;
|
|
1608
|
+
}
|
|
1609
|
+
};
|
|
1610
|
+
var parseFormatStr = (formatStr) => {
|
|
1611
|
+
let formatName = formatStr.toLowerCase().trim();
|
|
1612
|
+
const formatOptions = {};
|
|
1613
|
+
if (formatStr.indexOf("(") > -1) {
|
|
1614
|
+
const p = formatStr.split("(");
|
|
1615
|
+
formatName = p[0].toLowerCase().trim();
|
|
1616
|
+
const optStr = p[1].substring(0, p[1].length - 1);
|
|
1617
|
+
if (formatName === "currency" && optStr.indexOf(":") < 0) {
|
|
1618
|
+
if (!formatOptions.currency) formatOptions.currency = optStr.trim();
|
|
1619
|
+
} else if (formatName === "relativetime" && optStr.indexOf(":") < 0) {
|
|
1620
|
+
if (!formatOptions.range) formatOptions.range = optStr.trim();
|
|
1621
|
+
} else optStr.split(";").forEach((opt) => {
|
|
1622
|
+
if (opt) {
|
|
1623
|
+
const [key, ...rest] = opt.split(":");
|
|
1624
|
+
const val = rest.join(":").trim().replace(/^'+|'+$/g, "");
|
|
1625
|
+
const trimmedKey = key.trim();
|
|
1626
|
+
if (!formatOptions[trimmedKey]) formatOptions[trimmedKey] = val;
|
|
1627
|
+
if (val === "false") formatOptions[trimmedKey] = false;
|
|
1628
|
+
if (val === "true") formatOptions[trimmedKey] = true;
|
|
1629
|
+
if (!isNaN(val)) formatOptions[trimmedKey] = parseInt(val, 10);
|
|
1630
|
+
}
|
|
1631
|
+
});
|
|
1632
|
+
}
|
|
1633
|
+
return {
|
|
1634
|
+
formatName,
|
|
1635
|
+
formatOptions
|
|
1636
|
+
};
|
|
1637
|
+
};
|
|
1638
|
+
var createCachedFormatter = (fn) => {
|
|
1639
|
+
const cache = {};
|
|
1640
|
+
return (val, lng, options) => {
|
|
1641
|
+
let optForCache = options;
|
|
1642
|
+
if (options && options.interpolationkey && options.formatParams && options.formatParams[options.interpolationkey] && options[options.interpolationkey]) optForCache = {
|
|
1643
|
+
...optForCache,
|
|
1644
|
+
[options.interpolationkey]: void 0
|
|
1645
|
+
};
|
|
1646
|
+
const key = lng + JSON.stringify(optForCache);
|
|
1647
|
+
let formatter = cache[key];
|
|
1648
|
+
if (!formatter) {
|
|
1649
|
+
formatter = fn(getCleanedCode(lng), options);
|
|
1650
|
+
cache[key] = formatter;
|
|
1651
|
+
}
|
|
1652
|
+
return formatter(val);
|
|
1653
|
+
};
|
|
1654
|
+
};
|
|
1655
|
+
var Formatter = class {
|
|
1656
|
+
constructor() {
|
|
1657
|
+
let options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
1658
|
+
this.logger = baseLogger.create("formatter");
|
|
1659
|
+
this.options = options;
|
|
1660
|
+
this.formats = {
|
|
1661
|
+
number: createCachedFormatter((lng, opt) => {
|
|
1662
|
+
const formatter = new Intl.NumberFormat(lng, { ...opt });
|
|
1663
|
+
return (val) => formatter.format(val);
|
|
1664
|
+
}),
|
|
1665
|
+
currency: createCachedFormatter((lng, opt) => {
|
|
1666
|
+
const formatter = new Intl.NumberFormat(lng, {
|
|
1667
|
+
...opt,
|
|
1668
|
+
style: "currency"
|
|
1669
|
+
});
|
|
1670
|
+
return (val) => formatter.format(val);
|
|
1671
|
+
}),
|
|
1672
|
+
datetime: createCachedFormatter((lng, opt) => {
|
|
1673
|
+
const formatter = new Intl.DateTimeFormat(lng, { ...opt });
|
|
1674
|
+
return (val) => formatter.format(val);
|
|
1675
|
+
}),
|
|
1676
|
+
relativetime: createCachedFormatter((lng, opt) => {
|
|
1677
|
+
const formatter = new Intl.RelativeTimeFormat(lng, { ...opt });
|
|
1678
|
+
return (val) => formatter.format(val, opt.range || "day");
|
|
1679
|
+
}),
|
|
1680
|
+
list: createCachedFormatter((lng, opt) => {
|
|
1681
|
+
const formatter = new Intl.ListFormat(lng, { ...opt });
|
|
1682
|
+
return (val) => formatter.format(val);
|
|
1683
|
+
})
|
|
1684
|
+
};
|
|
1685
|
+
this.init(options);
|
|
1686
|
+
}
|
|
1687
|
+
init(services) {
|
|
1688
|
+
let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : { interpolation: {} };
|
|
1689
|
+
this.formatSeparator = options.interpolation.formatSeparator || ",";
|
|
1690
|
+
}
|
|
1691
|
+
add(name, fc) {
|
|
1692
|
+
this.formats[name.toLowerCase().trim()] = fc;
|
|
1693
|
+
}
|
|
1694
|
+
addCached(name, fc) {
|
|
1695
|
+
this.formats[name.toLowerCase().trim()] = createCachedFormatter(fc);
|
|
1696
|
+
}
|
|
1697
|
+
format(value, format, lng) {
|
|
1698
|
+
let options = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : {};
|
|
1699
|
+
const formats = format.split(this.formatSeparator);
|
|
1700
|
+
if (formats.length > 1 && formats[0].indexOf("(") > 1 && formats[0].indexOf(")") < 0 && formats.find((f) => f.indexOf(")") > -1)) {
|
|
1701
|
+
const lastIndex = formats.findIndex((f) => f.indexOf(")") > -1);
|
|
1702
|
+
formats[0] = [formats[0], ...formats.splice(1, lastIndex)].join(this.formatSeparator);
|
|
1703
|
+
}
|
|
1704
|
+
return formats.reduce((mem, f) => {
|
|
1705
|
+
const { formatName, formatOptions } = parseFormatStr(f);
|
|
1706
|
+
if (this.formats[formatName]) {
|
|
1707
|
+
let formatted = mem;
|
|
1708
|
+
try {
|
|
1709
|
+
const valOptions = options && options.formatParams && options.formatParams[options.interpolationkey] || {};
|
|
1710
|
+
const l = valOptions.locale || valOptions.lng || options.locale || options.lng || lng;
|
|
1711
|
+
formatted = this.formats[formatName](mem, l, {
|
|
1712
|
+
...formatOptions,
|
|
1713
|
+
...options,
|
|
1714
|
+
...valOptions
|
|
1715
|
+
});
|
|
1716
|
+
} catch (error) {
|
|
1717
|
+
this.logger.warn(error);
|
|
1718
|
+
}
|
|
1719
|
+
return formatted;
|
|
1720
|
+
} else this.logger.warn(`there was no format function for ${formatName}`);
|
|
1721
|
+
return mem;
|
|
1722
|
+
}, value);
|
|
1723
|
+
}
|
|
1724
|
+
};
|
|
1725
|
+
var removePending = (q, name) => {
|
|
1726
|
+
if (q.pending[name] !== void 0) {
|
|
1727
|
+
delete q.pending[name];
|
|
1728
|
+
q.pendingCount--;
|
|
1729
|
+
}
|
|
1730
|
+
};
|
|
1731
|
+
var Connector = class extends EventEmitter {
|
|
1732
|
+
constructor(backend, store, services) {
|
|
1733
|
+
let options = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : {};
|
|
1734
|
+
super();
|
|
1735
|
+
this.backend = backend;
|
|
1736
|
+
this.store = store;
|
|
1737
|
+
this.services = services;
|
|
1738
|
+
this.languageUtils = services.languageUtils;
|
|
1739
|
+
this.options = options;
|
|
1740
|
+
this.logger = baseLogger.create("backendConnector");
|
|
1741
|
+
this.waitingReads = [];
|
|
1742
|
+
this.maxParallelReads = options.maxParallelReads || 10;
|
|
1743
|
+
this.readingCalls = 0;
|
|
1744
|
+
this.maxRetries = options.maxRetries >= 0 ? options.maxRetries : 5;
|
|
1745
|
+
this.retryTimeout = options.retryTimeout >= 1 ? options.retryTimeout : 350;
|
|
1746
|
+
this.state = {};
|
|
1747
|
+
this.queue = [];
|
|
1748
|
+
if (this.backend && this.backend.init) this.backend.init(services, options.backend, options);
|
|
1749
|
+
}
|
|
1750
|
+
queueLoad(languages, namespaces, options, callback) {
|
|
1751
|
+
const toLoad = {};
|
|
1752
|
+
const pending = {};
|
|
1753
|
+
const toLoadLanguages = {};
|
|
1754
|
+
const toLoadNamespaces = {};
|
|
1755
|
+
languages.forEach((lng) => {
|
|
1756
|
+
let hasAllNamespaces = true;
|
|
1757
|
+
namespaces.forEach((ns) => {
|
|
1758
|
+
const name = `${lng}|${ns}`;
|
|
1759
|
+
if (!options.reload && this.store.hasResourceBundle(lng, ns)) this.state[name] = 2;
|
|
1760
|
+
else if (this.state[name] < 0);
|
|
1761
|
+
else if (this.state[name] === 1) {
|
|
1762
|
+
if (pending[name] === void 0) pending[name] = true;
|
|
1763
|
+
} else {
|
|
1764
|
+
this.state[name] = 1;
|
|
1765
|
+
hasAllNamespaces = false;
|
|
1766
|
+
if (pending[name] === void 0) pending[name] = true;
|
|
1767
|
+
if (toLoad[name] === void 0) toLoad[name] = true;
|
|
1768
|
+
if (toLoadNamespaces[ns] === void 0) toLoadNamespaces[ns] = true;
|
|
1769
|
+
}
|
|
1770
|
+
});
|
|
1771
|
+
if (!hasAllNamespaces) toLoadLanguages[lng] = true;
|
|
1772
|
+
});
|
|
1773
|
+
if (Object.keys(toLoad).length || Object.keys(pending).length) this.queue.push({
|
|
1774
|
+
pending,
|
|
1775
|
+
pendingCount: Object.keys(pending).length,
|
|
1776
|
+
loaded: {},
|
|
1777
|
+
errors: [],
|
|
1778
|
+
callback
|
|
1779
|
+
});
|
|
1780
|
+
return {
|
|
1781
|
+
toLoad: Object.keys(toLoad),
|
|
1782
|
+
pending: Object.keys(pending),
|
|
1783
|
+
toLoadLanguages: Object.keys(toLoadLanguages),
|
|
1784
|
+
toLoadNamespaces: Object.keys(toLoadNamespaces)
|
|
1785
|
+
};
|
|
1786
|
+
}
|
|
1787
|
+
loaded(name, err, data) {
|
|
1788
|
+
const s = name.split("|");
|
|
1789
|
+
const lng = s[0];
|
|
1790
|
+
const ns = s[1];
|
|
1791
|
+
if (err) this.emit("failedLoading", lng, ns, err);
|
|
1792
|
+
if (!err && data) this.store.addResourceBundle(lng, ns, data, void 0, void 0, { skipCopy: true });
|
|
1793
|
+
this.state[name] = err ? -1 : 2;
|
|
1794
|
+
if (err && data) this.state[name] = 0;
|
|
1795
|
+
const loaded = {};
|
|
1796
|
+
this.queue.forEach((q) => {
|
|
1797
|
+
pushPath(q.loaded, [lng], ns);
|
|
1798
|
+
removePending(q, name);
|
|
1799
|
+
if (err) q.errors.push(err);
|
|
1800
|
+
if (q.pendingCount === 0 && !q.done) {
|
|
1801
|
+
Object.keys(q.loaded).forEach((l) => {
|
|
1802
|
+
if (!loaded[l]) loaded[l] = {};
|
|
1803
|
+
const loadedKeys = q.loaded[l];
|
|
1804
|
+
if (loadedKeys.length) loadedKeys.forEach((n) => {
|
|
1805
|
+
if (loaded[l][n] === void 0) loaded[l][n] = true;
|
|
1806
|
+
});
|
|
1807
|
+
});
|
|
1808
|
+
q.done = true;
|
|
1809
|
+
if (q.errors.length) q.callback(q.errors);
|
|
1810
|
+
else q.callback();
|
|
1811
|
+
}
|
|
1812
|
+
});
|
|
1813
|
+
this.emit("loaded", loaded);
|
|
1814
|
+
this.queue = this.queue.filter((q) => !q.done);
|
|
1815
|
+
}
|
|
1816
|
+
read(lng, ns, fcName) {
|
|
1817
|
+
let tried = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : 0;
|
|
1818
|
+
let wait = arguments.length > 4 && arguments[4] !== void 0 ? arguments[4] : this.retryTimeout;
|
|
1819
|
+
let callback = arguments.length > 5 ? arguments[5] : void 0;
|
|
1820
|
+
if (!lng.length) return callback(null, {});
|
|
1821
|
+
if (this.readingCalls >= this.maxParallelReads) {
|
|
1822
|
+
this.waitingReads.push({
|
|
1823
|
+
lng,
|
|
1824
|
+
ns,
|
|
1825
|
+
fcName,
|
|
1826
|
+
tried,
|
|
1827
|
+
wait,
|
|
1828
|
+
callback
|
|
1829
|
+
});
|
|
1830
|
+
return;
|
|
1831
|
+
}
|
|
1832
|
+
this.readingCalls++;
|
|
1833
|
+
const resolver = (err, data) => {
|
|
1834
|
+
this.readingCalls--;
|
|
1835
|
+
if (this.waitingReads.length > 0) {
|
|
1836
|
+
const next = this.waitingReads.shift();
|
|
1837
|
+
this.read(next.lng, next.ns, next.fcName, next.tried, next.wait, next.callback);
|
|
1838
|
+
}
|
|
1839
|
+
if (err && data && tried < this.maxRetries) {
|
|
1840
|
+
setTimeout(() => {
|
|
1841
|
+
this.read.call(this, lng, ns, fcName, tried + 1, wait * 2, callback);
|
|
1842
|
+
}, wait);
|
|
1843
|
+
return;
|
|
1844
|
+
}
|
|
1845
|
+
callback(err, data);
|
|
1846
|
+
};
|
|
1847
|
+
const fc = this.backend[fcName].bind(this.backend);
|
|
1848
|
+
if (fc.length === 2) {
|
|
1849
|
+
try {
|
|
1850
|
+
const r = fc(lng, ns);
|
|
1851
|
+
if (r && typeof r.then === "function") r.then((data) => resolver(null, data)).catch(resolver);
|
|
1852
|
+
else resolver(null, r);
|
|
1853
|
+
} catch (err) {
|
|
1854
|
+
resolver(err);
|
|
1855
|
+
}
|
|
1856
|
+
return;
|
|
1857
|
+
}
|
|
1858
|
+
return fc(lng, ns, resolver);
|
|
1859
|
+
}
|
|
1860
|
+
prepareLoading(languages, namespaces) {
|
|
1861
|
+
let options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
|
|
1862
|
+
let callback = arguments.length > 3 ? arguments[3] : void 0;
|
|
1863
|
+
if (!this.backend) {
|
|
1864
|
+
this.logger.warn("No backend was added via i18next.use. Will not load resources.");
|
|
1865
|
+
return callback && callback();
|
|
1866
|
+
}
|
|
1867
|
+
if (isString(languages)) languages = this.languageUtils.toResolveHierarchy(languages);
|
|
1868
|
+
if (isString(namespaces)) namespaces = [namespaces];
|
|
1869
|
+
const toLoad = this.queueLoad(languages, namespaces, options, callback);
|
|
1870
|
+
if (!toLoad.toLoad.length) {
|
|
1871
|
+
if (!toLoad.pending.length) callback();
|
|
1872
|
+
return null;
|
|
1873
|
+
}
|
|
1874
|
+
toLoad.toLoad.forEach((name) => {
|
|
1875
|
+
this.loadOne(name);
|
|
1876
|
+
});
|
|
1877
|
+
}
|
|
1878
|
+
load(languages, namespaces, callback) {
|
|
1879
|
+
this.prepareLoading(languages, namespaces, {}, callback);
|
|
1880
|
+
}
|
|
1881
|
+
reload(languages, namespaces, callback) {
|
|
1882
|
+
this.prepareLoading(languages, namespaces, { reload: true }, callback);
|
|
1883
|
+
}
|
|
1884
|
+
loadOne(name) {
|
|
1885
|
+
let prefix = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "";
|
|
1886
|
+
const s = name.split("|");
|
|
1887
|
+
const lng = s[0];
|
|
1888
|
+
const ns = s[1];
|
|
1889
|
+
this.read(lng, ns, "read", void 0, void 0, (err, data) => {
|
|
1890
|
+
if (err) this.logger.warn(`${prefix}loading namespace ${ns} for language ${lng} failed`, err);
|
|
1891
|
+
if (!err && data) this.logger.log(`${prefix}loaded namespace ${ns} for language ${lng}`, data);
|
|
1892
|
+
this.loaded(name, err, data);
|
|
1893
|
+
});
|
|
1894
|
+
}
|
|
1895
|
+
saveMissing(languages, namespace, key, fallbackValue, isUpdate) {
|
|
1896
|
+
let options = arguments.length > 5 && arguments[5] !== void 0 ? arguments[5] : {};
|
|
1897
|
+
let clb = arguments.length > 6 && arguments[6] !== void 0 ? arguments[6] : () => {};
|
|
1898
|
+
if (this.services.utils && this.services.utils.hasLoadedNamespace && !this.services.utils.hasLoadedNamespace(namespace)) {
|
|
1899
|
+
this.logger.warn(`did not save key "${key}" as the namespace "${namespace}" was not yet loaded`, "This means something IS WRONG in your setup. You access the t function before i18next.init / i18next.loadNamespace / i18next.changeLanguage was done. Wait for the callback or Promise to resolve before accessing it!!!");
|
|
1900
|
+
return;
|
|
1901
|
+
}
|
|
1902
|
+
if (key === void 0 || key === null || key === "") return;
|
|
1903
|
+
if (this.backend && this.backend.create) {
|
|
1904
|
+
const opts = {
|
|
1905
|
+
...options,
|
|
1906
|
+
isUpdate
|
|
1907
|
+
};
|
|
1908
|
+
const fc = this.backend.create.bind(this.backend);
|
|
1909
|
+
if (fc.length < 6) try {
|
|
1910
|
+
let r;
|
|
1911
|
+
if (fc.length === 5) r = fc(languages, namespace, key, fallbackValue, opts);
|
|
1912
|
+
else r = fc(languages, namespace, key, fallbackValue);
|
|
1913
|
+
if (r && typeof r.then === "function") r.then((data) => clb(null, data)).catch(clb);
|
|
1914
|
+
else clb(null, r);
|
|
1915
|
+
} catch (err) {
|
|
1916
|
+
clb(err);
|
|
1917
|
+
}
|
|
1918
|
+
else fc(languages, namespace, key, fallbackValue, clb, opts);
|
|
1919
|
+
}
|
|
1920
|
+
if (!languages || !languages[0]) return;
|
|
1921
|
+
this.store.addResource(languages[0], namespace, key, fallbackValue);
|
|
1922
|
+
}
|
|
1923
|
+
};
|
|
1924
|
+
var get = () => ({
|
|
1925
|
+
debug: false,
|
|
1926
|
+
initImmediate: true,
|
|
1927
|
+
ns: ["translation"],
|
|
1928
|
+
defaultNS: ["translation"],
|
|
1929
|
+
fallbackLng: ["dev"],
|
|
1930
|
+
fallbackNS: false,
|
|
1931
|
+
supportedLngs: false,
|
|
1932
|
+
nonExplicitSupportedLngs: false,
|
|
1933
|
+
load: "all",
|
|
1934
|
+
preload: false,
|
|
1935
|
+
simplifyPluralSuffix: true,
|
|
1936
|
+
keySeparator: ".",
|
|
1937
|
+
nsSeparator: ":",
|
|
1938
|
+
pluralSeparator: "_",
|
|
1939
|
+
contextSeparator: "_",
|
|
1940
|
+
partialBundledLanguages: false,
|
|
1941
|
+
saveMissing: false,
|
|
1942
|
+
updateMissing: false,
|
|
1943
|
+
saveMissingTo: "fallback",
|
|
1944
|
+
saveMissingPlurals: true,
|
|
1945
|
+
missingKeyHandler: false,
|
|
1946
|
+
missingInterpolationHandler: false,
|
|
1947
|
+
postProcess: false,
|
|
1948
|
+
postProcessPassResolved: false,
|
|
1949
|
+
returnNull: false,
|
|
1950
|
+
returnEmptyString: true,
|
|
1951
|
+
returnObjects: false,
|
|
1952
|
+
joinArrays: false,
|
|
1953
|
+
returnedObjectHandler: false,
|
|
1954
|
+
parseMissingKeyHandler: false,
|
|
1955
|
+
appendNamespaceToMissingKey: false,
|
|
1956
|
+
appendNamespaceToCIMode: false,
|
|
1957
|
+
overloadTranslationOptionHandler: (args) => {
|
|
1958
|
+
let ret = {};
|
|
1959
|
+
if (typeof args[1] === "object") ret = args[1];
|
|
1960
|
+
if (isString(args[1])) ret.defaultValue = args[1];
|
|
1961
|
+
if (isString(args[2])) ret.tDescription = args[2];
|
|
1962
|
+
if (typeof args[2] === "object" || typeof args[3] === "object") {
|
|
1963
|
+
const options = args[3] || args[2];
|
|
1964
|
+
Object.keys(options).forEach((key) => {
|
|
1965
|
+
ret[key] = options[key];
|
|
1966
|
+
});
|
|
1967
|
+
}
|
|
1968
|
+
return ret;
|
|
1969
|
+
},
|
|
1970
|
+
interpolation: {
|
|
1971
|
+
escapeValue: true,
|
|
1972
|
+
format: (value) => value,
|
|
1973
|
+
prefix: "{{",
|
|
1974
|
+
suffix: "}}",
|
|
1975
|
+
formatSeparator: ",",
|
|
1976
|
+
unescapePrefix: "-",
|
|
1977
|
+
nestingPrefix: "$t(",
|
|
1978
|
+
nestingSuffix: ")",
|
|
1979
|
+
nestingOptionsSeparator: ",",
|
|
1980
|
+
maxReplaces: 1e3,
|
|
1981
|
+
skipOnVariables: true
|
|
1982
|
+
}
|
|
1983
|
+
});
|
|
1984
|
+
var transformOptions = (options) => {
|
|
1985
|
+
if (isString(options.ns)) options.ns = [options.ns];
|
|
1986
|
+
if (isString(options.fallbackLng)) options.fallbackLng = [options.fallbackLng];
|
|
1987
|
+
if (isString(options.fallbackNS)) options.fallbackNS = [options.fallbackNS];
|
|
1988
|
+
if (options.supportedLngs && options.supportedLngs.indexOf("cimode") < 0) options.supportedLngs = options.supportedLngs.concat(["cimode"]);
|
|
1989
|
+
return options;
|
|
1990
|
+
};
|
|
1991
|
+
var noop = () => {};
|
|
1992
|
+
var bindMemberFunctions = (inst) => {
|
|
1993
|
+
Object.getOwnPropertyNames(Object.getPrototypeOf(inst)).forEach((mem) => {
|
|
1994
|
+
if (typeof inst[mem] === "function") inst[mem] = inst[mem].bind(inst);
|
|
1995
|
+
});
|
|
1996
|
+
};
|
|
1997
|
+
var I18n = class I18n extends EventEmitter {
|
|
1998
|
+
constructor() {
|
|
1999
|
+
let options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
2000
|
+
let callback = arguments.length > 1 ? arguments[1] : void 0;
|
|
2001
|
+
super();
|
|
2002
|
+
this.options = transformOptions(options);
|
|
2003
|
+
this.services = {};
|
|
2004
|
+
this.logger = baseLogger;
|
|
2005
|
+
this.modules = { external: [] };
|
|
2006
|
+
bindMemberFunctions(this);
|
|
2007
|
+
if (callback && !this.isInitialized && !options.isClone) {
|
|
2008
|
+
if (!this.options.initImmediate) {
|
|
2009
|
+
this.init(options, callback);
|
|
2010
|
+
return this;
|
|
2011
|
+
}
|
|
2012
|
+
setTimeout(() => {
|
|
2013
|
+
this.init(options, callback);
|
|
2014
|
+
}, 0);
|
|
2015
|
+
}
|
|
2016
|
+
}
|
|
2017
|
+
init() {
|
|
2018
|
+
var _this = this;
|
|
2019
|
+
let options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
2020
|
+
let callback = arguments.length > 1 ? arguments[1] : void 0;
|
|
2021
|
+
this.isInitializing = true;
|
|
2022
|
+
if (typeof options === "function") {
|
|
2023
|
+
callback = options;
|
|
2024
|
+
options = {};
|
|
2025
|
+
}
|
|
2026
|
+
if (!options.defaultNS && options.defaultNS !== false && options.ns) {
|
|
2027
|
+
if (isString(options.ns)) options.defaultNS = options.ns;
|
|
2028
|
+
else if (options.ns.indexOf("translation") < 0) options.defaultNS = options.ns[0];
|
|
2029
|
+
}
|
|
2030
|
+
const defOpts = get();
|
|
2031
|
+
this.options = {
|
|
2032
|
+
...defOpts,
|
|
2033
|
+
...this.options,
|
|
2034
|
+
...transformOptions(options)
|
|
2035
|
+
};
|
|
2036
|
+
if (this.options.compatibilityAPI !== "v1") this.options.interpolation = {
|
|
2037
|
+
...defOpts.interpolation,
|
|
2038
|
+
...this.options.interpolation
|
|
2039
|
+
};
|
|
2040
|
+
if (options.keySeparator !== void 0) this.options.userDefinedKeySeparator = options.keySeparator;
|
|
2041
|
+
if (options.nsSeparator !== void 0) this.options.userDefinedNsSeparator = options.nsSeparator;
|
|
2042
|
+
const createClassOnDemand = (ClassOrObject) => {
|
|
2043
|
+
if (!ClassOrObject) return null;
|
|
2044
|
+
if (typeof ClassOrObject === "function") return new ClassOrObject();
|
|
2045
|
+
return ClassOrObject;
|
|
2046
|
+
};
|
|
2047
|
+
if (!this.options.isClone) {
|
|
2048
|
+
if (this.modules.logger) baseLogger.init(createClassOnDemand(this.modules.logger), this.options);
|
|
2049
|
+
else baseLogger.init(null, this.options);
|
|
2050
|
+
let formatter;
|
|
2051
|
+
if (this.modules.formatter) formatter = this.modules.formatter;
|
|
2052
|
+
else if (typeof Intl !== "undefined") formatter = Formatter;
|
|
2053
|
+
const lu = new LanguageUtil(this.options);
|
|
2054
|
+
this.store = new ResourceStore(this.options.resources, this.options);
|
|
2055
|
+
const s = this.services;
|
|
2056
|
+
s.logger = baseLogger;
|
|
2057
|
+
s.resourceStore = this.store;
|
|
2058
|
+
s.languageUtils = lu;
|
|
2059
|
+
s.pluralResolver = new PluralResolver(lu, {
|
|
2060
|
+
prepend: this.options.pluralSeparator,
|
|
2061
|
+
compatibilityJSON: this.options.compatibilityJSON,
|
|
2062
|
+
simplifyPluralSuffix: this.options.simplifyPluralSuffix
|
|
2063
|
+
});
|
|
2064
|
+
if (formatter && (!this.options.interpolation.format || this.options.interpolation.format === defOpts.interpolation.format)) {
|
|
2065
|
+
s.formatter = createClassOnDemand(formatter);
|
|
2066
|
+
s.formatter.init(s, this.options);
|
|
2067
|
+
this.options.interpolation.format = s.formatter.format.bind(s.formatter);
|
|
2068
|
+
}
|
|
2069
|
+
s.interpolator = new Interpolator(this.options);
|
|
2070
|
+
s.utils = { hasLoadedNamespace: this.hasLoadedNamespace.bind(this) };
|
|
2071
|
+
s.backendConnector = new Connector(createClassOnDemand(this.modules.backend), s.resourceStore, s, this.options);
|
|
2072
|
+
s.backendConnector.on("*", function(event) {
|
|
2073
|
+
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) args[_key - 1] = arguments[_key];
|
|
2074
|
+
_this.emit(event, ...args);
|
|
2075
|
+
});
|
|
2076
|
+
if (this.modules.languageDetector) {
|
|
2077
|
+
s.languageDetector = createClassOnDemand(this.modules.languageDetector);
|
|
2078
|
+
if (s.languageDetector.init) s.languageDetector.init(s, this.options.detection, this.options);
|
|
2079
|
+
}
|
|
2080
|
+
if (this.modules.i18nFormat) {
|
|
2081
|
+
s.i18nFormat = createClassOnDemand(this.modules.i18nFormat);
|
|
2082
|
+
if (s.i18nFormat.init) s.i18nFormat.init(this);
|
|
2083
|
+
}
|
|
2084
|
+
this.translator = new Translator(this.services, this.options);
|
|
2085
|
+
this.translator.on("*", function(event) {
|
|
2086
|
+
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) args[_key2 - 1] = arguments[_key2];
|
|
2087
|
+
_this.emit(event, ...args);
|
|
2088
|
+
});
|
|
2089
|
+
this.modules.external.forEach((m) => {
|
|
2090
|
+
if (m.init) m.init(this);
|
|
2091
|
+
});
|
|
2092
|
+
}
|
|
2093
|
+
this.format = this.options.interpolation.format;
|
|
2094
|
+
if (!callback) callback = noop;
|
|
2095
|
+
if (this.options.fallbackLng && !this.services.languageDetector && !this.options.lng) {
|
|
2096
|
+
const codes = this.services.languageUtils.getFallbackCodes(this.options.fallbackLng);
|
|
2097
|
+
if (codes.length > 0 && codes[0] !== "dev") this.options.lng = codes[0];
|
|
2098
|
+
}
|
|
2099
|
+
if (!this.services.languageDetector && !this.options.lng) this.logger.warn("init: no languageDetector is used and no lng is defined");
|
|
2100
|
+
[
|
|
2101
|
+
"getResource",
|
|
2102
|
+
"hasResourceBundle",
|
|
2103
|
+
"getResourceBundle",
|
|
2104
|
+
"getDataByLanguage"
|
|
2105
|
+
].forEach((fcName) => {
|
|
2106
|
+
this[fcName] = function() {
|
|
2107
|
+
return _this.store[fcName](...arguments);
|
|
2108
|
+
};
|
|
2109
|
+
});
|
|
2110
|
+
[
|
|
2111
|
+
"addResource",
|
|
2112
|
+
"addResources",
|
|
2113
|
+
"addResourceBundle",
|
|
2114
|
+
"removeResourceBundle"
|
|
2115
|
+
].forEach((fcName) => {
|
|
2116
|
+
this[fcName] = function() {
|
|
2117
|
+
_this.store[fcName](...arguments);
|
|
2118
|
+
return _this;
|
|
2119
|
+
};
|
|
2120
|
+
});
|
|
2121
|
+
const deferred = defer();
|
|
2122
|
+
const load = () => {
|
|
2123
|
+
const finish = (err, t) => {
|
|
2124
|
+
this.isInitializing = false;
|
|
2125
|
+
if (this.isInitialized && !this.initializedStoreOnce) this.logger.warn("init: i18next is already initialized. You should call init just once!");
|
|
2126
|
+
this.isInitialized = true;
|
|
2127
|
+
if (!this.options.isClone) this.logger.log("initialized", this.options);
|
|
2128
|
+
this.emit("initialized", this.options);
|
|
2129
|
+
deferred.resolve(t);
|
|
2130
|
+
callback(err, t);
|
|
2131
|
+
};
|
|
2132
|
+
if (this.languages && this.options.compatibilityAPI !== "v1" && !this.isInitialized) return finish(null, this.t.bind(this));
|
|
2133
|
+
this.changeLanguage(this.options.lng, finish);
|
|
2134
|
+
};
|
|
2135
|
+
if (this.options.resources || !this.options.initImmediate) load();
|
|
2136
|
+
else setTimeout(load, 0);
|
|
2137
|
+
return deferred;
|
|
2138
|
+
}
|
|
2139
|
+
loadResources(language) {
|
|
2140
|
+
let usedCallback = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
|
|
2141
|
+
const usedLng = isString(language) ? language : this.language;
|
|
2142
|
+
if (typeof language === "function") usedCallback = language;
|
|
2143
|
+
if (!this.options.resources || this.options.partialBundledLanguages) {
|
|
2144
|
+
if (usedLng && usedLng.toLowerCase() === "cimode" && (!this.options.preload || this.options.preload.length === 0)) return usedCallback();
|
|
2145
|
+
const toLoad = [];
|
|
2146
|
+
const append = (lng) => {
|
|
2147
|
+
if (!lng) return;
|
|
2148
|
+
if (lng === "cimode") return;
|
|
2149
|
+
this.services.languageUtils.toResolveHierarchy(lng).forEach((l) => {
|
|
2150
|
+
if (l === "cimode") return;
|
|
2151
|
+
if (toLoad.indexOf(l) < 0) toLoad.push(l);
|
|
2152
|
+
});
|
|
2153
|
+
};
|
|
2154
|
+
if (!usedLng) this.services.languageUtils.getFallbackCodes(this.options.fallbackLng).forEach((l) => append(l));
|
|
2155
|
+
else append(usedLng);
|
|
2156
|
+
if (this.options.preload) this.options.preload.forEach((l) => append(l));
|
|
2157
|
+
this.services.backendConnector.load(toLoad, this.options.ns, (e) => {
|
|
2158
|
+
if (!e && !this.resolvedLanguage && this.language) this.setResolvedLanguage(this.language);
|
|
2159
|
+
usedCallback(e);
|
|
2160
|
+
});
|
|
2161
|
+
} else usedCallback(null);
|
|
2162
|
+
}
|
|
2163
|
+
reloadResources(lngs, ns, callback) {
|
|
2164
|
+
const deferred = defer();
|
|
2165
|
+
if (typeof lngs === "function") {
|
|
2166
|
+
callback = lngs;
|
|
2167
|
+
lngs = void 0;
|
|
2168
|
+
}
|
|
2169
|
+
if (typeof ns === "function") {
|
|
2170
|
+
callback = ns;
|
|
2171
|
+
ns = void 0;
|
|
2172
|
+
}
|
|
2173
|
+
if (!lngs) lngs = this.languages;
|
|
2174
|
+
if (!ns) ns = this.options.ns;
|
|
2175
|
+
if (!callback) callback = noop;
|
|
2176
|
+
this.services.backendConnector.reload(lngs, ns, (err) => {
|
|
2177
|
+
deferred.resolve();
|
|
2178
|
+
callback(err);
|
|
2179
|
+
});
|
|
2180
|
+
return deferred;
|
|
2181
|
+
}
|
|
2182
|
+
use(module) {
|
|
2183
|
+
if (!module) throw new Error("You are passing an undefined module! Please check the object you are passing to i18next.use()");
|
|
2184
|
+
if (!module.type) throw new Error("You are passing a wrong module! Please check the object you are passing to i18next.use()");
|
|
2185
|
+
if (module.type === "backend") this.modules.backend = module;
|
|
2186
|
+
if (module.type === "logger" || module.log && module.warn && module.error) this.modules.logger = module;
|
|
2187
|
+
if (module.type === "languageDetector") this.modules.languageDetector = module;
|
|
2188
|
+
if (module.type === "i18nFormat") this.modules.i18nFormat = module;
|
|
2189
|
+
if (module.type === "postProcessor") postProcessor.addPostProcessor(module);
|
|
2190
|
+
if (module.type === "formatter") this.modules.formatter = module;
|
|
2191
|
+
if (module.type === "3rdParty") this.modules.external.push(module);
|
|
2192
|
+
return this;
|
|
2193
|
+
}
|
|
2194
|
+
setResolvedLanguage(l) {
|
|
2195
|
+
if (!l || !this.languages) return;
|
|
2196
|
+
if (["cimode", "dev"].indexOf(l) > -1) return;
|
|
2197
|
+
for (let li = 0; li < this.languages.length; li++) {
|
|
2198
|
+
const lngInLngs = this.languages[li];
|
|
2199
|
+
if (["cimode", "dev"].indexOf(lngInLngs) > -1) continue;
|
|
2200
|
+
if (this.store.hasLanguageSomeTranslations(lngInLngs)) {
|
|
2201
|
+
this.resolvedLanguage = lngInLngs;
|
|
2202
|
+
break;
|
|
2203
|
+
}
|
|
2204
|
+
}
|
|
2205
|
+
}
|
|
2206
|
+
changeLanguage(lng, callback) {
|
|
2207
|
+
var _this2 = this;
|
|
2208
|
+
this.isLanguageChangingTo = lng;
|
|
2209
|
+
const deferred = defer();
|
|
2210
|
+
this.emit("languageChanging", lng);
|
|
2211
|
+
const setLngProps = (l) => {
|
|
2212
|
+
this.language = l;
|
|
2213
|
+
this.languages = this.services.languageUtils.toResolveHierarchy(l);
|
|
2214
|
+
this.resolvedLanguage = void 0;
|
|
2215
|
+
this.setResolvedLanguage(l);
|
|
2216
|
+
};
|
|
2217
|
+
const done = (err, l) => {
|
|
2218
|
+
if (l) {
|
|
2219
|
+
setLngProps(l);
|
|
2220
|
+
this.translator.changeLanguage(l);
|
|
2221
|
+
this.isLanguageChangingTo = void 0;
|
|
2222
|
+
this.emit("languageChanged", l);
|
|
2223
|
+
this.logger.log("languageChanged", l);
|
|
2224
|
+
} else this.isLanguageChangingTo = void 0;
|
|
2225
|
+
deferred.resolve(function() {
|
|
2226
|
+
return _this2.t(...arguments);
|
|
2227
|
+
});
|
|
2228
|
+
if (callback) callback(err, function() {
|
|
2229
|
+
return _this2.t(...arguments);
|
|
2230
|
+
});
|
|
2231
|
+
};
|
|
2232
|
+
const setLng = (lngs) => {
|
|
2233
|
+
if (!lng && !lngs && this.services.languageDetector) lngs = [];
|
|
2234
|
+
const l = isString(lngs) ? lngs : this.services.languageUtils.getBestMatchFromCodes(lngs);
|
|
2235
|
+
if (l) {
|
|
2236
|
+
if (!this.language) setLngProps(l);
|
|
2237
|
+
if (!this.translator.language) this.translator.changeLanguage(l);
|
|
2238
|
+
if (this.services.languageDetector && this.services.languageDetector.cacheUserLanguage) this.services.languageDetector.cacheUserLanguage(l);
|
|
2239
|
+
}
|
|
2240
|
+
this.loadResources(l, (err) => {
|
|
2241
|
+
done(err, l);
|
|
2242
|
+
});
|
|
2243
|
+
};
|
|
2244
|
+
if (!lng && this.services.languageDetector && !this.services.languageDetector.async) setLng(this.services.languageDetector.detect());
|
|
2245
|
+
else if (!lng && this.services.languageDetector && this.services.languageDetector.async) {
|
|
2246
|
+
if (this.services.languageDetector.detect.length === 0) this.services.languageDetector.detect().then(setLng);
|
|
2247
|
+
else this.services.languageDetector.detect(setLng);
|
|
2248
|
+
} else setLng(lng);
|
|
2249
|
+
return deferred;
|
|
2250
|
+
}
|
|
2251
|
+
getFixedT(lng, ns, keyPrefix) {
|
|
2252
|
+
var _this3 = this;
|
|
2253
|
+
const fixedT = function(key, opts) {
|
|
2254
|
+
let options;
|
|
2255
|
+
if (typeof opts !== "object") {
|
|
2256
|
+
for (var _len3 = arguments.length, rest = new Array(_len3 > 2 ? _len3 - 2 : 0), _key3 = 2; _key3 < _len3; _key3++) rest[_key3 - 2] = arguments[_key3];
|
|
2257
|
+
options = _this3.options.overloadTranslationOptionHandler([key, opts].concat(rest));
|
|
2258
|
+
} else options = { ...opts };
|
|
2259
|
+
options.lng = options.lng || fixedT.lng;
|
|
2260
|
+
options.lngs = options.lngs || fixedT.lngs;
|
|
2261
|
+
options.ns = options.ns || fixedT.ns;
|
|
2262
|
+
if (options.keyPrefix !== "") options.keyPrefix = options.keyPrefix || keyPrefix || fixedT.keyPrefix;
|
|
2263
|
+
const keySeparator = _this3.options.keySeparator || ".";
|
|
2264
|
+
let resultKey;
|
|
2265
|
+
if (options.keyPrefix && Array.isArray(key)) resultKey = key.map((k) => `${options.keyPrefix}${keySeparator}${k}`);
|
|
2266
|
+
else resultKey = options.keyPrefix ? `${options.keyPrefix}${keySeparator}${key}` : key;
|
|
2267
|
+
return _this3.t(resultKey, options);
|
|
2268
|
+
};
|
|
2269
|
+
if (isString(lng)) fixedT.lng = lng;
|
|
2270
|
+
else fixedT.lngs = lng;
|
|
2271
|
+
fixedT.ns = ns;
|
|
2272
|
+
fixedT.keyPrefix = keyPrefix;
|
|
2273
|
+
return fixedT;
|
|
2274
|
+
}
|
|
2275
|
+
t() {
|
|
2276
|
+
return this.translator && this.translator.translate(...arguments);
|
|
2277
|
+
}
|
|
2278
|
+
exists() {
|
|
2279
|
+
return this.translator && this.translator.exists(...arguments);
|
|
2280
|
+
}
|
|
2281
|
+
setDefaultNamespace(ns) {
|
|
2282
|
+
this.options.defaultNS = ns;
|
|
2283
|
+
}
|
|
2284
|
+
hasLoadedNamespace(ns) {
|
|
2285
|
+
let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
2286
|
+
if (!this.isInitialized) {
|
|
2287
|
+
this.logger.warn("hasLoadedNamespace: i18next was not initialized", this.languages);
|
|
2288
|
+
return false;
|
|
2289
|
+
}
|
|
2290
|
+
if (!this.languages || !this.languages.length) {
|
|
2291
|
+
this.logger.warn("hasLoadedNamespace: i18n.languages were undefined or empty", this.languages);
|
|
2292
|
+
return false;
|
|
2293
|
+
}
|
|
2294
|
+
const lng = options.lng || this.resolvedLanguage || this.languages[0];
|
|
2295
|
+
const fallbackLng = this.options ? this.options.fallbackLng : false;
|
|
2296
|
+
const lastLng = this.languages[this.languages.length - 1];
|
|
2297
|
+
if (lng.toLowerCase() === "cimode") return true;
|
|
2298
|
+
const loadNotPending = (l, n) => {
|
|
2299
|
+
const loadState = this.services.backendConnector.state[`${l}|${n}`];
|
|
2300
|
+
return loadState === -1 || loadState === 0 || loadState === 2;
|
|
2301
|
+
};
|
|
2302
|
+
if (options.precheck) {
|
|
2303
|
+
const preResult = options.precheck(this, loadNotPending);
|
|
2304
|
+
if (preResult !== void 0) return preResult;
|
|
2305
|
+
}
|
|
2306
|
+
if (this.hasResourceBundle(lng, ns)) return true;
|
|
2307
|
+
if (!this.services.backendConnector.backend || this.options.resources && !this.options.partialBundledLanguages) return true;
|
|
2308
|
+
if (loadNotPending(lng, ns) && (!fallbackLng || loadNotPending(lastLng, ns))) return true;
|
|
2309
|
+
return false;
|
|
2310
|
+
}
|
|
2311
|
+
loadNamespaces(ns, callback) {
|
|
2312
|
+
const deferred = defer();
|
|
2313
|
+
if (!this.options.ns) {
|
|
2314
|
+
if (callback) callback();
|
|
2315
|
+
return Promise.resolve();
|
|
2316
|
+
}
|
|
2317
|
+
if (isString(ns)) ns = [ns];
|
|
2318
|
+
ns.forEach((n) => {
|
|
2319
|
+
if (this.options.ns.indexOf(n) < 0) this.options.ns.push(n);
|
|
2320
|
+
});
|
|
2321
|
+
this.loadResources((err) => {
|
|
2322
|
+
deferred.resolve();
|
|
2323
|
+
if (callback) callback(err);
|
|
2324
|
+
});
|
|
2325
|
+
return deferred;
|
|
2326
|
+
}
|
|
2327
|
+
loadLanguages(lngs, callback) {
|
|
2328
|
+
const deferred = defer();
|
|
2329
|
+
if (isString(lngs)) lngs = [lngs];
|
|
2330
|
+
const preloaded = this.options.preload || [];
|
|
2331
|
+
const newLngs = lngs.filter((lng) => preloaded.indexOf(lng) < 0 && this.services.languageUtils.isSupportedCode(lng));
|
|
2332
|
+
if (!newLngs.length) {
|
|
2333
|
+
if (callback) callback();
|
|
2334
|
+
return Promise.resolve();
|
|
2335
|
+
}
|
|
2336
|
+
this.options.preload = preloaded.concat(newLngs);
|
|
2337
|
+
this.loadResources((err) => {
|
|
2338
|
+
deferred.resolve();
|
|
2339
|
+
if (callback) callback(err);
|
|
2340
|
+
});
|
|
2341
|
+
return deferred;
|
|
2342
|
+
}
|
|
2343
|
+
dir(lng) {
|
|
2344
|
+
if (!lng) lng = this.resolvedLanguage || (this.languages && this.languages.length > 0 ? this.languages[0] : this.language);
|
|
2345
|
+
if (!lng) return "rtl";
|
|
2346
|
+
const rtlLngs = [
|
|
2347
|
+
"ar",
|
|
2348
|
+
"shu",
|
|
2349
|
+
"sqr",
|
|
2350
|
+
"ssh",
|
|
2351
|
+
"xaa",
|
|
2352
|
+
"yhd",
|
|
2353
|
+
"yud",
|
|
2354
|
+
"aao",
|
|
2355
|
+
"abh",
|
|
2356
|
+
"abv",
|
|
2357
|
+
"acm",
|
|
2358
|
+
"acq",
|
|
2359
|
+
"acw",
|
|
2360
|
+
"acx",
|
|
2361
|
+
"acy",
|
|
2362
|
+
"adf",
|
|
2363
|
+
"ads",
|
|
2364
|
+
"aeb",
|
|
2365
|
+
"aec",
|
|
2366
|
+
"afb",
|
|
2367
|
+
"ajp",
|
|
2368
|
+
"apc",
|
|
2369
|
+
"apd",
|
|
2370
|
+
"arb",
|
|
2371
|
+
"arq",
|
|
2372
|
+
"ars",
|
|
2373
|
+
"ary",
|
|
2374
|
+
"arz",
|
|
2375
|
+
"auz",
|
|
2376
|
+
"avl",
|
|
2377
|
+
"ayh",
|
|
2378
|
+
"ayl",
|
|
2379
|
+
"ayn",
|
|
2380
|
+
"ayp",
|
|
2381
|
+
"bbz",
|
|
2382
|
+
"pga",
|
|
2383
|
+
"he",
|
|
2384
|
+
"iw",
|
|
2385
|
+
"ps",
|
|
2386
|
+
"pbt",
|
|
2387
|
+
"pbu",
|
|
2388
|
+
"pst",
|
|
2389
|
+
"prp",
|
|
2390
|
+
"prd",
|
|
2391
|
+
"ug",
|
|
2392
|
+
"ur",
|
|
2393
|
+
"ydd",
|
|
2394
|
+
"yds",
|
|
2395
|
+
"yih",
|
|
2396
|
+
"ji",
|
|
2397
|
+
"yi",
|
|
2398
|
+
"hbo",
|
|
2399
|
+
"men",
|
|
2400
|
+
"xmn",
|
|
2401
|
+
"fa",
|
|
2402
|
+
"jpr",
|
|
2403
|
+
"peo",
|
|
2404
|
+
"pes",
|
|
2405
|
+
"prs",
|
|
2406
|
+
"dv",
|
|
2407
|
+
"sam",
|
|
2408
|
+
"ckb"
|
|
2409
|
+
];
|
|
2410
|
+
const languageUtils = this.services && this.services.languageUtils || new LanguageUtil(get());
|
|
2411
|
+
return rtlLngs.indexOf(languageUtils.getLanguagePartFromCode(lng)) > -1 || lng.toLowerCase().indexOf("-arab") > 1 ? "rtl" : "ltr";
|
|
2412
|
+
}
|
|
2413
|
+
static createInstance() {
|
|
2414
|
+
let options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
2415
|
+
let callback = arguments.length > 1 ? arguments[1] : void 0;
|
|
2416
|
+
return new I18n(options, callback);
|
|
2417
|
+
}
|
|
2418
|
+
cloneInstance() {
|
|
2419
|
+
let options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
2420
|
+
let callback = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
|
|
2421
|
+
const forkResourceStore = options.forkResourceStore;
|
|
2422
|
+
if (forkResourceStore) delete options.forkResourceStore;
|
|
2423
|
+
const mergedOptions = {
|
|
2424
|
+
...this.options,
|
|
2425
|
+
...options,
|
|
2426
|
+
isClone: true
|
|
2427
|
+
};
|
|
2428
|
+
const clone = new I18n(mergedOptions);
|
|
2429
|
+
if (options.debug !== void 0 || options.prefix !== void 0) clone.logger = clone.logger.clone(options);
|
|
2430
|
+
[
|
|
2431
|
+
"store",
|
|
2432
|
+
"services",
|
|
2433
|
+
"language"
|
|
2434
|
+
].forEach((m) => {
|
|
2435
|
+
clone[m] = this[m];
|
|
2436
|
+
});
|
|
2437
|
+
clone.services = { ...this.services };
|
|
2438
|
+
clone.services.utils = { hasLoadedNamespace: clone.hasLoadedNamespace.bind(clone) };
|
|
2439
|
+
if (forkResourceStore) {
|
|
2440
|
+
clone.store = new ResourceStore(this.store.data, mergedOptions);
|
|
2441
|
+
clone.services.resourceStore = clone.store;
|
|
2442
|
+
}
|
|
2443
|
+
clone.translator = new Translator(clone.services, mergedOptions);
|
|
2444
|
+
clone.translator.on("*", function(event) {
|
|
2445
|
+
for (var _len4 = arguments.length, args = new Array(_len4 > 1 ? _len4 - 1 : 0), _key4 = 1; _key4 < _len4; _key4++) args[_key4 - 1] = arguments[_key4];
|
|
2446
|
+
clone.emit(event, ...args);
|
|
2447
|
+
});
|
|
2448
|
+
clone.init(mergedOptions, callback);
|
|
2449
|
+
clone.translator.options = mergedOptions;
|
|
2450
|
+
clone.translator.backendConnector.services.utils = { hasLoadedNamespace: clone.hasLoadedNamespace.bind(clone) };
|
|
2451
|
+
return clone;
|
|
2452
|
+
}
|
|
2453
|
+
toJSON() {
|
|
2454
|
+
return {
|
|
2455
|
+
options: this.options,
|
|
2456
|
+
store: this.store,
|
|
2457
|
+
language: this.language,
|
|
2458
|
+
languages: this.languages,
|
|
2459
|
+
resolvedLanguage: this.resolvedLanguage
|
|
2460
|
+
};
|
|
2461
|
+
}
|
|
2462
|
+
};
|
|
2463
|
+
var instance = I18n.createInstance();
|
|
2464
|
+
instance.createInstance = I18n.createInstance;
|
|
2465
|
+
var createInstance = instance.createInstance;
|
|
2466
|
+
instance.dir;
|
|
2467
|
+
instance.init;
|
|
2468
|
+
instance.loadResources;
|
|
2469
|
+
instance.reloadResources;
|
|
2470
|
+
instance.use;
|
|
2471
|
+
instance.changeLanguage;
|
|
2472
|
+
instance.getFixedT;
|
|
2473
|
+
instance.t;
|
|
2474
|
+
instance.exists;
|
|
2475
|
+
instance.setDefaultNamespace;
|
|
2476
|
+
instance.hasLoadedNamespace;
|
|
2477
|
+
instance.loadNamespaces;
|
|
2478
|
+
instance.loadLanguages;
|
|
2479
|
+
//#endregion
|
|
2480
|
+
//#region src/i18n.ts
|
|
2481
|
+
var catalogs = {
|
|
2482
|
+
"de-de": {
|
|
2483
|
+
"common.close": "Schließen",
|
|
2484
|
+
"common.loading": "Lädt...",
|
|
2485
|
+
"common.next": "Weiter",
|
|
2486
|
+
"common.previous": "Vorherige",
|
|
2487
|
+
"file_preview.load_error.description": "Der Vorschauinhalt konnte nicht geladen werden.",
|
|
2488
|
+
"file_preview.load_error.title": "Vorschau fehlgeschlagen",
|
|
2489
|
+
"file_preview.loading": "Vorschau wird geladen...",
|
|
2490
|
+
"file_preview.pdf.outline.empty": "Diese PDF-Datei hat kein Inhaltsverzeichnis.",
|
|
2491
|
+
"file_preview.pdf.outline.load_error": "Das Inhaltsverzeichnis konnte nicht geladen werden.",
|
|
2492
|
+
"file_preview.pdf.outline.title": "Inhaltsverzeichnis",
|
|
2493
|
+
"file_preview.pdf.page_number": "Seitenzahl",
|
|
2494
|
+
"file_preview.pdf.too_large.description": "Ein Teil dieser PDF-Datei ist zu groß, um sicher in der App angezeigt zu werden.",
|
|
2495
|
+
"file_preview.pdf.too_large.title": "Diese PDF kann nicht in der Vorschau angezeigt werden",
|
|
2496
|
+
"file_preview.too_large.action": "Mit Standard-App öffnen",
|
|
2497
|
+
"file_preview.too_large.description": "Die Dateigröße {{size}} überschreitet das Vorschaulimit von {{limit}}.",
|
|
2498
|
+
"file_preview.too_large.title": "Datei zu groß für die Vorschau",
|
|
2499
|
+
"file_preview.unsupported.action": "Mit Standard-App öffnen",
|
|
2500
|
+
"file_preview.unsupported.description": "Dieser Dateityp kann noch nicht in der Vorschau angezeigt werden.",
|
|
2501
|
+
"file_preview.unsupported.title": "Vorschau nicht verfügbar",
|
|
2502
|
+
"preview.flip_horizontal": "Horizontal spiegeln",
|
|
2503
|
+
"preview.flip_vertical": "Vertikal spiegeln",
|
|
2504
|
+
"preview.label": "Vorschau",
|
|
2505
|
+
"preview.reset": "Zurücksetzen",
|
|
2506
|
+
"preview.rotate_left": "Nach links drehen",
|
|
2507
|
+
"preview.rotate_right": "Nach rechts drehen",
|
|
2508
|
+
"preview.zoom_in": "Vergrößern",
|
|
2509
|
+
"preview.zoom_out": "Verkleinern",
|
|
2510
|
+
"xlsx_preview.chart": "Diagramm",
|
|
2511
|
+
"xlsx_preview.chart_unsupported": "Dieser Diagrammtyp wird noch nicht unterstützt",
|
|
2512
|
+
"xlsx_preview.error.description": "Für diese Tabelle konnte keine Vorschau angezeigt werden.",
|
|
2513
|
+
"xlsx_preview.formula_not_evaluated": "Die Formel konnte nicht ausgewertet werden",
|
|
2514
|
+
"xlsx_preview.sheet_tabs_label": "Tabellenblätter"
|
|
2515
|
+
},
|
|
2516
|
+
"el-gr": {
|
|
2517
|
+
"common.close": "Κλείσιμο",
|
|
2518
|
+
"common.loading": "Φόρτωση...",
|
|
2519
|
+
"common.next": "Επόμενο",
|
|
2520
|
+
"common.previous": "Προηγούμενο",
|
|
2521
|
+
"file_preview.load_error.description": "Το περιεχόμενο προεπισκόπησης δεν μπόρεσε να φορτωθεί.",
|
|
2522
|
+
"file_preview.load_error.title": "Η προεπισκόπηση απέτυχε",
|
|
2523
|
+
"file_preview.loading": "Φόρτωση προεπισκόπησης...",
|
|
2524
|
+
"file_preview.pdf.outline.empty": "Αυτό το PDF δεν έχει πίνακα περιεχομένων.",
|
|
2525
|
+
"file_preview.pdf.outline.load_error": "Δεν ήταν δυνατή η φόρτωση του πίνακα περιεχομένων.",
|
|
2526
|
+
"file_preview.pdf.outline.title": "Πίνακας περιεχομένων",
|
|
2527
|
+
"file_preview.pdf.page_number": "Αριθμός σελίδας",
|
|
2528
|
+
"file_preview.pdf.too_large.description": "Μέρος αυτού του PDF είναι πολύ μεγάλο για ασφαλή προεπισκόπηση στην εφαρμογή.",
|
|
2529
|
+
"file_preview.pdf.too_large.title": "Δεν είναι δυνατή η προεπισκόπηση αυτού του PDF",
|
|
2530
|
+
"file_preview.too_large.action": "Άνοιγμα με προεπιλεγμένη εφαρμογή",
|
|
2531
|
+
"file_preview.too_large.description": "Το μέγεθος αρχείου {{size}} υπερβαίνει το όριο προεπισκόπησης {{limit}}.",
|
|
2532
|
+
"file_preview.too_large.title": "Το αρχείο είναι πολύ μεγάλο για προεπισκόπηση",
|
|
2533
|
+
"file_preview.unsupported.action": "Άνοιγμα με προεπιλεγμένη εφαρμογή",
|
|
2534
|
+
"file_preview.unsupported.description": "Αυτός ο τύπος αρχείου δεν μπορεί να προεπισκοπηθεί ακόμα.",
|
|
2535
|
+
"file_preview.unsupported.title": "Η προεπισκόπηση δεν είναι διαθέσιμη",
|
|
2536
|
+
"preview.flip_horizontal": "Αναστροφή Οριζόντια",
|
|
2537
|
+
"preview.flip_vertical": "Αναστροφή Κάθετα",
|
|
2538
|
+
"preview.label": "Προεπισκόπηση",
|
|
2539
|
+
"preview.reset": "Επαναφορά",
|
|
2540
|
+
"preview.rotate_left": "Περιστροφή Αριστερά",
|
|
2541
|
+
"preview.rotate_right": "Περιστροφή Δεξιά",
|
|
2542
|
+
"preview.zoom_in": "Μεγέθυνση",
|
|
2543
|
+
"preview.zoom_out": "συρρίκνωση",
|
|
2544
|
+
"xlsx_preview.chart": "Γράφημα",
|
|
2545
|
+
"xlsx_preview.chart_unsupported": "Αυτός ο τύπος γραφήματος δεν υποστηρίζεται ακόμη",
|
|
2546
|
+
"xlsx_preview.error.description": "Δεν ήταν δυνατή η προεπισκόπηση αυτού του υπολογιστικού φύλλου.",
|
|
2547
|
+
"xlsx_preview.formula_not_evaluated": "Δεν ήταν δυνατή η αξιολόγηση του τύπου",
|
|
2548
|
+
"xlsx_preview.sheet_tabs_label": "Φύλλα"
|
|
2549
|
+
},
|
|
2550
|
+
"en-us": {
|
|
2551
|
+
"common.close": "Close",
|
|
2552
|
+
"common.loading": "Loading...",
|
|
2553
|
+
"common.next": "Next",
|
|
2554
|
+
"common.previous": "Previous",
|
|
2555
|
+
"file_preview.load_error.description": "The preview content could not be loaded.",
|
|
2556
|
+
"file_preview.load_error.title": "Preview failed",
|
|
2557
|
+
"file_preview.loading": "Loading preview...",
|
|
2558
|
+
"file_preview.pdf.outline.empty": "This PDF has no table of contents.",
|
|
2559
|
+
"file_preview.pdf.outline.load_error": "Couldn't load the table of contents.",
|
|
2560
|
+
"file_preview.pdf.outline.title": "Table of contents",
|
|
2561
|
+
"file_preview.pdf.page_number": "Page number",
|
|
2562
|
+
"file_preview.pdf.too_large.description": "Part of this PDF is too large to preview safely in the app.",
|
|
2563
|
+
"file_preview.pdf.too_large.title": "Can't preview this PDF",
|
|
2564
|
+
"file_preview.too_large.action": "Open with default app",
|
|
2565
|
+
"file_preview.too_large.description": "File size {{size}} exceeds the {{limit}} preview limit.",
|
|
2566
|
+
"file_preview.too_large.title": "File too large to preview",
|
|
2567
|
+
"file_preview.unsupported.action": "Open with default app",
|
|
2568
|
+
"file_preview.unsupported.description": "This file type cannot be previewed yet.",
|
|
2569
|
+
"file_preview.unsupported.title": "Preview unavailable",
|
|
2570
|
+
"preview.flip_horizontal": "Flip Horizontal",
|
|
2571
|
+
"preview.flip_vertical": "Flip Vertical",
|
|
2572
|
+
"preview.label": "Preview",
|
|
2573
|
+
"preview.reset": "Reset",
|
|
2574
|
+
"preview.rotate_left": "Rotate Left",
|
|
2575
|
+
"preview.rotate_right": "Rotate Right",
|
|
2576
|
+
"preview.zoom_in": "Zoom In",
|
|
2577
|
+
"preview.zoom_out": "Zoom Out",
|
|
2578
|
+
"xlsx_preview.chart": "Chart",
|
|
2579
|
+
"xlsx_preview.chart_unsupported": "This chart type isn't supported yet",
|
|
2580
|
+
"xlsx_preview.error.description": "This spreadsheet couldn't be previewed.",
|
|
2581
|
+
"xlsx_preview.formula_not_evaluated": "Formula couldn't be evaluated",
|
|
2582
|
+
"xlsx_preview.sheet_tabs_label": "Sheets"
|
|
2583
|
+
},
|
|
2584
|
+
"es-es": {
|
|
2585
|
+
"common.close": "Cerrar",
|
|
2586
|
+
"common.loading": "Cargando...",
|
|
2587
|
+
"common.next": "Siguiente",
|
|
2588
|
+
"common.previous": "Anterior",
|
|
2589
|
+
"file_preview.load_error.description": "No se pudo cargar el contenido de vista previa.",
|
|
2590
|
+
"file_preview.load_error.title": "Vista previa fallida",
|
|
2591
|
+
"file_preview.loading": "Cargando vista previa...",
|
|
2592
|
+
"file_preview.pdf.outline.empty": "Este PDF no tiene índice.",
|
|
2593
|
+
"file_preview.pdf.outline.load_error": "No se pudo cargar el índice.",
|
|
2594
|
+
"file_preview.pdf.outline.title": "Índice",
|
|
2595
|
+
"file_preview.pdf.page_number": "Número de página",
|
|
2596
|
+
"file_preview.pdf.too_large.description": "Parte de este PDF es demasiado grande para previsualizarla de forma segura en la aplicación.",
|
|
2597
|
+
"file_preview.pdf.too_large.title": "No se puede previsualizar este PDF",
|
|
2598
|
+
"file_preview.too_large.action": "Abrir con la aplicación predeterminada",
|
|
2599
|
+
"file_preview.too_large.description": "El tamaño del archivo {{size}} supera el límite de vista previa de {{limit}}.",
|
|
2600
|
+
"file_preview.too_large.title": "El archivo es demasiado grande para previsualizarlo",
|
|
2601
|
+
"file_preview.unsupported.action": "Abrir con la aplicación predeterminada",
|
|
2602
|
+
"file_preview.unsupported.description": "Este tipo de archivo aún no se puede previsualizar.",
|
|
2603
|
+
"file_preview.unsupported.title": "Vista previa no disponible",
|
|
2604
|
+
"preview.flip_horizontal": "Voltear horizontalmente",
|
|
2605
|
+
"preview.flip_vertical": "Voltear verticalmente",
|
|
2606
|
+
"preview.label": "Vista previa",
|
|
2607
|
+
"preview.reset": "Restablecer",
|
|
2608
|
+
"preview.rotate_left": "Rotar a la izquierda",
|
|
2609
|
+
"preview.rotate_right": "Rotar a la derecha",
|
|
2610
|
+
"preview.zoom_in": "ampliar",
|
|
2611
|
+
"preview.zoom_out": "reducir",
|
|
2612
|
+
"xlsx_preview.chart": "Gráfico",
|
|
2613
|
+
"xlsx_preview.chart_unsupported": "Este tipo de gráfico todavía no es compatible",
|
|
2614
|
+
"xlsx_preview.error.description": "No se pudo previsualizar esta hoja de cálculo.",
|
|
2615
|
+
"xlsx_preview.formula_not_evaluated": "No se pudo evaluar la fórmula",
|
|
2616
|
+
"xlsx_preview.sheet_tabs_label": "Hojas"
|
|
2617
|
+
},
|
|
2618
|
+
"fr-fr": {
|
|
2619
|
+
"common.close": "Fermer",
|
|
2620
|
+
"common.loading": "Chargement...",
|
|
2621
|
+
"common.next": "Suivant",
|
|
2622
|
+
"common.previous": "Précédent",
|
|
2623
|
+
"file_preview.load_error.description": "Le contenu de l'aperçu n'a pas pu être chargé.",
|
|
2624
|
+
"file_preview.load_error.title": "L'aperçu a échoué",
|
|
2625
|
+
"file_preview.loading": "Chargement de l'aperçu...",
|
|
2626
|
+
"file_preview.pdf.outline.empty": "Ce PDF ne contient aucune table des matières.",
|
|
2627
|
+
"file_preview.pdf.outline.load_error": "Impossible de charger la table des matières.",
|
|
2628
|
+
"file_preview.pdf.outline.title": "Table des matières",
|
|
2629
|
+
"file_preview.pdf.page_number": "Numéro de page",
|
|
2630
|
+
"file_preview.pdf.too_large.description": "Une partie de ce PDF est trop volumineuse pour être prévisualisée en toute sécurité dans l'application.",
|
|
2631
|
+
"file_preview.pdf.too_large.title": "Impossible de prévisualiser ce PDF",
|
|
2632
|
+
"file_preview.too_large.action": "Ouvrir avec l'application par défaut",
|
|
2633
|
+
"file_preview.too_large.description": "La taille du fichier {{size}} dépasse la limite d’aperçu de {{limit}}.",
|
|
2634
|
+
"file_preview.too_large.title": "Fichier trop volumineux pour être prévisualisé",
|
|
2635
|
+
"file_preview.unsupported.action": "Ouvrir avec l'application par défaut",
|
|
2636
|
+
"file_preview.unsupported.description": "Ce type de fichier ne peut pas encore être prévisualisé.",
|
|
2637
|
+
"file_preview.unsupported.title": "Aperçu indisponible",
|
|
2638
|
+
"preview.flip_horizontal": "Retourner horizontalement",
|
|
2639
|
+
"preview.flip_vertical": "Retourner verticalement",
|
|
2640
|
+
"preview.label": "Aperçu",
|
|
2641
|
+
"preview.reset": "Réinitialiser",
|
|
2642
|
+
"preview.rotate_left": "Rotation vers la gauche",
|
|
2643
|
+
"preview.rotate_right": "Rotation vers la droite",
|
|
2644
|
+
"preview.zoom_in": "agrandir",
|
|
2645
|
+
"preview.zoom_out": "réduire",
|
|
2646
|
+
"xlsx_preview.chart": "Graphique",
|
|
2647
|
+
"xlsx_preview.chart_unsupported": "Ce type de graphique n’est pas encore pris en charge",
|
|
2648
|
+
"xlsx_preview.error.description": "Impossible d’afficher un aperçu de cette feuille de calcul.",
|
|
2649
|
+
"xlsx_preview.formula_not_evaluated": "Impossible d’évaluer la formule",
|
|
2650
|
+
"xlsx_preview.sheet_tabs_label": "Feuilles"
|
|
2651
|
+
},
|
|
2652
|
+
"ja-jp": {
|
|
2653
|
+
"common.close": "閉じる",
|
|
2654
|
+
"common.loading": "読み込み中...",
|
|
2655
|
+
"common.next": "次",
|
|
2656
|
+
"common.previous": "前",
|
|
2657
|
+
"file_preview.load_error.description": "プレビュー内容を読み込めませんでした。",
|
|
2658
|
+
"file_preview.load_error.title": "プレビューに失敗しました",
|
|
2659
|
+
"file_preview.loading": "プレビューを読み込み中...",
|
|
2660
|
+
"file_preview.pdf.outline.empty": "このPDFには目次がありません。",
|
|
2661
|
+
"file_preview.pdf.outline.load_error": "目次を読み込めませんでした。",
|
|
2662
|
+
"file_preview.pdf.outline.title": "目次",
|
|
2663
|
+
"file_preview.pdf.page_number": "ページ番号",
|
|
2664
|
+
"file_preview.pdf.too_large.description": "この PDF の一部は大きすぎるため、アプリ内で安全にプレビューできません。",
|
|
2665
|
+
"file_preview.pdf.too_large.title": "この PDF をプレビューできません",
|
|
2666
|
+
"file_preview.too_large.action": "デフォルトのアプリで開く",
|
|
2667
|
+
"file_preview.too_large.description": "ファイルサイズ {{size}} はプレビュー上限の {{limit}} を超えています。",
|
|
2668
|
+
"file_preview.too_large.title": "ファイルが大きすぎてプレビューできません",
|
|
2669
|
+
"file_preview.unsupported.action": "デフォルトのアプリで開く",
|
|
2670
|
+
"file_preview.unsupported.description": "このファイルタイプはまだプレビューできません。",
|
|
2671
|
+
"file_preview.unsupported.title": "プレビューは利用できません",
|
|
2672
|
+
"preview.flip_horizontal": "左右反転",
|
|
2673
|
+
"preview.flip_vertical": "垂直反転",
|
|
2674
|
+
"preview.label": "プレビュー",
|
|
2675
|
+
"preview.reset": "リセット",
|
|
2676
|
+
"preview.rotate_left": "左回転",
|
|
2677
|
+
"preview.rotate_right": "右に回転",
|
|
2678
|
+
"preview.zoom_in": "拡大",
|
|
2679
|
+
"preview.zoom_out": "縮小",
|
|
2680
|
+
"xlsx_preview.chart": "グラフ",
|
|
2681
|
+
"xlsx_preview.chart_unsupported": "このグラフ形式はまだサポートされていません",
|
|
2682
|
+
"xlsx_preview.error.description": "このスプレッドシートをプレビューできませんでした。",
|
|
2683
|
+
"xlsx_preview.formula_not_evaluated": "数式を評価できませんでした",
|
|
2684
|
+
"xlsx_preview.sheet_tabs_label": "シート"
|
|
2685
|
+
},
|
|
2686
|
+
"pt-pt": {
|
|
2687
|
+
"common.close": "Fechar",
|
|
2688
|
+
"common.loading": "A carregar...",
|
|
2689
|
+
"common.next": "Próximo",
|
|
2690
|
+
"common.previous": "Anterior",
|
|
2691
|
+
"file_preview.load_error.description": "O conteúdo de pré-visualização não pôde ser carregado.",
|
|
2692
|
+
"file_preview.load_error.title": "Falha na pré-visualização",
|
|
2693
|
+
"file_preview.loading": "A carregar pré-visualização...",
|
|
2694
|
+
"file_preview.pdf.outline.empty": "Este PDF não tem índice.",
|
|
2695
|
+
"file_preview.pdf.outline.load_error": "Não foi possível carregar o índice.",
|
|
2696
|
+
"file_preview.pdf.outline.title": "Índice",
|
|
2697
|
+
"file_preview.pdf.page_number": "Número da página",
|
|
2698
|
+
"file_preview.pdf.too_large.description": "Parte deste PDF é demasiado grande para uma pré-visualização segura na aplicação.",
|
|
2699
|
+
"file_preview.pdf.too_large.title": "Não é possível pré-visualizar este PDF",
|
|
2700
|
+
"file_preview.too_large.action": "Abrir com aplicação padrão",
|
|
2701
|
+
"file_preview.too_large.description": "O tamanho do ficheiro {{size}} excede o limite de pré-visualização de {{limit}}.",
|
|
2702
|
+
"file_preview.too_large.title": "Ficheiro demasiado grande para pré-visualizar",
|
|
2703
|
+
"file_preview.unsupported.action": "Abrir com aplicação padrão",
|
|
2704
|
+
"file_preview.unsupported.description": "Este tipo de ficheiro ainda não pode ser visualizado.",
|
|
2705
|
+
"file_preview.unsupported.title": "Visualização indisponível",
|
|
2706
|
+
"preview.flip_horizontal": "Virar Horizontalmente",
|
|
2707
|
+
"preview.flip_vertical": "Virar Verticalmente",
|
|
2708
|
+
"preview.label": "Pré-visualização",
|
|
2709
|
+
"preview.reset": "repor",
|
|
2710
|
+
"preview.rotate_left": "Rodar para a Esquerda",
|
|
2711
|
+
"preview.rotate_right": "Rodar para a Direita",
|
|
2712
|
+
"preview.zoom_in": "ampliar",
|
|
2713
|
+
"preview.zoom_out": "reduzir",
|
|
2714
|
+
"xlsx_preview.chart": "Gráfico",
|
|
2715
|
+
"xlsx_preview.chart_unsupported": "Este tipo de gráfico ainda não é suportado",
|
|
2716
|
+
"xlsx_preview.error.description": "Não foi possível pré-visualizar esta folha de cálculo.",
|
|
2717
|
+
"xlsx_preview.formula_not_evaluated": "Não foi possível avaliar a fórmula",
|
|
2718
|
+
"xlsx_preview.sheet_tabs_label": "Folhas"
|
|
2719
|
+
},
|
|
2720
|
+
"ro-ro": {
|
|
2721
|
+
"common.close": "Închide",
|
|
2722
|
+
"common.loading": "Se încarcă...",
|
|
2723
|
+
"common.next": "Următorul",
|
|
2724
|
+
"common.previous": "Anterior",
|
|
2725
|
+
"file_preview.load_error.description": "Conținutul previzualizării nu a putut fi încărcat.",
|
|
2726
|
+
"file_preview.load_error.title": "Previzualizarea a eșuat",
|
|
2727
|
+
"file_preview.loading": "Încărcare previzualizare...",
|
|
2728
|
+
"file_preview.pdf.outline.empty": "Acest PDF nu are cuprins.",
|
|
2729
|
+
"file_preview.pdf.outline.load_error": "Cuprinsul nu a putut fi încărcat.",
|
|
2730
|
+
"file_preview.pdf.outline.title": "Cuprins",
|
|
2731
|
+
"file_preview.pdf.page_number": "Numărul paginii",
|
|
2732
|
+
"file_preview.pdf.too_large.description": "O parte din acest PDF este prea mare pentru a fi previzualizată în siguranță în aplicație.",
|
|
2733
|
+
"file_preview.pdf.too_large.title": "Nu se poate previzualiza acest PDF",
|
|
2734
|
+
"file_preview.too_large.action": "Deschide cu aplicația implicită",
|
|
2735
|
+
"file_preview.too_large.description": "Dimensiunea fișierului {{size}} depășește limita de previzualizare de {{limit}}.",
|
|
2736
|
+
"file_preview.too_large.title": "Fișier prea mare pentru previzualizare",
|
|
2737
|
+
"file_preview.unsupported.action": "Deschide cu aplicația implicită",
|
|
2738
|
+
"file_preview.unsupported.description": "Acest tip de fișier nu poate fi previzualizat încă.",
|
|
2739
|
+
"file_preview.unsupported.title": "Previzualizare indisponibilă",
|
|
2740
|
+
"preview.flip_horizontal": "Întoarce orizontal",
|
|
2741
|
+
"preview.flip_vertical": "Întoarce vertical",
|
|
2742
|
+
"preview.label": "Previzualizare",
|
|
2743
|
+
"preview.reset": "Resetează",
|
|
2744
|
+
"preview.rotate_left": "Rotire la stânga",
|
|
2745
|
+
"preview.rotate_right": "Rotire la dreapta",
|
|
2746
|
+
"preview.zoom_in": "Mărește",
|
|
2747
|
+
"preview.zoom_out": "Micșorează",
|
|
2748
|
+
"xlsx_preview.chart": "Diagramă",
|
|
2749
|
+
"xlsx_preview.chart_unsupported": "Acest tip de diagramă nu este încă acceptat",
|
|
2750
|
+
"xlsx_preview.error.description": "Această foaie de calcul nu a putut fi previzualizată.",
|
|
2751
|
+
"xlsx_preview.formula_not_evaluated": "Formula nu a putut fi evaluată",
|
|
2752
|
+
"xlsx_preview.sheet_tabs_label": "Foi"
|
|
2753
|
+
},
|
|
2754
|
+
"ru-ru": {
|
|
2755
|
+
"common.close": "Закрыть",
|
|
2756
|
+
"common.loading": "Загрузка...",
|
|
2757
|
+
"common.next": "Далее",
|
|
2758
|
+
"common.previous": "Предыдущий",
|
|
2759
|
+
"file_preview.load_error.description": "Не удалось загрузить содержимое предпросмотра.",
|
|
2760
|
+
"file_preview.load_error.title": "Предпросмотр не удался",
|
|
2761
|
+
"file_preview.loading": "Загрузка предварительного просмотра...",
|
|
2762
|
+
"file_preview.pdf.outline.empty": "В этом PDF нет оглавления.",
|
|
2763
|
+
"file_preview.pdf.outline.load_error": "Не удалось загрузить оглавление.",
|
|
2764
|
+
"file_preview.pdf.outline.title": "Оглавление",
|
|
2765
|
+
"file_preview.pdf.page_number": "Номер страницы",
|
|
2766
|
+
"file_preview.pdf.too_large.description": "Часть этого PDF-файла слишком велика для безопасного предварительного просмотра в приложении.",
|
|
2767
|
+
"file_preview.pdf.too_large.title": "Не удалось открыть предпросмотр этого PDF",
|
|
2768
|
+
"file_preview.too_large.action": "Открыть с помощью приложения по умолчанию",
|
|
2769
|
+
"file_preview.too_large.description": "Размер файла {{size}} превышает ограничение предварительного просмотра {{limit}}.",
|
|
2770
|
+
"file_preview.too_large.title": "Файл слишком велик для предварительного просмотра",
|
|
2771
|
+
"file_preview.unsupported.action": "Открыть с помощью приложения по умолчанию",
|
|
2772
|
+
"file_preview.unsupported.description": "Этот тип файла пока нельзя просмотреть.",
|
|
2773
|
+
"file_preview.unsupported.title": "Предварительный просмотр недоступен",
|
|
2774
|
+
"preview.flip_horizontal": "Отразить по горизонтали",
|
|
2775
|
+
"preview.flip_vertical": "Отразить по вертикали",
|
|
2776
|
+
"preview.label": "Предварительный просмотр",
|
|
2777
|
+
"preview.reset": "Сбросить",
|
|
2778
|
+
"preview.rotate_left": "Повернуть влево",
|
|
2779
|
+
"preview.rotate_right": "Повернуть вправо",
|
|
2780
|
+
"preview.zoom_in": "Увеличить",
|
|
2781
|
+
"preview.zoom_out": "Уменьшить",
|
|
2782
|
+
"xlsx_preview.chart": "Диаграмма",
|
|
2783
|
+
"xlsx_preview.chart_unsupported": "Этот тип диаграммы пока не поддерживается",
|
|
2784
|
+
"xlsx_preview.error.description": "Не удалось открыть предварительный просмотр этой таблицы.",
|
|
2785
|
+
"xlsx_preview.formula_not_evaluated": "Не удалось вычислить формулу",
|
|
2786
|
+
"xlsx_preview.sheet_tabs_label": "Листы"
|
|
2787
|
+
},
|
|
2788
|
+
"tr-tr": {
|
|
2789
|
+
"common.close": "Kapat",
|
|
2790
|
+
"common.loading": "Yükleniyor...",
|
|
2791
|
+
"common.next": "İleri",
|
|
2792
|
+
"common.previous": "Önceki",
|
|
2793
|
+
"file_preview.load_error.description": "Önizleme içeriği yüklenemedi.",
|
|
2794
|
+
"file_preview.load_error.title": "Önizleme başarısız oldu",
|
|
2795
|
+
"file_preview.loading": "Önizleme yükleniyor...",
|
|
2796
|
+
"file_preview.pdf.outline.empty": "Bu PDF'de içindekiler tablosu yok.",
|
|
2797
|
+
"file_preview.pdf.outline.load_error": "İçindekiler tablosu yüklenemedi.",
|
|
2798
|
+
"file_preview.pdf.outline.title": "İçindekiler",
|
|
2799
|
+
"file_preview.pdf.page_number": "Sayfa numarası",
|
|
2800
|
+
"file_preview.pdf.too_large.description": "Bu PDF'nin bir bölümü uygulamada güvenli biçimde önizlenemeyecek kadar büyük.",
|
|
2801
|
+
"file_preview.pdf.too_large.title": "Bu PDF önizlenemiyor",
|
|
2802
|
+
"file_preview.too_large.action": "Varsayılan uygulamayla aç",
|
|
2803
|
+
"file_preview.too_large.description": "{{size}} dosya boyutu, {{limit}} önizleme sınırını aşıyor.",
|
|
2804
|
+
"file_preview.too_large.title": "Dosya önizlenemeyecek kadar büyük",
|
|
2805
|
+
"file_preview.unsupported.action": "Varsayılan uygulamayla aç",
|
|
2806
|
+
"file_preview.unsupported.description": "Bu dosya türü henüz önizlenemiyor.",
|
|
2807
|
+
"file_preview.unsupported.title": "Önizleme kullanılamıyor",
|
|
2808
|
+
"preview.flip_horizontal": "Yatay Çevir",
|
|
2809
|
+
"preview.flip_vertical": "Dikey Çevir",
|
|
2810
|
+
"preview.label": "Önizleme",
|
|
2811
|
+
"preview.reset": "Sıfırla",
|
|
2812
|
+
"preview.rotate_left": "Sola Döndür",
|
|
2813
|
+
"preview.rotate_right": "Sağa Döndür",
|
|
2814
|
+
"preview.zoom_in": "Yakınlaştır",
|
|
2815
|
+
"preview.zoom_out": "Uzaklaştır",
|
|
2816
|
+
"xlsx_preview.chart": "Grafik",
|
|
2817
|
+
"xlsx_preview.chart_unsupported": "Bu grafik türü henüz desteklenmiyor",
|
|
2818
|
+
"xlsx_preview.error.description": "Bu elektronik tablo önizlenemedi.",
|
|
2819
|
+
"xlsx_preview.formula_not_evaluated": "Formül değerlendirilemedi",
|
|
2820
|
+
"xlsx_preview.sheet_tabs_label": "Sayfalar"
|
|
2821
|
+
},
|
|
2822
|
+
"vi-vn": {
|
|
2823
|
+
"common.close": "Đóng",
|
|
2824
|
+
"common.loading": "Đang tải...",
|
|
2825
|
+
"common.next": "Tiếp",
|
|
2826
|
+
"common.previous": "Trước",
|
|
2827
|
+
"file_preview.load_error.description": "Không thể tải nội dung xem trước.",
|
|
2828
|
+
"file_preview.load_error.title": "Xem trước thất bại",
|
|
2829
|
+
"file_preview.loading": "Đang tải bản xem trước...",
|
|
2830
|
+
"file_preview.pdf.outline.empty": "PDF này không có mục lục.",
|
|
2831
|
+
"file_preview.pdf.outline.load_error": "Không thể tải mục lục.",
|
|
2832
|
+
"file_preview.pdf.outline.title": "Mục lục",
|
|
2833
|
+
"file_preview.pdf.page_number": "Số trang",
|
|
2834
|
+
"file_preview.pdf.too_large.description": "Một phần của tệp PDF này quá lớn để xem trước an toàn trong ứng dụng.",
|
|
2835
|
+
"file_preview.pdf.too_large.title": "Không thể xem trước tệp PDF này",
|
|
2836
|
+
"file_preview.too_large.action": "Mở bằng ứng dụng mặc định",
|
|
2837
|
+
"file_preview.too_large.description": "Kích thước tệp {{size}} vượt quá giới hạn xem trước {{limit}}.",
|
|
2838
|
+
"file_preview.too_large.title": "Tệp quá lớn để xem trước",
|
|
2839
|
+
"file_preview.unsupported.action": "Mở bằng ứng dụng mặc định",
|
|
2840
|
+
"file_preview.unsupported.description": "Loại tệp này chưa thể xem trước được.",
|
|
2841
|
+
"file_preview.unsupported.title": "Xem trước không khả dụng",
|
|
2842
|
+
"preview.flip_horizontal": "Lật ngang",
|
|
2843
|
+
"preview.flip_vertical": "Lật dọc",
|
|
2844
|
+
"preview.label": "Xem trước",
|
|
2845
|
+
"preview.reset": "Đặt lại",
|
|
2846
|
+
"preview.rotate_left": "Xoay Trái",
|
|
2847
|
+
"preview.rotate_right": "Xoay phải",
|
|
2848
|
+
"preview.zoom_in": "Phóng to",
|
|
2849
|
+
"preview.zoom_out": "Thu nhỏ",
|
|
2850
|
+
"xlsx_preview.chart": "Biểu đồ",
|
|
2851
|
+
"xlsx_preview.chart_unsupported": "Loại biểu đồ này chưa được hỗ trợ",
|
|
2852
|
+
"xlsx_preview.error.description": "Không thể xem trước bảng tính này.",
|
|
2853
|
+
"xlsx_preview.formula_not_evaluated": "Không thể tính giá trị công thức",
|
|
2854
|
+
"xlsx_preview.sheet_tabs_label": "Trang tính"
|
|
2855
|
+
},
|
|
2856
|
+
"zh-cn": {
|
|
2857
|
+
"common.close": "关闭",
|
|
2858
|
+
"common.loading": "加载中...",
|
|
2859
|
+
"common.next": "下一页",
|
|
2860
|
+
"common.previous": "上一页",
|
|
2861
|
+
"file_preview.load_error.description": "无法加载此文件的预览内容。",
|
|
2862
|
+
"file_preview.load_error.title": "预览失败",
|
|
2863
|
+
"file_preview.loading": "正在加载预览...",
|
|
2864
|
+
"file_preview.pdf.outline.empty": "此 PDF 没有目录。",
|
|
2865
|
+
"file_preview.pdf.outline.load_error": "无法加载目录。",
|
|
2866
|
+
"file_preview.pdf.outline.title": "目录",
|
|
2867
|
+
"file_preview.pdf.page_number": "页码",
|
|
2868
|
+
"file_preview.pdf.too_large.description": "该 PDF 部分内容过大,无法安全地在应用内预览。",
|
|
2869
|
+
"file_preview.pdf.too_large.title": "无法预览此 PDF",
|
|
2870
|
+
"file_preview.too_large.action": "用默认应用打开",
|
|
2871
|
+
"file_preview.too_large.description": "文件大小 {{size}} 超过 {{limit}} 的预览大小限制。",
|
|
2872
|
+
"file_preview.too_large.title": "文件过大,无法预览",
|
|
2873
|
+
"file_preview.unsupported.action": "用默认应用打开",
|
|
2874
|
+
"file_preview.unsupported.description": "此文件类型暂不支持预览。",
|
|
2875
|
+
"file_preview.unsupported.title": "暂不支持预览",
|
|
2876
|
+
"preview.flip_horizontal": "水平翻转",
|
|
2877
|
+
"preview.flip_vertical": "垂直翻转",
|
|
2878
|
+
"preview.label": "预览",
|
|
2879
|
+
"preview.reset": "重置",
|
|
2880
|
+
"preview.rotate_left": "向左旋转",
|
|
2881
|
+
"preview.rotate_right": "向右旋转",
|
|
2882
|
+
"preview.zoom_in": "放大",
|
|
2883
|
+
"preview.zoom_out": "缩小",
|
|
2884
|
+
"xlsx_preview.chart": "图表",
|
|
2885
|
+
"xlsx_preview.chart_unsupported": "暂不支持此图表类型",
|
|
2886
|
+
"xlsx_preview.error.description": "无法预览此电子表格。",
|
|
2887
|
+
"xlsx_preview.formula_not_evaluated": "公式无法求值",
|
|
2888
|
+
"xlsx_preview.sheet_tabs_label": "工作表"
|
|
2889
|
+
},
|
|
2890
|
+
"zh-tw": {
|
|
2891
|
+
"common.close": "關閉",
|
|
2892
|
+
"common.loading": "載入中...",
|
|
2893
|
+
"common.next": "下一頁",
|
|
2894
|
+
"common.previous": "上一頁",
|
|
2895
|
+
"file_preview.load_error.description": "無法載入預覽內容。",
|
|
2896
|
+
"file_preview.load_error.title": "預覽失敗",
|
|
2897
|
+
"file_preview.loading": "載入預覽中...",
|
|
2898
|
+
"file_preview.pdf.outline.empty": "此 PDF 沒有目錄。",
|
|
2899
|
+
"file_preview.pdf.outline.load_error": "無法載入目錄。",
|
|
2900
|
+
"file_preview.pdf.outline.title": "目錄",
|
|
2901
|
+
"file_preview.pdf.page_number": "頁碼",
|
|
2902
|
+
"file_preview.pdf.too_large.description": "這份 PDF 的部分內容過大,無法在應用程式中安全預覽。",
|
|
2903
|
+
"file_preview.pdf.too_large.title": "無法預覽此 PDF",
|
|
2904
|
+
"file_preview.too_large.action": "使用預設應用程式開啟",
|
|
2905
|
+
"file_preview.too_large.description": "檔案大小 {{size}} 超過 {{limit}} 的預覽大小限制。",
|
|
2906
|
+
"file_preview.too_large.title": "檔案過大,無法預覽",
|
|
2907
|
+
"file_preview.unsupported.action": "使用預設應用程式開啟",
|
|
2908
|
+
"file_preview.unsupported.description": "此檔案類型尚無法預覽。",
|
|
2909
|
+
"file_preview.unsupported.title": "無法預覽",
|
|
2910
|
+
"preview.flip_horizontal": "水平翻轉",
|
|
2911
|
+
"preview.flip_vertical": "垂直翻轉",
|
|
2912
|
+
"preview.label": "預覽",
|
|
2913
|
+
"preview.reset": "重設",
|
|
2914
|
+
"preview.rotate_left": "向左旋轉",
|
|
2915
|
+
"preview.rotate_right": "向右旋轉",
|
|
2916
|
+
"preview.zoom_in": "放大",
|
|
2917
|
+
"preview.zoom_out": "縮小",
|
|
2918
|
+
"xlsx_preview.chart": "圖表",
|
|
2919
|
+
"xlsx_preview.chart_unsupported": "暫不支援此圖表類型",
|
|
2920
|
+
"xlsx_preview.error.description": "無法預覽此試算表。",
|
|
2921
|
+
"xlsx_preview.formula_not_evaluated": "公式無法求值",
|
|
2922
|
+
"xlsx_preview.sheet_tabs_label": "工作表"
|
|
2923
|
+
}
|
|
2924
|
+
};
|
|
2925
|
+
function createPreviewI18n(locale) {
|
|
2926
|
+
const instance = createInstance();
|
|
2927
|
+
instance.init({
|
|
2928
|
+
lng: locale.toLowerCase(),
|
|
2929
|
+
fallbackLng: "en-us",
|
|
2930
|
+
supportedLngs: Object.keys(catalogs),
|
|
2931
|
+
lowerCaseLng: true,
|
|
2932
|
+
load: "currentOnly",
|
|
2933
|
+
initImmediate: false,
|
|
2934
|
+
defaultNS: "file-preview",
|
|
2935
|
+
resources: Object.fromEntries(Object.entries(catalogs).map(([language, catalog]) => [language, { "file-preview": catalog }])),
|
|
2936
|
+
interpolation: { escapeValue: false }
|
|
2937
|
+
});
|
|
2938
|
+
return instance;
|
|
2939
|
+
}
|
|
2940
|
+
//#endregion
|
|
2941
|
+
//#region src/Preview.tsx
|
|
2942
|
+
function PreviewState({ kind }) {
|
|
2943
|
+
const { t } = useTranslation();
|
|
2944
|
+
const { onRequestOpen } = usePreviewHost();
|
|
2945
|
+
const canOpen = kind === "unsupported" && onRequestOpen !== void 0;
|
|
2946
|
+
return /* @__PURE__ */ jsx(FilePreviewLayout.Frame, { children: /* @__PURE__ */ jsx(FilePreviewLayout.Content, { children: kind === "loading" ? /* @__PURE__ */ jsxs("div", {
|
|
2947
|
+
role: "status",
|
|
2948
|
+
className: "flex h-full items-center justify-center gap-2 text-sm text-muted-foreground",
|
|
2949
|
+
children: [/* @__PURE__ */ jsx(LoaderCircle, {
|
|
2950
|
+
className: "size-4 animate-spin",
|
|
2951
|
+
"aria-hidden": true
|
|
2952
|
+
}), /* @__PURE__ */ jsx("span", { children: t("file_preview.loading") })]
|
|
2953
|
+
}) : /* @__PURE__ */ jsx(EmptyState, {
|
|
2954
|
+
icon: kind === "unsupported" ? FileQuestionMark : FileWarning,
|
|
2955
|
+
title: t(kind === "unsupported" ? "file_preview.unsupported.title" : "file_preview.load_error.title"),
|
|
2956
|
+
description: t(kind === "unsupported" ? "file_preview.unsupported.description" : "file_preview.load_error.description"),
|
|
2957
|
+
actionLabel: canOpen ? t("file_preview.unsupported.action") : void 0,
|
|
2958
|
+
onAction: canOpen ? () => onRequestOpen("unsupported") : void 0,
|
|
2959
|
+
className: "h-full"
|
|
2960
|
+
}) }) });
|
|
2961
|
+
}
|
|
2962
|
+
function Preview({ locale = "en-us", ...props }) {
|
|
2963
|
+
const i18n = useMemo(() => createPreviewI18n(locale), [locale]);
|
|
2964
|
+
return /* @__PURE__ */ jsx(I18nextProvider, {
|
|
2965
|
+
i18n,
|
|
2966
|
+
children: /* @__PURE__ */ jsx(PreviewSession, { ...props })
|
|
2967
|
+
});
|
|
2968
|
+
}
|
|
2969
|
+
function PreviewSession({ source, header, className, style, refreshKey = 0, resources, options, onSelection, onDiagnostic, onError, onRequestOpen }) {
|
|
2970
|
+
const [root, setRoot] = useState(null);
|
|
2971
|
+
const [session, setSession] = useState(null);
|
|
2972
|
+
const [failure, setFailure] = useState(null);
|
|
2973
|
+
const closeRef = useRef(void 0);
|
|
2974
|
+
const hasFailedRef = useRef(false);
|
|
2975
|
+
const callbacks = useRef({
|
|
2976
|
+
onSelection,
|
|
2977
|
+
onDiagnostic,
|
|
2978
|
+
onError,
|
|
2979
|
+
onRequestOpen
|
|
2980
|
+
});
|
|
2981
|
+
callbacks.current = {
|
|
2982
|
+
onSelection,
|
|
2983
|
+
onDiagnostic,
|
|
2984
|
+
onError,
|
|
2985
|
+
onRequestOpen
|
|
2986
|
+
};
|
|
2987
|
+
const failDocument = useCallback((error) => {
|
|
2988
|
+
if (hasFailedRef.current) return;
|
|
2989
|
+
hasFailedRef.current = true;
|
|
2990
|
+
closeRef.current?.();
|
|
2991
|
+
const normalized = error instanceof PreviewError ? error : new PreviewError("load_error", "Failed to load preview", { cause: error });
|
|
2992
|
+
callbacks.current.onDiagnostic?.({
|
|
2993
|
+
level: normalized.code === "too_large" ? "warn" : "error",
|
|
2994
|
+
code: normalized.code,
|
|
2995
|
+
context: "Preview",
|
|
2996
|
+
message: normalized.message,
|
|
2997
|
+
detail: normalized
|
|
2998
|
+
});
|
|
2999
|
+
callbacks.current.onError?.(normalized);
|
|
3000
|
+
}, []);
|
|
3001
|
+
const reportSelection = useCallback((selection) => callbacks.current.onSelection?.(selection), []);
|
|
3002
|
+
const reportDiagnostic = useCallback((diagnostic) => callbacks.current.onDiagnostic?.(diagnostic), []);
|
|
3003
|
+
const requestOpen = useCallback((reason) => callbacks.current.onRequestOpen?.(reason), []);
|
|
3004
|
+
const hasOpenAction = onRequestOpen !== void 0;
|
|
3005
|
+
const host = useMemo(() => ({
|
|
3006
|
+
root,
|
|
3007
|
+
resources,
|
|
3008
|
+
options,
|
|
3009
|
+
onDiagnostic: reportDiagnostic,
|
|
3010
|
+
onRequestOpen: hasOpenAction ? requestOpen : void 0,
|
|
3011
|
+
failDocument
|
|
3012
|
+
}), [
|
|
3013
|
+
root,
|
|
3014
|
+
resources,
|
|
3015
|
+
options,
|
|
3016
|
+
reportDiagnostic,
|
|
3017
|
+
requestOpen,
|
|
3018
|
+
hasOpenAction,
|
|
3019
|
+
failDocument
|
|
3020
|
+
]);
|
|
3021
|
+
const plugin = useMemo(() => resolvePreviewPlugin(source.name, source.mediaType), [source.name, source.mediaType]);
|
|
3022
|
+
const Plugin = useMemo(() => plugin ? lazy(plugin.load) : null, [plugin]);
|
|
3023
|
+
useEffect(() => {
|
|
3024
|
+
setSession(null);
|
|
3025
|
+
setFailure(null);
|
|
3026
|
+
hasFailedRef.current = false;
|
|
3027
|
+
if (!plugin) return;
|
|
3028
|
+
const controller = new AbortController();
|
|
3029
|
+
let opened = null;
|
|
3030
|
+
let closed = false;
|
|
3031
|
+
const close = () => {
|
|
3032
|
+
if (!opened || closed) return;
|
|
3033
|
+
closed = true;
|
|
3034
|
+
opened.close().catch((error) => callbacks.current.onDiagnostic?.({
|
|
3035
|
+
level: "warn",
|
|
3036
|
+
context: "Preview",
|
|
3037
|
+
message: "Failed to close preview source",
|
|
3038
|
+
detail: error
|
|
3039
|
+
}));
|
|
3040
|
+
};
|
|
3041
|
+
closeRef.current = close;
|
|
3042
|
+
(async () => {
|
|
3043
|
+
try {
|
|
3044
|
+
opened = await source.open(controller.signal);
|
|
3045
|
+
if (controller.signal.aborted) {
|
|
3046
|
+
close();
|
|
3047
|
+
return;
|
|
3048
|
+
}
|
|
3049
|
+
assertPreviewRange(opened.size, 0, opened.size);
|
|
3050
|
+
setSession({
|
|
3051
|
+
source,
|
|
3052
|
+
refreshKey,
|
|
3053
|
+
document: opened
|
|
3054
|
+
});
|
|
3055
|
+
} catch (error) {
|
|
3056
|
+
close();
|
|
3057
|
+
if (controller.signal.aborted) return;
|
|
3058
|
+
setFailure({
|
|
3059
|
+
source,
|
|
3060
|
+
refreshKey
|
|
3061
|
+
});
|
|
3062
|
+
failDocument(error);
|
|
3063
|
+
}
|
|
3064
|
+
})();
|
|
3065
|
+
return () => {
|
|
3066
|
+
controller.abort();
|
|
3067
|
+
close();
|
|
3068
|
+
if (closeRef.current === close) closeRef.current = void 0;
|
|
3069
|
+
};
|
|
3070
|
+
}, [
|
|
3071
|
+
source,
|
|
3072
|
+
refreshKey,
|
|
3073
|
+
plugin,
|
|
3074
|
+
failDocument
|
|
3075
|
+
]);
|
|
3076
|
+
const ready = session?.source === source && session.refreshKey === refreshKey ? session : null;
|
|
3077
|
+
const failed = failure?.source === source && failure.refreshKey === refreshKey;
|
|
3078
|
+
const content = !Plugin ? /* @__PURE__ */ jsx(PreviewState, { kind: "unsupported" }) : failed ? /* @__PURE__ */ jsx(PreviewState, { kind: "error" }) : !ready ? /* @__PURE__ */ jsx(PreviewState, { kind: "loading" }) : /* @__PURE__ */ jsx(m, {
|
|
3079
|
+
resetKeys: [ready.document],
|
|
3080
|
+
fallback: /* @__PURE__ */ jsx(PreviewState, { kind: "error" }),
|
|
3081
|
+
onError: failDocument,
|
|
3082
|
+
children: /* @__PURE__ */ jsx(Suspense, {
|
|
3083
|
+
fallback: /* @__PURE__ */ jsx(PreviewState, { kind: "loading" }),
|
|
3084
|
+
children: /* @__PURE__ */ jsx(Plugin, {
|
|
3085
|
+
sourceId: source.id,
|
|
3086
|
+
fileName: source.name,
|
|
3087
|
+
mediaType: source.mediaType,
|
|
3088
|
+
document: ready.document,
|
|
3089
|
+
onSelection: onSelection ? reportSelection : void 0
|
|
3090
|
+
}, `${source.id}:${refreshKey}:${ready.document.revision}`)
|
|
3091
|
+
})
|
|
3092
|
+
}, `${source.id}:${refreshKey}:${ready.document.revision}`);
|
|
3093
|
+
return /* @__PURE__ */ jsx("div", {
|
|
3094
|
+
ref: setRoot,
|
|
3095
|
+
"data-file-preview-root": "",
|
|
3096
|
+
className: cn("file-preview-root relative h-full min-h-0 w-full", className),
|
|
3097
|
+
style,
|
|
3098
|
+
children: /* @__PURE__ */ jsx(PortalContainerProvider, {
|
|
3099
|
+
container: root,
|
|
3100
|
+
children: /* @__PURE__ */ jsx(DialogPortalContainerProvider, {
|
|
3101
|
+
container: root,
|
|
3102
|
+
children: /* @__PURE__ */ jsx(PreviewHostContext, {
|
|
3103
|
+
value: host,
|
|
3104
|
+
children: /* @__PURE__ */ jsx(FilePreviewLayout.Shell, {
|
|
3105
|
+
header,
|
|
3106
|
+
children: content
|
|
3107
|
+
})
|
|
3108
|
+
})
|
|
3109
|
+
})
|
|
3110
|
+
})
|
|
3111
|
+
});
|
|
3112
|
+
}
|
|
3113
|
+
//#endregion
|
|
3114
|
+
export { FilePreviewLayout, FilePreviewToolbar, FilePreviewToolbarButton, FilePreviewToolbarPortalHost, FilePreviewToolbarPortalProvider, Preview, canSelectPreview, previewFormats, supportsPreview };
|