i18n-keyless-react 1.14.11 → 1.14.13

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.
@@ -10,7 +10,7 @@ export const store = {
10
10
  },
11
11
  currentLanguage: "fr",
12
12
  translations: {},
13
- lastUsedTranslations: {},
13
+ translationsUsage: {},
14
14
  uniqueId: null,
15
15
  lastRefresh: null,
16
16
  setTranslations: vi.fn(),
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { I18nKeylessText } from "./I18nKeylessText";
1
+ export { I18nKeylessText, I18nKeylessText as T } from "./I18nKeylessText";
2
2
  export { init, setCurrentLanguage, useCurrentLanguage, getTranslation, getSupportedLanguages } from "./store";
3
3
  export { clearI18nKeylessStorage, validateLanguage } from "./utils";
4
4
  export type { I18nKeylessTextProps } from "./I18nKeylessText";
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- export { I18nKeylessText } from "./I18nKeylessText";
1
+ export { I18nKeylessText, I18nKeylessText as T } from "./I18nKeylessText";
2
2
  export { init, setCurrentLanguage, useCurrentLanguage, getTranslation, getSupportedLanguages } from "./store";
3
3
  export { clearI18nKeylessStorage, validateLanguage } from "./utils";
4
4
  export { getAllTranslationsFromLanguage, queue, } from "i18n-keyless-core";
package/dist/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "i18n-keyless-react",
3
3
  "private": false,
4
- "version": "1.14.11",
4
+ "version": "1.14.13",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
7
  "module": "./dist/index.js",
@@ -17,7 +17,7 @@
17
17
  "postpublish": "rm -rf ./dist && rm *.tgz"
18
18
  },
19
19
  "dependencies": {
20
- "i18n-keyless-core": "1.14.11",
20
+ "i18n-keyless-core": "1.14.13",
21
21
  "zustand": "^5.0.3"
22
22
  },
23
23
  "peerDependencies": {
package/dist/store.js CHANGED
@@ -12,7 +12,7 @@ export const useI18nKeyless = create((set, get) => ({
12
12
  uniqueId: null,
13
13
  lastRefresh: null,
14
14
  translations: {},
15
- lastUsedTranslations: {},
15
+ translationsUsage: {},
16
16
  currentLanguage: "fr",
17
17
  config: {
18
18
  API_KEY: "",
@@ -50,41 +50,38 @@ export const useI18nKeyless = create((set, get) => ({
50
50
  sendTranslationsUsage: async () => {
51
51
  const store = get();
52
52
  if (!store.config) {
53
- throw new Error(`i18n-keyless: config is not initialized sending last used translation`);
53
+ throw new Error(`i18n-keyless: config is not initialized sending translations usage`);
54
54
  }
55
55
  const storage = store.config.storage;
56
- const lastUsedTranslations = store.lastUsedTranslations;
57
- if (Object.keys(lastUsedTranslations).length === 0) {
56
+ const translationsUsage = store.translationsUsage;
57
+ if (Object.keys(translationsUsage).length === 0) {
58
58
  return;
59
59
  }
60
- const response = await sendTranslationsUsageToI18nKeyless(lastUsedTranslations, store);
60
+ const response = await sendTranslationsUsageToI18nKeyless(translationsUsage, store);
61
61
  if (response?.ok) {
62
- set({ lastUsedTranslations: {} });
62
+ set({ translationsUsage: {} });
63
63
  if (storage) {
64
- setItem(storeKeys.lastUsedTranslations, "", storage);
64
+ setItem(storeKeys.translationsUsage, "", storage);
65
65
  }
66
66
  }
67
67
  },
68
68
  setTranslationUsage: async (key, context) => {
69
69
  const store = get();
70
70
  if (!store.config) {
71
- throw new Error(`i18n-keyless: config is not initialized sending last used translation`);
71
+ throw new Error(`i18n-keyless: config is not initialized setting translation usage translation`);
72
72
  }
73
73
  const storage = store.config.storage;
74
- const lastUsedTranslations = store.lastUsedTranslations;
75
- if (Object.keys(lastUsedTranslations).length === 0) {
76
- return;
77
- }
74
+ const translationsUsage = store.translationsUsage;
78
75
  const lastUpdatedAt = new Date().toISOString().split("T")[0];
79
76
  if (context) {
80
- lastUsedTranslations[`${key}__${context}`] = lastUpdatedAt;
77
+ translationsUsage[`${key}__${context}`] = lastUpdatedAt;
81
78
  }
82
79
  else {
83
- lastUsedTranslations[key] = lastUpdatedAt;
80
+ translationsUsage[key] = lastUpdatedAt;
84
81
  }
85
- set({ lastUsedTranslations });
82
+ set({ translationsUsage });
86
83
  if (storage) {
87
- setItem(storeKeys.lastUsedTranslations, JSON.stringify(lastUsedTranslations), storage);
84
+ setItem(storeKeys.translationsUsage, JSON.stringify(translationsUsage), storage);
88
85
  }
89
86
  },
90
87
  setLanguage: async (lang) => {
@@ -134,15 +131,15 @@ async function hydrate() {
134
131
  if (debug)
135
132
  console.log("i18n-keyless: _hydrate: no translations");
136
133
  }
137
- const lastUsedTranslations = await getItem(storeKeys.lastUsedTranslations, storage, JSON.parse);
138
- if (lastUsedTranslations) {
134
+ const translationsUsage = await getItem(storeKeys.translationsUsage, storage, JSON.parse);
135
+ if (translationsUsage) {
139
136
  if (debug)
140
- console.log("i18n-keyless: _hydrate: last used translation", lastUsedTranslations);
141
- useI18nKeyless.setState({ lastUsedTranslations: lastUsedTranslations });
137
+ console.log("i18n-keyless: _hydrate: translations usage", translationsUsage);
138
+ useI18nKeyless.setState({ translationsUsage: translationsUsage });
142
139
  }
143
140
  else {
144
141
  if (debug)
145
- console.log("i18n-keyless: _hydrate: no last used translation");
142
+ console.log("i18n-keyless: _hydrate: no translations usage");
146
143
  }
147
144
  const currentLanguage = await getItem(storeKeys.currentLanguage, storage);
148
145
  if (currentLanguage) {
package/dist/types.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { I18nKeylessResponse, Lang, Translations, LastUsedTranslations, HandleTranslateFunction, GetAllTranslationsFunction, SendTranslationsUsageFunction, UniqueId, LastRefresh, LanguagesConfig } from "i18n-keyless-core";
1
+ import type { I18nKeylessResponse, Lang, Translations, TranslationsUsage, HandleTranslateFunction, GetAllTranslationsFunction, SendTranslationsUsageFunction, UniqueId, LastRefresh, LanguagesConfig } from "i18n-keyless-core";
2
2
  type GetStorageFunction = (key: string) => string | null | undefined | Promise<string | null | undefined>;
3
3
  type SetStorageFunction = (key: string, value: string) => void | Promise<void>;
4
4
  type RemoveStorageFunction = (key: string) => void | Promise<void>;
@@ -134,7 +134,7 @@ export interface TranslationStoreState {
134
134
  * it's used to clean up the translations database
135
135
  * and to avoid paying for translations that are not used anymore
136
136
  */
137
- lastUsedTranslations: LastUsedTranslations;
137
+ translationsUsage: TranslationsUsage;
138
138
  /**
139
139
  * the current language of the user
140
140
  */
package/dist/utils.d.ts CHANGED
@@ -7,7 +7,7 @@ export declare const storeKeys: {
7
7
  lastRefresh: "i18n-keyless-last-refresh";
8
8
  translations: "i18n-keyless-translations";
9
9
  currentLanguage: "i18n-keyless-current-language";
10
- lastUsedTranslations: "i18n-keyless-last-used-translations";
10
+ translationsUsage: "i18n-keyless-translations-usage";
11
11
  };
12
12
  /**
13
13
  * Retrieves an item from storage using various storage API patterns
package/dist/utils.js CHANGED
@@ -6,7 +6,7 @@ export const storeKeys = {
6
6
  lastRefresh: "i18n-keyless-last-refresh",
7
7
  translations: "i18n-keyless-translations",
8
8
  currentLanguage: "i18n-keyless-current-language",
9
- lastUsedTranslations: "i18n-keyless-last-used-translations",
9
+ translationsUsage: "i18n-keyless-translations-usage",
10
10
  };
11
11
  /**
12
12
  * Retrieves an item from storage using various storage API patterns
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "i18n-keyless-react",
3
3
  "private": false,
4
- "version": "1.14.11",
4
+ "version": "1.14.13",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
7
  "module": "./dist/index.js",
@@ -17,7 +17,7 @@
17
17
  "postpublish": "rm -rf ./dist && rm *.tgz"
18
18
  },
19
19
  "dependencies": {
20
- "i18n-keyless-core": "1.14.11",
20
+ "i18n-keyless-core": "1.14.13",
21
21
  "zustand": "^5.0.3"
22
22
  },
23
23
  "peerDependencies": {