@churchapps/apphelper 0.3.23 → 0.3.25
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/dist/helpers/FileHelper.d.ts +1 -1
- package/dist/helpers/FileHelper.d.ts.map +1 -1
- package/dist/helpers/FileHelper.js +2 -6
- package/dist/helpers/FileHelper.js.map +1 -1
- package/dist/helpers/Locale.d.ts +3 -3
- package/dist/helpers/Locale.d.ts.map +1 -1
- package/dist/helpers/Locale.js +56 -34
- package/dist/helpers/Locale.js.map +1 -1
- package/package.json +8 -3
- package/src/helpers/FileHelper.ts +3 -6
- package/src/helpers/Locale.ts +98 -56
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export declare class FileHelper {
|
|
2
|
-
static postPresignedFile: (presigned: any, uploadedFile: File, progressCallback: (percent: number) => void
|
|
2
|
+
static postPresignedFile: (presigned: any, uploadedFile: File, progressCallback: (percent: number) => void) => Promise<import("axios").AxiosResponse<any, any>>;
|
|
3
3
|
static dataURLtoBlob(dataurl: string): Blob;
|
|
4
4
|
}
|
|
5
5
|
//# sourceMappingURL=FileHelper.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FileHelper.d.ts","sourceRoot":"","sources":["../../src/helpers/FileHelper.ts"],"names":[],"mappings":"AAEA,qBAAa,UAAU;
|
|
1
|
+
{"version":3,"file":"FileHelper.d.ts","sourceRoot":"","sources":["../../src/helpers/FileHelper.ts"],"names":[],"mappings":"AAEA,qBAAa,UAAU;IAErB,MAAM,CAAC,iBAAiB,cAAe,GAAG,gBAAgB,IAAI,8BAA8B,MAAM,KAAK,IAAI,sDAgBzG;IAEF,MAAM,CAAC,aAAa,CAAC,OAAO,EAAE,MAAM;CAQrC"}
|
|
@@ -15,8 +15,7 @@ class FileHelper {
|
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
exports.FileHelper = FileHelper;
|
|
18
|
-
FileHelper.postPresignedFile = (presigned, uploadedFile, progressCallback
|
|
19
|
-
const axiosToUse = axiosInstance || axios_1.default;
|
|
18
|
+
FileHelper.postPresignedFile = (presigned, uploadedFile, progressCallback) => {
|
|
20
19
|
const formData = new FormData();
|
|
21
20
|
//formData.append("key", presigned.key); //no longer needed with new aws sdk
|
|
22
21
|
formData.append("acl", "public-read");
|
|
@@ -30,9 +29,6 @@ FileHelper.postPresignedFile = (presigned, uploadedFile, progressCallback, axios
|
|
|
30
29
|
progressCallback(Math.round((100 * data.loaded) / data.total));
|
|
31
30
|
}
|
|
32
31
|
};
|
|
33
|
-
|
|
34
|
-
console.log("axios: ", axiosToUse);
|
|
35
|
-
console.log("axios tyeof: ", typeof axiosToUse.post);
|
|
36
|
-
return axiosToUse.post(presigned.url, formData, axiosConfig);
|
|
32
|
+
return axios_1.default.post(presigned.url, formData, axiosConfig);
|
|
37
33
|
};
|
|
38
34
|
//# sourceMappingURL=FileHelper.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FileHelper.js","sourceRoot":"","sources":["../../src/helpers/FileHelper.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAE1B,MAAa,UAAU;
|
|
1
|
+
{"version":3,"file":"FileHelper.js","sourceRoot":"","sources":["../../src/helpers/FileHelper.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAE1B,MAAa,UAAU;IAoBrB,MAAM,CAAC,aAAa,CAAC,OAAe;QAClC,IAAI,GAAG,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,IAAI,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,EAC7D,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,KAAK,GAAG,IAAI,UAAU,CAAC,CAAC,CAAC,CAAC;QAClE,OAAO,CAAC,EAAE,EAAE;YACV,KAAK,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;SAC/B;QACD,OAAO,IAAI,IAAI,CAAC,CAAC,KAAK,CAAC,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;IAC3C,CAAC;;AA3BH,gCA4BC;AA1BQ,4BAAiB,GAAG,CAAC,SAAc,EAAE,YAAkB,EAAE,gBAA2C,EAAE,EAAE;IAC7G,MAAM,QAAQ,GAAG,IAAI,QAAQ,EAAE,CAAC;IAChC,4EAA4E;IAC5E,QAAQ,CAAC,MAAM,CAAC,KAAK,EAAE,aAAa,CAAC,CAAC;IACtC,QAAQ,CAAC,MAAM,CAAC,cAAc,EAAE,YAAY,CAAC,IAAI,CAAC,CAAC;IACnD,KAAK,MAAM,QAAQ,IAAI,SAAS,CAAC,MAAM;QAAE,QAAQ,CAAC,MAAM,CAAC,QAAQ,EAAE,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC;IAC/F,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;IAEtC,MAAM,WAAW,GAAG;QAClB,OAAO,EAAE,EAAE,cAAc,EAAE,qBAAqB,EAAE;QAClD,gBAAgB,EAAE,CAAC,IAAS,EAAE,EAAE;YAC9B,gBAAgB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;QACjE,CAAC;KACF,CAAC;IAEF,OAAO,eAAK,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE,QAAQ,EAAE,WAAW,CAAC,CAAC;AAC1D,CAAC,CAAC"}
|
package/dist/helpers/Locale.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
export declare class Locale {
|
|
2
|
-
private static supportedLanguages;
|
|
3
|
-
private static extraCodes;
|
|
4
|
-
private static keys;
|
|
2
|
+
private static readonly supportedLanguages;
|
|
3
|
+
private static readonly extraCodes;
|
|
5
4
|
static init: (backends: string[]) => Promise<void>;
|
|
6
5
|
private static deepMerge;
|
|
7
6
|
private static isObject;
|
|
7
|
+
static t(key: string, options?: Record<string, unknown>): string;
|
|
8
8
|
static label(key: string): string;
|
|
9
9
|
}
|
|
10
10
|
//# sourceMappingURL=Locale.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Locale.d.ts","sourceRoot":"","sources":["../../src/helpers/Locale.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Locale.d.ts","sourceRoot":"","sources":["../../src/helpers/Locale.ts"],"names":[],"mappings":"AAgBA,qBAAa,MAAM;IAClB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,kBAAkB,CAaxC;IACF,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,UAAU,CAA4C;IAE9E,MAAM,CAAC,IAAI,aAAoB,MAAM,EAAE,KAAG,QAAQ,IAAI,CAAC,CA4CrD;IAEF,OAAO,CAAC,MAAM,CAAC,SAAS;IAgBxB,OAAO,CAAC,MAAM,CAAC,QAAQ;IAKvB,MAAM,CAAC,CAAC,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM;IAKhE,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM;CAGjC"}
|
package/dist/helpers/Locale.js
CHANGED
|
@@ -1,11 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
import i18n from 'i18next';
|
|
4
|
-
import { initReactI18next } from 'react-i18next';
|
|
5
|
-
import LanguageDetector from 'i18next-browser-languagedetector';
|
|
6
|
-
import Backend from 'i18next-chained-backend';
|
|
7
|
-
import HttpBackend from 'i18next-http-backend';
|
|
8
|
-
*/
|
|
9
2
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
10
3
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
11
4
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -15,9 +8,16 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
15
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
16
9
|
});
|
|
17
10
|
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
18
14
|
var _a;
|
|
19
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
16
|
exports.Locale = void 0;
|
|
17
|
+
const i18next_1 = __importDefault(require("i18next"));
|
|
18
|
+
const react_i18next_1 = require("react-i18next");
|
|
19
|
+
const i18next_browser_languagedetector_1 = __importDefault(require("i18next-browser-languagedetector"));
|
|
20
|
+
const i18next_chained_backend_1 = __importDefault(require("i18next-chained-backend"));
|
|
21
21
|
class Locale {
|
|
22
22
|
static deepMerge(target, source) {
|
|
23
23
|
for (const key in source) {
|
|
@@ -32,46 +32,68 @@ class Locale {
|
|
|
32
32
|
return target;
|
|
33
33
|
}
|
|
34
34
|
static isObject(obj) {
|
|
35
|
-
return obj && typeof obj ===
|
|
35
|
+
return obj !== null && typeof obj === "object" && !Array.isArray(obj);
|
|
36
|
+
}
|
|
37
|
+
// New helper method that uses i18n
|
|
38
|
+
static t(key, options) {
|
|
39
|
+
return i18next_1.default.t(key, options);
|
|
36
40
|
}
|
|
41
|
+
// Keep the old method for backward compatibility
|
|
37
42
|
static label(key) {
|
|
38
|
-
|
|
39
|
-
let result = key;
|
|
40
|
-
let obj = this.keys;
|
|
41
|
-
for (let part of parts) {
|
|
42
|
-
if (obj[part]) {
|
|
43
|
-
obj = obj[part];
|
|
44
|
-
result = obj;
|
|
45
|
-
}
|
|
46
|
-
else {
|
|
47
|
-
return key;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
return result;
|
|
43
|
+
return this.t(key);
|
|
51
44
|
}
|
|
52
45
|
}
|
|
53
46
|
exports.Locale = Locale;
|
|
54
47
|
_a = Locale;
|
|
55
|
-
Locale.supportedLanguages = [
|
|
48
|
+
Locale.supportedLanguages = [
|
|
49
|
+
"de",
|
|
50
|
+
"en",
|
|
51
|
+
"es",
|
|
52
|
+
"fr",
|
|
53
|
+
"hi",
|
|
54
|
+
"it",
|
|
55
|
+
"ko",
|
|
56
|
+
"no",
|
|
57
|
+
"pt",
|
|
58
|
+
"ru",
|
|
59
|
+
"tl",
|
|
60
|
+
"zh",
|
|
61
|
+
];
|
|
56
62
|
Locale.extraCodes = { no: ["nb", "nn"] };
|
|
57
|
-
Locale.keys = {};
|
|
58
63
|
Locale.init = (backends) => __awaiter(void 0, void 0, void 0, function* () {
|
|
64
|
+
const resources = {};
|
|
59
65
|
let langs = ["en"];
|
|
60
66
|
if (typeof navigator !== "undefined") {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
const notSupported = _a.supportedLanguages.indexOf(
|
|
64
|
-
langs =
|
|
67
|
+
const browserLang = navigator.language.split("-")[0];
|
|
68
|
+
const mappedLang = Object.keys(_a.extraCodes).find((code) => _a.extraCodes[code].includes(browserLang)) || browserLang;
|
|
69
|
+
const notSupported = _a.supportedLanguages.indexOf(mappedLang) === -1;
|
|
70
|
+
langs = mappedLang === "en" || notSupported ? ["en"] : ["en", mappedLang];
|
|
65
71
|
}
|
|
66
|
-
|
|
67
|
-
for (
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
72
|
+
// Load translations for each language
|
|
73
|
+
for (const lang of langs) {
|
|
74
|
+
resources[lang] = { translation: {} };
|
|
75
|
+
for (const backend of backends) {
|
|
76
|
+
const url = backend.replace("{{lng}}", lang);
|
|
71
77
|
const data = yield fetch(url).then((response) => response.json());
|
|
72
|
-
|
|
78
|
+
resources[lang].translation = _a.deepMerge(resources[lang].translation, data);
|
|
73
79
|
}
|
|
74
80
|
}
|
|
75
|
-
|
|
81
|
+
// Initialize i18n
|
|
82
|
+
yield i18next_1.default
|
|
83
|
+
.use(i18next_chained_backend_1.default)
|
|
84
|
+
.use(i18next_browser_languagedetector_1.default)
|
|
85
|
+
.use(react_i18next_1.initReactI18next)
|
|
86
|
+
.init({
|
|
87
|
+
resources,
|
|
88
|
+
fallbackLng: "en",
|
|
89
|
+
debug: process.env.NODE_ENV === "development",
|
|
90
|
+
interpolation: {
|
|
91
|
+
escapeValue: false,
|
|
92
|
+
},
|
|
93
|
+
detection: {
|
|
94
|
+
order: ["navigator"],
|
|
95
|
+
caches: ["localStorage"],
|
|
96
|
+
},
|
|
97
|
+
});
|
|
76
98
|
});
|
|
77
99
|
//# sourceMappingURL=Locale.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Locale.js","sourceRoot":"","sources":["../../src/helpers/Locale.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Locale.js","sourceRoot":"","sources":["../../src/helpers/Locale.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,sDAA2B;AAC3B,iDAAiD;AACjD,wGAAgE;AAChE,sFAA8C;AAa9C,MAAa,MAAM;IA+DV,MAAM,CAAC,SAAS,CACvB,MAA+B,EAC/B,MAA+B;QAE/B,KAAK,MAAM,GAAG,IAAI,MAAM,EAAE;YACzB,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE;gBAC/B,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC;oBAAE,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,EAAE,CAAC,GAAG,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;gBACvD,IAAI,CAAC,SAAS,CACb,MAAM,CAAC,GAAG,CAA4B,EACtC,MAAM,CAAC,GAAG,CAA4B,CACtC,CAAC;aACF;;gBAAM,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,EAAE,CAAC,GAAG,CAAC,EAAE,M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;AACL,CAAC,CAAA,AA5CU,CA4CT"}
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@churchapps/apphelper",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.25",
|
|
4
4
|
"description": "Library of helper functions for React and NextJS ChurchApps",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
|
-
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
9
9
|
"clean": "rimraf dist",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"copy-assets": "npm-run-all copy-css copy-icons copy-emojis copy-languages",
|
|
15
15
|
"link": "link",
|
|
16
16
|
"tsc": "tsc",
|
|
17
|
-
|
|
17
|
+
"prepare": "npm run build",
|
|
18
18
|
"build": "npm-run-all clean tsc copy-assets",
|
|
19
19
|
"updateLink": "npm-run-all clean tsc && npm rm @churchapps/apphelper -g && npm link"
|
|
20
20
|
},
|
|
@@ -58,6 +58,10 @@
|
|
|
58
58
|
"cropperjs": "^1.6.0",
|
|
59
59
|
"date-fns": "^2.30.0",
|
|
60
60
|
"flexsearch": "0.7.43",
|
|
61
|
+
"i18next": "^25.0.2",
|
|
62
|
+
"i18next-browser-languagedetector": "^8.1.0",
|
|
63
|
+
"i18next-chained-backend": "^4.6.2",
|
|
64
|
+
"i18next-http-backend": "^3.0.2",
|
|
61
65
|
"jwt-decode": "^3.1.2",
|
|
62
66
|
"lexical": "^0.12.0",
|
|
63
67
|
"marked": "15.0.6",
|
|
@@ -70,6 +74,7 @@
|
|
|
70
74
|
"react-ga4": "^2.1.0",
|
|
71
75
|
"react-google-charts": "^3.0.15",
|
|
72
76
|
"react-google-recaptcha": "^3.1.0",
|
|
77
|
+
"react-i18next": "^15.5.1",
|
|
73
78
|
"react-to-print": "^2.14.13",
|
|
74
79
|
"rrule": "^2.8.1",
|
|
75
80
|
"slug": "^8.2.3"
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import axios from "axios";
|
|
2
2
|
|
|
3
3
|
export class FileHelper {
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
|
|
5
|
+
static postPresignedFile = (presigned: any, uploadedFile: File, progressCallback: (percent: number) => void) => {
|
|
6
6
|
const formData = new FormData();
|
|
7
7
|
//formData.append("key", presigned.key); //no longer needed with new aws sdk
|
|
8
8
|
formData.append("acl", "public-read");
|
|
@@ -17,10 +17,7 @@ export class FileHelper {
|
|
|
17
17
|
}
|
|
18
18
|
};
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
console.log("axios: ", axiosToUse);
|
|
22
|
-
console.log("axios tyeof: ", typeof axiosToUse.post);
|
|
23
|
-
return axiosToUse.post(presigned.url, formData, axiosConfig);
|
|
20
|
+
return axios.post(presigned.url, formData, axiosConfig);
|
|
24
21
|
};
|
|
25
22
|
|
|
26
23
|
static dataURLtoBlob(dataurl: string) {
|
package/src/helpers/Locale.ts
CHANGED
|
@@ -1,67 +1,109 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import HttpBackend from 'i18next-http-backend';
|
|
7
|
-
*/
|
|
1
|
+
import i18n from "i18next";
|
|
2
|
+
import { initReactI18next } from "react-i18next";
|
|
3
|
+
import LanguageDetector from "i18next-browser-languagedetector";
|
|
4
|
+
import Backend from "i18next-chained-backend";
|
|
5
|
+
import HttpBackend from "i18next-http-backend";
|
|
8
6
|
|
|
9
|
-
|
|
7
|
+
interface TranslationResources {
|
|
8
|
+
[key: string]: {
|
|
9
|
+
translation: Record<string, unknown>;
|
|
10
|
+
};
|
|
11
|
+
}
|
|
10
12
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
+
interface ExtraLanguageCodes {
|
|
14
|
+
[key: string]: string[];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export class Locale {
|
|
18
|
+
private static readonly supportedLanguages: string[] = [
|
|
19
|
+
"de",
|
|
20
|
+
"en",
|
|
21
|
+
"es",
|
|
22
|
+
"fr",
|
|
23
|
+
"hi",
|
|
24
|
+
"it",
|
|
25
|
+
"ko",
|
|
26
|
+
"no",
|
|
27
|
+
"pt",
|
|
28
|
+
"ru",
|
|
29
|
+
"tl",
|
|
30
|
+
"zh",
|
|
31
|
+
];
|
|
32
|
+
private static readonly extraCodes: ExtraLanguageCodes = { no: ["nb", "nn"] };
|
|
13
33
|
|
|
14
|
-
|
|
34
|
+
static init = async (backends: string[]): Promise<void> => {
|
|
35
|
+
const resources: TranslationResources = {};
|
|
36
|
+
let langs = ["en"];
|
|
15
37
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
38
|
+
if (typeof navigator !== "undefined") {
|
|
39
|
+
const browserLang = navigator.language.split("-")[0];
|
|
40
|
+
const mappedLang
|
|
41
|
+
= Object.keys(this.extraCodes).find((code) =>
|
|
42
|
+
this.extraCodes[code].includes(browserLang),
|
|
43
|
+
) || browserLang;
|
|
44
|
+
const notSupported = this.supportedLanguages.indexOf(mappedLang) === -1;
|
|
45
|
+
langs = mappedLang === "en" || notSupported ? ["en"] : ["en", mappedLang];
|
|
46
|
+
}
|
|
24
47
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
48
|
+
// Load translations for each language
|
|
49
|
+
for (const lang of langs) {
|
|
50
|
+
resources[lang] = { translation: {} };
|
|
51
|
+
for (const backend of backends) {
|
|
52
|
+
const url = backend.replace("{{lng}}", lang);
|
|
53
|
+
const data = await fetch(url).then((response) => response.json());
|
|
54
|
+
resources[lang].translation = this.deepMerge(
|
|
55
|
+
resources[lang].translation,
|
|
56
|
+
data,
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
36
60
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
61
|
+
// Initialize i18n
|
|
62
|
+
await i18n
|
|
63
|
+
.use(Backend)
|
|
64
|
+
.use(LanguageDetector)
|
|
65
|
+
.use(initReactI18next)
|
|
66
|
+
.init({
|
|
67
|
+
resources,
|
|
68
|
+
fallbackLng: "en",
|
|
69
|
+
debug: process.env.NODE_ENV === "development",
|
|
70
|
+
interpolation: {
|
|
71
|
+
escapeValue: false,
|
|
72
|
+
},
|
|
73
|
+
detection: {
|
|
74
|
+
order: ["navigator"],
|
|
75
|
+
caches: ["localStorage"],
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
};
|
|
46
79
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
80
|
+
private static deepMerge(
|
|
81
|
+
target: Record<string, unknown>,
|
|
82
|
+
source: Record<string, unknown>,
|
|
83
|
+
): Record<string, unknown> {
|
|
84
|
+
for (const key in source) {
|
|
85
|
+
if (this.isObject(source[key])) {
|
|
86
|
+
if (!target[key]) Object.assign(target, { [key]: {} });
|
|
87
|
+
this.deepMerge(
|
|
88
|
+
target[key] as Record<string, unknown>,
|
|
89
|
+
source[key] as Record<string, unknown>,
|
|
90
|
+
);
|
|
91
|
+
} else Object.assign(target, { [key]: source[key] });
|
|
92
|
+
}
|
|
93
|
+
return target;
|
|
94
|
+
}
|
|
50
95
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
let obj = this.keys;
|
|
55
|
-
for (let part of parts) {
|
|
56
|
-
if (obj[part]) {
|
|
57
|
-
obj = obj[part];
|
|
58
|
-
result = obj;
|
|
59
|
-
} else {
|
|
60
|
-
return key;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
return result;
|
|
64
|
-
}
|
|
96
|
+
private static isObject(obj: unknown): boolean {
|
|
97
|
+
return obj !== null && typeof obj === "object" && !Array.isArray(obj);
|
|
98
|
+
}
|
|
65
99
|
|
|
100
|
+
// New helper method that uses i18n
|
|
101
|
+
static t(key: string, options?: Record<string, unknown>): string {
|
|
102
|
+
return i18n.t(key, options);
|
|
103
|
+
}
|
|
66
104
|
|
|
105
|
+
// Keep the old method for backward compatibility
|
|
106
|
+
static label(key: string): string {
|
|
107
|
+
return this.t(key);
|
|
108
|
+
}
|
|
67
109
|
}
|