@armoury/fivem-framework-client 1.0.42 → 1.0.44
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/cjs/client/services/i18n/i18n.service.js +66 -0
- package/dist/cjs/client/services/i18n/index.js +17 -0
- package/dist/cjs/client/services/index.js +1 -0
- package/dist/esm/client/services/i18n/i18n.service.js +60 -0
- package/dist/esm/client/services/i18n/index.js +1 -0
- package/dist/esm/client/services/index.js +1 -0
- package/dist/types/client/services/i18n/i18n.service.d.ts +15 -0
- package/dist/types/client/services/i18n/index.d.ts +1 -0
- package/dist/types/client/services/index.d.ts +1 -0
- package/package.json +10 -4
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
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;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
9
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.I18n = void 0;
|
|
13
|
+
const node_polyglot_1 = __importDefault(require("node-polyglot"));
|
|
14
|
+
const injection_js_1 = require("injection-js");
|
|
15
|
+
const fivem_framework_common_1 = require("@armoury/fivem-framework-common");
|
|
16
|
+
let I18n = class I18n {
|
|
17
|
+
static withOptions(options = {}) {
|
|
18
|
+
var _a, _b;
|
|
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
|
+
return {
|
|
23
|
+
provide: fivem_framework_common_1.APP_INITIALIZER,
|
|
24
|
+
useValue: () => this.loadLanguage(language, resources),
|
|
25
|
+
multi: true
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
static setLanguage(language, resources) {
|
|
29
|
+
this.loadLanguage(language, resources !== null && resources !== void 0 ? resources : this._resources);
|
|
30
|
+
}
|
|
31
|
+
static loadLanguage(language, resources) {
|
|
32
|
+
const currentResource = Cfx.Client.GetCurrentResourceName();
|
|
33
|
+
const filePath = `locales/${language}.json`;
|
|
34
|
+
const currentContent = Cfx.Client.LoadResourceFile(currentResource, filePath);
|
|
35
|
+
const translations = {};
|
|
36
|
+
let foundLanguage = currentContent !== null;
|
|
37
|
+
for (const resource of resources) {
|
|
38
|
+
if (resource === currentResource) {
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
const content = Cfx.Client.LoadResourceFile(resource, filePath);
|
|
42
|
+
if (content !== null) {
|
|
43
|
+
Object.assign(translations, JSON.parse(content));
|
|
44
|
+
foundLanguage = true;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
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
|
+
}
|
|
54
|
+
this.polyglot.locale(language);
|
|
55
|
+
this.polyglot.replace(translations);
|
|
56
|
+
}
|
|
57
|
+
static translate(key, params = {}) {
|
|
58
|
+
return this.polyglot.t(key, params);
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
exports.I18n = I18n;
|
|
62
|
+
I18n.polyglot = new node_polyglot_1.default();
|
|
63
|
+
I18n._resources = [];
|
|
64
|
+
exports.I18n = I18n = __decorate([
|
|
65
|
+
(0, injection_js_1.Injectable)()
|
|
66
|
+
], I18n);
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./i18n.service"), exports);
|
|
@@ -27,3 +27,4 @@ __exportStar(require("./client-vehicles.service"), exports);
|
|
|
27
27
|
__exportStar(require("./client-ui.service"), exports);
|
|
28
28
|
__exportStar(require("./client-waypoints.service"), exports);
|
|
29
29
|
__exportStar(require("./ui"), exports);
|
|
30
|
+
__exportStar(require("./i18n"), exports);
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
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
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import Polyglot from 'node-polyglot';
|
|
8
|
+
import { Injectable } from 'injection-js';
|
|
9
|
+
import { APP_INITIALIZER } from '@armoury/fivem-framework-common';
|
|
10
|
+
let I18n = class I18n {
|
|
11
|
+
static withOptions(options = {}) {
|
|
12
|
+
var _a, _b;
|
|
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
|
+
return {
|
|
17
|
+
provide: APP_INITIALIZER,
|
|
18
|
+
useValue: () => this.loadLanguage(language, resources),
|
|
19
|
+
multi: true
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
static setLanguage(language, resources) {
|
|
23
|
+
this.loadLanguage(language, resources !== null && resources !== void 0 ? resources : this._resources);
|
|
24
|
+
}
|
|
25
|
+
static loadLanguage(language, resources) {
|
|
26
|
+
const currentResource = Cfx.Client.GetCurrentResourceName();
|
|
27
|
+
const filePath = `locales/${language}.json`;
|
|
28
|
+
const currentContent = Cfx.Client.LoadResourceFile(currentResource, filePath);
|
|
29
|
+
const translations = {};
|
|
30
|
+
let foundLanguage = currentContent !== null;
|
|
31
|
+
for (const resource of resources) {
|
|
32
|
+
if (resource === currentResource) {
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
const content = Cfx.Client.LoadResourceFile(resource, filePath);
|
|
36
|
+
if (content !== null) {
|
|
37
|
+
Object.assign(translations, JSON.parse(content));
|
|
38
|
+
foundLanguage = true;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
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
|
+
}
|
|
48
|
+
this.polyglot.locale(language);
|
|
49
|
+
this.polyglot.replace(translations);
|
|
50
|
+
}
|
|
51
|
+
static translate(key, params = {}) {
|
|
52
|
+
return this.polyglot.t(key, params);
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
I18n.polyglot = new Polyglot();
|
|
56
|
+
I18n._resources = [];
|
|
57
|
+
I18n = __decorate([
|
|
58
|
+
Injectable()
|
|
59
|
+
], I18n);
|
|
60
|
+
export { I18n };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './i18n.service';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Provider } from 'injection-js';
|
|
2
|
+
export declare class I18n {
|
|
3
|
+
private static polyglot;
|
|
4
|
+
private static _resources;
|
|
5
|
+
static withOptions(options?: I18nOptions): Provider;
|
|
6
|
+
static setLanguage(language: string, resources?: string[]): void;
|
|
7
|
+
private static loadLanguage;
|
|
8
|
+
static translate(key: string, params?: TranslationParams): string;
|
|
9
|
+
}
|
|
10
|
+
type I18nOptions = {
|
|
11
|
+
defaultLanguage?: string;
|
|
12
|
+
with?: string[];
|
|
13
|
+
};
|
|
14
|
+
type TranslationParams = Record<string, string | number>;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './i18n.service';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@armoury/fivem-framework-client",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.44",
|
|
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",
|
|
@@ -12,7 +12,9 @@
|
|
|
12
12
|
"require": "./dist/cjs/client/index.js"
|
|
13
13
|
}
|
|
14
14
|
},
|
|
15
|
-
"files": [
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
16
18
|
"scripts": {
|
|
17
19
|
"build": "npm run build:cjs && npm run build:esm && npm run build:types",
|
|
18
20
|
"build:cjs": "tsc -p tsconfig.cjs.json",
|
|
@@ -25,9 +27,13 @@
|
|
|
25
27
|
"rxjs": "^7.8.1"
|
|
26
28
|
},
|
|
27
29
|
"peerDependencies": {
|
|
28
|
-
"@armoury/fivem-framework-common": "1.0.
|
|
30
|
+
"@armoury/fivem-framework-common": "1.0.44",
|
|
31
|
+
"node-polyglot": "2.6.0"
|
|
29
32
|
},
|
|
30
33
|
"publishConfig": {
|
|
31
34
|
"access": "public"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@types/node-polyglot": "^2.5.0"
|
|
32
38
|
}
|
|
33
|
-
}
|
|
39
|
+
}
|