@armoury/fivem-framework-client 1.0.45 → 1.0.46

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,57 +10,57 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.I18n = void 0;
13
+ const fivem_framework_common_1 = require("@armoury/fivem-framework-common");
13
14
  const node_polyglot_1 = __importDefault(require("node-polyglot"));
14
15
  const injection_js_1 = require("injection-js");
15
- const fivem_framework_common_1 = require("@armoury/fivem-framework-common");
16
16
  let I18n = class I18n {
17
17
  static withOptions(options = {}) {
18
- var _a, _b;
18
+ var _a;
19
19
  const language = (_a = options.defaultLanguage) !== null && _a !== void 0 ? _a : 'en-US';
20
- const resources = [...((_b = options.with) !== null && _b !== void 0 ? _b : [])];
21
- this._resources = resources;
22
20
  return {
23
21
  provide: fivem_framework_common_1.APP_INITIALIZER,
24
- useValue: () => this.loadLanguage(language, resources),
22
+ useValue: () => this.loadLanguage(language),
25
23
  multi: true
26
24
  };
27
25
  }
28
- static setLanguage(language, resources) {
29
- this.loadLanguage(language, resources !== null && resources !== void 0 ? resources : this._resources);
26
+ static setLanguage(language) {
27
+ this.loadLanguage(language);
30
28
  }
31
- static loadLanguage(language, resources) {
29
+ static loadLanguage(language) {
32
30
  const currentResource = Cfx.Client.GetCurrentResourceName();
33
31
  const filePath = `locales/${language}.json`;
34
- const currentContent = Cfx.Client.LoadResourceFile(currentResource, filePath);
35
32
  const translations = {};
36
- let foundLanguage = currentContent !== null;
37
- for (const resource of resources) {
38
- if (resource === currentResource) {
39
- continue;
33
+ if (currentResource === 'armoury') {
34
+ for (let i = 0; i < Cfx.Client.GetNumResources(); i++) {
35
+ const resourceName = Cfx.Client.GetResourceByFindIndex(i);
36
+ if (resourceName) {
37
+ const content = Cfx.Client.LoadResourceFile(resourceName, filePath);
38
+ if (content != null) {
39
+ translations[resourceName] = JSON.parse(content);
40
+ }
41
+ }
40
42
  }
41
- const content = Cfx.Client.LoadResourceFile(resource, filePath);
42
- if (content !== null) {
43
+ }
44
+ else {
45
+ const content = Cfx.Client.LoadResourceFile(currentResource, filePath);
46
+ if (content != null) {
43
47
  Object.assign(translations, JSON.parse(content));
44
- foundLanguage = true;
48
+ }
49
+ else {
50
+ console.warn(`Language not found: ${language}`);
45
51
  }
46
52
  }
47
- if (!foundLanguage) {
48
- console.warn(`Language not found: ${language}`);
49
- return;
50
- }
51
- if (currentContent !== null) {
52
- Object.assign(translations, JSON.parse(currentContent));
53
- }
53
+ console.log('translations are', translations);
54
54
  this.polyglot.locale(language);
55
55
  this.polyglot.replace(translations);
56
56
  }
57
57
  static translate(key, params = {}) {
58
+ console.log('translate() called! key:', key, 'params:', params);
58
59
  return this.polyglot.t(key, params);
59
60
  }
60
61
  };
61
62
  exports.I18n = I18n;
62
63
  I18n.polyglot = new node_polyglot_1.default();
63
- I18n._resources = [];
64
64
  exports.I18n = I18n = __decorate([
65
65
  (0, injection_js_1.Injectable)()
66
66
  ], I18n);
@@ -4,56 +4,56 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
4
4
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
5
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6
6
  };
7
+ import { APP_INITIALIZER } from '@armoury/fivem-framework-common';
7
8
  import Polyglot from 'node-polyglot';
8
9
  import { Injectable } from 'injection-js';
9
- import { APP_INITIALIZER } from '@armoury/fivem-framework-common';
10
10
  let I18n = class I18n {
11
11
  static withOptions(options = {}) {
12
- var _a, _b;
12
+ var _a;
13
13
  const language = (_a = options.defaultLanguage) !== null && _a !== void 0 ? _a : 'en-US';
14
- const resources = [...((_b = options.with) !== null && _b !== void 0 ? _b : [])];
15
- this._resources = resources;
16
14
  return {
17
15
  provide: APP_INITIALIZER,
18
- useValue: () => this.loadLanguage(language, resources),
16
+ useValue: () => this.loadLanguage(language),
19
17
  multi: true
20
18
  };
21
19
  }
22
- static setLanguage(language, resources) {
23
- this.loadLanguage(language, resources !== null && resources !== void 0 ? resources : this._resources);
20
+ static setLanguage(language) {
21
+ this.loadLanguage(language);
24
22
  }
25
- static loadLanguage(language, resources) {
23
+ static loadLanguage(language) {
26
24
  const currentResource = Cfx.Client.GetCurrentResourceName();
27
25
  const filePath = `locales/${language}.json`;
28
- const currentContent = Cfx.Client.LoadResourceFile(currentResource, filePath);
29
26
  const translations = {};
30
- let foundLanguage = currentContent !== null;
31
- for (const resource of resources) {
32
- if (resource === currentResource) {
33
- continue;
27
+ if (currentResource === 'armoury') {
28
+ for (let i = 0; i < Cfx.Client.GetNumResources(); i++) {
29
+ const resourceName = Cfx.Client.GetResourceByFindIndex(i);
30
+ if (resourceName) {
31
+ const content = Cfx.Client.LoadResourceFile(resourceName, filePath);
32
+ if (content != null) {
33
+ translations[resourceName] = JSON.parse(content);
34
+ }
35
+ }
34
36
  }
35
- const content = Cfx.Client.LoadResourceFile(resource, filePath);
36
- if (content !== null) {
37
+ }
38
+ else {
39
+ const content = Cfx.Client.LoadResourceFile(currentResource, filePath);
40
+ if (content != null) {
37
41
  Object.assign(translations, JSON.parse(content));
38
- foundLanguage = true;
42
+ }
43
+ else {
44
+ console.warn(`Language not found: ${language}`);
39
45
  }
40
46
  }
41
- if (!foundLanguage) {
42
- console.warn(`Language not found: ${language}`);
43
- return;
44
- }
45
- if (currentContent !== null) {
46
- Object.assign(translations, JSON.parse(currentContent));
47
- }
47
+ console.log('translations are', translations);
48
48
  this.polyglot.locale(language);
49
49
  this.polyglot.replace(translations);
50
50
  }
51
51
  static translate(key, params = {}) {
52
+ console.log('translate() called! key:', key, 'params:', params);
52
53
  return this.polyglot.t(key, params);
53
54
  }
54
55
  };
55
56
  I18n.polyglot = new Polyglot();
56
- I18n._resources = [];
57
57
  I18n = __decorate([
58
58
  Injectable()
59
59
  ], I18n);
@@ -1,15 +1,13 @@
1
1
  import { Provider } from 'injection-js';
2
2
  export declare class I18n {
3
3
  private static polyglot;
4
- private static _resources;
5
4
  static withOptions(options?: I18nOptions): Provider;
6
- static setLanguage(language: string, resources?: string[]): void;
5
+ static setLanguage(language: string): void;
7
6
  private static loadLanguage;
8
7
  static translate(key: string, params?: TranslationParams): string;
9
8
  }
10
9
  type I18nOptions = {
11
10
  defaultLanguage?: string;
12
- with?: string[];
13
11
  };
14
12
  type TranslationParams = Record<string, string | number>;
15
13
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@armoury/fivem-framework-client",
3
- "version": "1.0.45",
3
+ "version": "1.0.46",
4
4
  "description": "Client APIs for the Armoury FiveM framework",
5
5
  "main": "dist/cjs/client/index.js",
6
6
  "module": "dist/esm/client/index.js",
@@ -27,7 +27,7 @@
27
27
  "rxjs": "^7.8.1"
28
28
  },
29
29
  "peerDependencies": {
30
- "@armoury/fivem-framework-common": "1.0.45",
30
+ "@armoury/fivem-framework-common": "1.0.46",
31
31
  "node-polyglot": "2.6.0"
32
32
  },
33
33
  "publishConfig": {