@globalart/nestcord 1.3.12 → 1.4.1
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/LICENSE +21 -0
- package/dist/localization/adapters/base-localization.adapter.d.ts +1 -0
- package/dist/localization/adapters/default-localization.adapter.d.ts +1 -0
- package/dist/localization/adapters/default-localization.adapter.js +7 -0
- package/dist/localization/adapters/nested-localization.adapter.d.ts +1 -0
- package/dist/localization/adapters/nested-localization.adapter.js +7 -0
- package/package.json +4 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2003 GlobalArt Inc
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -2,4 +2,5 @@ export declare abstract class BaseLocalizationAdapter<Options = unknown> {
|
|
|
2
2
|
protected readonly options?: Options;
|
|
3
3
|
constructor(options?: Options);
|
|
4
4
|
abstract getTranslation(key: string, locale: string, ...args: unknown[]): string;
|
|
5
|
+
abstract translate(key: string, ...args: unknown[]): string;
|
|
5
6
|
}
|
|
@@ -5,6 +5,7 @@ interface DefaultLocalizationAdapterOptions {
|
|
|
5
5
|
}
|
|
6
6
|
export declare class DefaultLocalizationAdapter extends BaseLocalizationAdapter<DefaultLocalizationAdapterOptions> {
|
|
7
7
|
getTranslation(key: string, locale: string, placeholders?: Record<string, string>): string;
|
|
8
|
+
translate(key: string, placeholders?: Record<string, string>): string;
|
|
8
9
|
private getTranslations;
|
|
9
10
|
private getFallbackTranslation;
|
|
10
11
|
}
|
|
@@ -3,11 +3,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.DefaultLocalizationAdapter = void 0;
|
|
4
4
|
const text_utils_1 = require("@globalart/text-utils");
|
|
5
5
|
const base_localization_adapter_1 = require("./base-localization.adapter");
|
|
6
|
+
const interceptors_1 = require("../interceptors");
|
|
6
7
|
class DefaultLocalizationAdapter extends base_localization_adapter_1.BaseLocalizationAdapter {
|
|
7
8
|
getTranslation(key, locale, placeholders) {
|
|
8
9
|
const translation = this.getTranslations(locale)[key] || this.getFallbackTranslation(key);
|
|
9
10
|
return placeholders ? (0, text_utils_1.replacePlaceholdersInString)(translation, placeholders) : translation;
|
|
10
11
|
}
|
|
12
|
+
translate(key, placeholders) {
|
|
13
|
+
const currentTranslationFn = interceptors_1.LocalizationInterceptor.getCurrentTranslationFn();
|
|
14
|
+
return currentTranslationFn
|
|
15
|
+
? currentTranslationFn(key, placeholders)
|
|
16
|
+
: this.getTranslation(key, this.options.fallbackLocale, placeholders);
|
|
17
|
+
}
|
|
11
18
|
getTranslations(locale) {
|
|
12
19
|
var _a, _b;
|
|
13
20
|
return ((_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.locales) === null || _b === void 0 ? void 0 : _b[locale]) || {};
|
|
@@ -8,6 +8,7 @@ interface NestedLocalizationAdapterOptions {
|
|
|
8
8
|
}
|
|
9
9
|
export declare class NestedLocalizationAdapter extends BaseLocalizationAdapter<NestedLocalizationAdapterOptions> {
|
|
10
10
|
getTranslation(key: string, locale: string, placeholders?: Record<string, string>): string;
|
|
11
|
+
translate(key: string, placeholders?: Record<string, string>): string;
|
|
11
12
|
private getTranslations;
|
|
12
13
|
private findTranslation;
|
|
13
14
|
private getFallbackTranslation;
|
|
@@ -3,12 +3,19 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.NestedLocalizationAdapter = void 0;
|
|
4
4
|
const text_utils_1 = require("@globalart/text-utils");
|
|
5
5
|
const base_localization_adapter_1 = require("./base-localization.adapter");
|
|
6
|
+
const interceptors_1 = require("../interceptors");
|
|
6
7
|
class NestedLocalizationAdapter extends base_localization_adapter_1.BaseLocalizationAdapter {
|
|
7
8
|
getTranslation(key, locale, placeholders) {
|
|
8
9
|
const translations = this.getTranslations(locale);
|
|
9
10
|
const translation = this.findTranslation(translations, key) || this.getFallbackTranslation(key);
|
|
10
11
|
return (0, text_utils_1.replacePlaceholdersInString)(translation, placeholders);
|
|
11
12
|
}
|
|
13
|
+
translate(key, placeholders) {
|
|
14
|
+
const currentTranslationFn = interceptors_1.LocalizationInterceptor.getCurrentTranslationFn();
|
|
15
|
+
return currentTranslationFn
|
|
16
|
+
? currentTranslationFn(key, placeholders)
|
|
17
|
+
: this.getTranslation(key, this.options.fallbackLocale, placeholders);
|
|
18
|
+
}
|
|
12
19
|
getTranslations(locale) {
|
|
13
20
|
var _a, _b;
|
|
14
21
|
return ((_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.locales) === null || _b === void 0 ? void 0 : _b[locale]) || {};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@globalart/nestcord",
|
|
3
3
|
"description": "A module for creating Discord bots using NestJS, based on Discord.js",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.4.1",
|
|
5
5
|
"private": false,
|
|
6
6
|
"scripts": {
|
|
7
7
|
"build": "rimraf dist && tsc -p tsconfig.build.json",
|
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
"publish:dev": "npm publish --access public --tag dev",
|
|
12
12
|
"prepare": "husky ./.github/husky",
|
|
13
13
|
"format": "prettier --write \"packages/**/*.ts\"",
|
|
14
|
-
"lint": "eslint --ignore-path .gitignore packages/**/*.ts"
|
|
14
|
+
"lint": "eslint --ignore-path .gitignore packages/**/*.ts",
|
|
15
|
+
"upgrade": "npx npm-check-updates -u"
|
|
15
16
|
},
|
|
16
17
|
"lint-staged": {
|
|
17
18
|
"*.ts": "npm run format"
|
|
@@ -60,7 +61,7 @@
|
|
|
60
61
|
"@nestjs/common": "10.3.8",
|
|
61
62
|
"@nestjs/core": "10.3.8",
|
|
62
63
|
"@nestjs/platform-express": "^10.3.8",
|
|
63
|
-
"@types/node": "20.
|
|
64
|
+
"@types/node": "20.13.0",
|
|
64
65
|
"@typescript-eslint/eslint-plugin": "7.0.0",
|
|
65
66
|
"@typescript-eslint/parser": "6.21.0",
|
|
66
67
|
"discord-api-types": "0.37.86",
|