@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.
@@ -1,5 +1,5 @@
1
1
  export declare class FileHelper {
2
- static postPresignedFile: (presigned: any, uploadedFile: File, progressCallback: (percent: number) => void, axiosInstance?: any) => any;
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;IACrB,MAAM,CAAC,iBAAiB,cAAe,GAAG,gBAAgB,IAAI,8BAA8B,MAAM,KAAK,IAAI,kBAAkB,GAAG,SAoB9H;IAEF,MAAM,CAAC,aAAa,CAAC,OAAO,EAAE,MAAM;CAQrC"}
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, axiosInstance) => {
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
- console.log("#10");
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;IAuBrB,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;;AA9BH,gCA+BC;AA9BQ,4BAAiB,GAAG,CAAC,SAAc,EAAE,YAAkB,EAAE,gBAA2C,EAAE,aAAmB,EAAE,EAAE;IAClI,MAAM,UAAU,GAAG,aAAa,IAAI,eAAK,CAAC;IAC1C,MAAM,QAAQ,GAAG,IAAI,QAAQ,EAAE,CAAC;IAChC,4EAA4E;IAC5E,QAAQ,CAAC,MAAM,CAAC,KAAK,EAAE,aAAa,CAAC,CAAC;IACtC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
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":"AAQA,qBAAa,MAAM;IAEjB,OAAO,CAAC,MAAM,CAAC,kBAAkB,CAA4E;IAC7G,OAAO,CAAC,MAAM,CAAC,UAAU,CAAgD;IAEzE,OAAO,CAAC,MAAM,CAAC,IAAI,CAAS;IAE5B,MAAM,CAAC,IAAI,aAAmB,MAAM,EAAE,mBAmBrC;IAED,OAAO,CAAC,MAAM,CAAC,SAAS;IAUxB,OAAO,CAAC,MAAM,CAAC,QAAQ;IAIvB,MAAM,CAAC,KAAK,CAAC,GAAG,EAAC,MAAM;CAgBxB"}
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"}
@@ -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 === 'object' && !Array.isArray(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
- const parts = key.split(".");
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 = ["de", "en", "es", "fr", "hi", "it", "ko", "no", "pt", "ru", "tl", "zh"];
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
- let l = navigator.language.split("-")[0];
62
- l = Object.keys(_a.extraCodes).find(code => _a.extraCodes[code].includes(l)) || l;
63
- const notSupported = _a.supportedLanguages.indexOf(l) === -1;
64
- langs = (l === "en" || notSupported) ? ["en"] : ["en", l];
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
- let result = {};
67
- for (let lang of langs) {
68
- for (let backend of backends) {
69
- let url = backend.replace("{{lng}}", lang);
70
- console.log(url);
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
- result = _a.deepMerge(result, data);
78
+ resources[lang].translation = _a.deepMerge(resources[lang].translation, data);
73
79
  }
74
80
  }
75
- _a.keys = result;
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":";AAAA;;;;;;EAME;;;;;;;;;;;;;AAEF,MAAa,MAAM;IA4BT,MAAM,CAAC,SAAS,CAAC,MAAU,EAAE,MAAU;QAC7C,KAAK,MAAM,GAAG,IAAI,MAAM,EAAE;YACxB,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE;gBAC9B,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,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;aAC1C;;gBAAM,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,EAAE,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;SACtD;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;IAEO,MAAM,CAAC,QAAQ,CAAC,GAAO;QAC7B,OAAO,GAAG,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAC/D,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,GAAU;QACrB,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAC7B,IAAI,MAAM,GAAG,GAAG,CAAC;QACjB,IAAI,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC;QACpB,KAAK,IAAI,IAAI,IAAI,KAAK,EAAE;YACtB,IAA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HANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@churchapps/apphelper",
3
- "version": "0.3.23",
3
+ "version": "0.3.25",
4
4
  "description": "Library of helper functions for React and NextJS ChurchApps",
5
5
  "main": "dist/index.js",
6
- "types": "dist/index.d.ts",
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
- "prepare": "npm run build",
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
- static postPresignedFile = (presigned: any, uploadedFile: File, progressCallback: (percent: number) => void, axiosInstance?: any) => {
5
- const axiosToUse = axiosInstance || axios;
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
- console.log("#10");
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) {
@@ -1,67 +1,109 @@
1
- /*
2
- import i18n from 'i18next';
3
- import { initReactI18next } from 'react-i18next';
4
- import LanguageDetector from 'i18next-browser-languagedetector';
5
- import Backend from 'i18next-chained-backend';
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
- export class Locale {
7
+ interface TranslationResources {
8
+ [key: string]: {
9
+ translation: Record<string, unknown>;
10
+ };
11
+ }
10
12
 
11
- private static supportedLanguages = ["de", "en", "es", "fr", "hi", "it", "ko", "no", "pt", "ru", "tl", "zh"];
12
- private static extraCodes: {[key: string]: string[]} = {no: ["nb", "nn"]}
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
- private static keys:any = {}
34
+ static init = async (backends: string[]): Promise<void> => {
35
+ const resources: TranslationResources = {};
36
+ let langs = ["en"];
15
37
 
16
- static init = async (backends:string[]) => {
17
- let langs = ["en"];
18
- if (typeof navigator !== "undefined") {
19
- let l = navigator.language.split("-")[0];
20
- l = Object.keys(this.extraCodes).find(code => this.extraCodes[code].includes(l)) || l
21
- const notSupported = this.supportedLanguages.indexOf(l) === -1
22
- langs = (l==="en" || notSupported) ? ["en"] : ["en", l];
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
- let result = {};
26
- for (let lang of langs) {
27
- for (let backend of backends) {
28
- let url = backend.replace("{{lng}}", lang);
29
- console.log(url);
30
- const data = await fetch(url).then((response) => response.json());
31
- result = this.deepMerge(result, data);
32
- }
33
- }
34
- this.keys = result;
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
- private static deepMerge(target:any, source:any) {
38
- for (const key in source) {
39
- if (this.isObject(source[key])) {
40
- if (!target[key]) Object.assign(target, { [key]: {} });
41
- this.deepMerge(target[key], source[key]);
42
- } else Object.assign(target, { [key]: source[key] });
43
- }
44
- return target;
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
- private static isObject(obj:any) {
48
- return obj && typeof obj === 'object' && !Array.isArray(obj);
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
- static label(key:string) {
52
- const parts = key.split(".");
53
- let result = key;
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
  }