@diia-inhouse/i18n 3.1.87 → 3.2.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.
@@ -27,7 +27,6 @@ import { AlsData } from "@diia-inhouse/types";
27
27
  declare class I18nService<L = string> {
28
28
  private readonly asyncLocalStorage;
29
29
  private readonly i18n;
30
- private readonly headerName;
31
30
  constructor(asyncLocalStorage: AsyncLocalStorage<AlsData>, localesDirectory?: string);
32
31
  /**
33
32
  * @deprecated Use I18nextService with namespaced translation functions instead.
@@ -1,4 +1,5 @@
1
1
  import { LOCALE } from "../interfaces/services/i18n.js";
2
+ import { getSupportedLocale } from "../utils/locale.js";
2
3
  import he from "he";
3
4
  import { I18n } from "i18n";
4
5
  //#region src/services/i18n.ts
@@ -25,7 +26,6 @@ import { I18n } from "i18n";
25
26
  var I18nService = class {
26
27
  asyncLocalStorage;
27
28
  i18n;
28
- headerName = "appLocale";
29
29
  constructor(asyncLocalStorage, localesDirectory = "./dist/locales") {
30
30
  this.asyncLocalStorage = asyncLocalStorage;
31
31
  this.i18n = new I18n();
@@ -38,7 +38,6 @@ var I18nService = class {
38
38
  autoReload: false,
39
39
  updateFiles: false,
40
40
  objectNotation: true,
41
- header: this.headerName,
42
41
  defaultLocale: LOCALE.uk
43
42
  });
44
43
  }
@@ -62,7 +61,7 @@ var I18nService = class {
62
61
  return this.i18n.setLocale({}, locale);
63
62
  }
64
63
  getLocaleFromStore() {
65
- return this.asyncLocalStorage.getStore()?.headers?.[this.headerName] || "";
64
+ return getSupportedLocale(this.asyncLocalStorage.getStore()?.headers?.acceptLanguage) || "";
66
65
  }
67
66
  };
68
67
  //#endregion
@@ -11,7 +11,6 @@ declare class I18nextService {
11
11
  private readonly asyncLocalStorage;
12
12
  private readonly logger;
13
13
  private readonly i18nextInstance;
14
- private readonly headerName;
15
14
  constructor(localesDirectory: string | undefined, initOptions: Partial<i18next.InitOptions> | undefined, asyncLocalStorage: AsyncLocalStorage<AlsData>, logger: Logger);
16
15
  ns<TResource>(namespace: string): TranslationFunction<TResource>;
17
16
  get(key: string, options?: object): string;
@@ -1,4 +1,5 @@
1
1
  import { LOCALE } from "../interfaces/services/i18n.js";
2
+ import { getSupportedLocale } from "../utils/locale.js";
2
3
  import { missedInterpolationParamsTotalMetric, missedLocaleKeysTotalMetric } from "../metrics/index.js";
3
4
  import { lstatSync, readdirSync } from "node:fs";
4
5
  import path from "node:path";
@@ -11,7 +12,6 @@ var I18nextService = class {
11
12
  asyncLocalStorage;
12
13
  logger;
13
14
  i18nextInstance;
14
- headerName = "appLocale";
15
15
  constructor(localesDirectory = "./dist/locales", initOptions = {}, asyncLocalStorage, logger) {
16
16
  this.localesDirectory = localesDirectory;
17
17
  this.initOptions = initOptions;
@@ -43,7 +43,7 @@ var I18nextService = class {
43
43
  return this.i18nextInstance;
44
44
  }
45
45
  getLocaleFromStore() {
46
- return this.asyncLocalStorage.getStore()?.headers?.[this.headerName] || LOCALE.uk;
46
+ return getSupportedLocale(this.asyncLocalStorage.getStore()?.headers?.acceptLanguage) || LOCALE.uk;
47
47
  }
48
48
  initializeI18next() {
49
49
  const namespaces = this.findAllNamespaces();
@@ -0,0 +1,7 @@
1
+ import { LOCALE } from "../interfaces/services/i18n.js";
2
+ //#region src/utils/locale.ts
3
+ function getSupportedLocale(value) {
4
+ return Object.values(LOCALE).find((locale) => locale === value);
5
+ }
6
+ //#endregion
7
+ export { getSupportedLocale };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@diia-inhouse/i18n",
3
- "version": "3.1.87",
3
+ "version": "3.2.0",
4
4
  "description": "Internationalization package",
5
5
  "license": "SEE LICENSE IN LICENSE.md",
6
6
  "author": "diia-team",
@@ -31,8 +31,8 @@
31
31
  "test:watch": "vitest watch"
32
32
  },
33
33
  "dependencies": {
34
- "@diia-inhouse/diia-logger": "4.7.23",
35
- "@diia-inhouse/diia-metrics": "7.1.149",
34
+ "@diia-inhouse/diia-logger": "4.7.24",
35
+ "@diia-inhouse/diia-metrics": "7.1.150",
36
36
  "@types/i18n": "0.13.12",
37
37
  "glob": "13.0.6",
38
38
  "he": "1.2.0",
@@ -45,8 +45,8 @@
45
45
  "@commitlint/cli": "20.4.2",
46
46
  "@diia-inhouse/configs": "7.2.2",
47
47
  "@diia-inhouse/oxc-config": "4.0.3",
48
- "@diia-inhouse/test": "8.3.42",
49
- "@diia-inhouse/types": "14.7.1",
48
+ "@diia-inhouse/test": "8.3.43",
49
+ "@diia-inhouse/types": "14.7.2",
50
50
  "@types/he": "1.2.3",
51
51
  "@types/node": "25.6.2",
52
52
  "@vitest/coverage-v8": "4.1.11",