@sapphire/plugin-i18next 7.1.3-next.fae3a34.0 → 7.1.3-next.fc8c5ba
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/README.md +0 -1
- package/dist/cjs/index.cjs +2 -2
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +44 -4
- package/dist/cjs/lib/Augmentations.d.cjs +1 -1
- package/dist/cjs/lib/Augmentations.d.cjs.map +1 -1
- package/dist/cjs/lib/InternationalizationHandler.cjs +14 -21
- package/dist/cjs/lib/InternationalizationHandler.cjs.map +1 -1
- package/dist/cjs/lib/functions.cjs +1 -1
- package/dist/cjs/lib/functions.cjs.map +1 -1
- package/dist/cjs/lib/types.cjs +1 -1
- package/dist/cjs/lib/types.cjs.map +1 -1
- package/dist/cjs/register.cjs +2 -3
- package/dist/cjs/register.cjs.map +1 -1
- package/dist/esm/{chunk-6QB3UK4Q.mjs → chunk-2JTKI4GS.mjs} +3 -6
- package/dist/esm/chunk-2JTKI4GS.mjs.map +1 -0
- package/dist/esm/index.d.mts +44 -4
- package/dist/esm/index.mjs +3 -3
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/lib/Augmentations.d.mjs +1 -1
- package/dist/esm/lib/Augmentations.d.mjs.map +1 -1
- package/dist/esm/lib/InternationalizationHandler.mjs +14 -18
- package/dist/esm/lib/InternationalizationHandler.mjs.map +1 -1
- package/dist/esm/lib/functions.mjs +2 -2
- package/dist/esm/lib/functions.mjs.map +1 -1
- package/dist/esm/lib/types.mjs +1 -1
- package/dist/esm/lib/types.mjs.map +1 -1
- package/dist/esm/register.mjs +3 -4
- package/dist/esm/register.mjs.map +1 -1
- package/package.json +7 -7
- package/dist/esm/chunk-6QB3UK4Q.mjs.map +0 -1
package/README.md
CHANGED
|
@@ -7,7 +7,6 @@
|
|
|
7
7
|
**Plugin for <a href="https://github.com/sapphiredev/framework">@sapphire/framework</a> to support i18next based internationalization.**
|
|
8
8
|
|
|
9
9
|
[](https://github.com/sapphiredev/plugins/blob/main/LICENSE.md)
|
|
10
|
-
[](https://codecov.io/gh/sapphiredev/plugins)
|
|
11
10
|
[](https://bundlephobia.com/result?p=@sapphire/plugin-in17n)
|
|
12
11
|
[](https://www.npmjs.com/package/@sapphire/plugin-in17n)
|
|
13
12
|
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -10,7 +10,7 @@ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
|
10
10
|
var i18next__default = /*#__PURE__*/_interopDefault(i18next);
|
|
11
11
|
|
|
12
12
|
// src/index.ts
|
|
13
|
-
var version = "7.1.3-next.
|
|
13
|
+
var version = "7.1.3-next.fc8c5ba";
|
|
14
14
|
|
|
15
15
|
Object.defineProperty(exports, "i18next", {
|
|
16
16
|
enumerable: true,
|
|
@@ -35,5 +35,5 @@ Object.keys(types_cjs).forEach(function (k) {
|
|
|
35
35
|
get: function () { return types_cjs[k]; }
|
|
36
36
|
});
|
|
37
37
|
});
|
|
38
|
-
//# sourceMappingURL=
|
|
38
|
+
//# sourceMappingURL=index.cjs.map
|
|
39
39
|
//# sourceMappingURL=index.cjs.map
|
package/dist/cjs/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts"],"names":[
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAyBO,IAAM,OAAkB,GAAA","file":"index.cjs","sourcesContent":["import type { InternationalizationHandler } from './lib/InternationalizationHandler';\nimport type { InternationalizationClientOptions } from './lib/types';\n\nexport { default as i18next, type TFunction, type TOptions } from 'i18next';\nexport * from './lib/InternationalizationHandler';\nexport * from './lib/functions';\nexport * from './lib/types';\n\ndeclare module '@sapphire/pieces' {\n\tinterface Container {\n\t\ti18n: InternationalizationHandler;\n\t}\n}\n\ndeclare module 'discord.js' {\n\texport interface ClientOptions extends InternationalizationClientOptions {}\n}\n\n/**\n * The [@sapphire/plugin-i18next](https://github.com/sapphiredev/plugins/blob/main/packages/i18next) version that you are currently using.\n * An example use of this is showing it of in a bot information command.\n *\n * Note to Sapphire developers: This needs to explicitly be `string` so it is not typed as the string that gets replaced by esbuild\n */\n// eslint-disable-next-line @typescript-eslint/no-inferrable-types\nexport const version: string = '7.1.3-next.fc8c5ba';\n"]}
|
package/dist/cjs/index.d.cts
CHANGED
|
@@ -282,9 +282,30 @@ declare class InternationalizationHandler {
|
|
|
282
282
|
* @see {@link https://www.i18next.com/overview/api#t}
|
|
283
283
|
* @returns The localized content.
|
|
284
284
|
*/
|
|
285
|
-
format<const Key extends ParseKeys<Ns, TOpt, undefined>, const TOpt extends TOptions = TOptions, Ns extends Namespace = DefaultNamespace, Ret extends TFunctionReturn<Ns, AppendKeyPrefix<Key, undefined>, TOpt> = TOpt['returnObjects'] extends true ? $SpecialObject : string, const ActualOptions extends TOpt & InterpolationMap<Ret> = TOpt & InterpolationMap<Ret>>(locale: string,
|
|
285
|
+
format<const Key extends ParseKeys<Ns, TOpt, undefined>, const TOpt extends TOptions = TOptions, Ns extends Namespace = DefaultNamespace, Ret extends TFunctionReturn<Ns, AppendKeyPrefix<Key, undefined>, TOpt> = TOpt['returnObjects'] extends true ? $SpecialObject : string, const ActualOptions extends TOpt & InterpolationMap<Ret> = TOpt & InterpolationMap<Ret>>(locale: string, key: Key | Key[], options?: ActualOptions): TFunctionReturnOptionalDetails<Ret, TOpt>;
|
|
286
|
+
/**
|
|
287
|
+
* Localizes a content given one or more keys and i18next options.
|
|
288
|
+
* @since 2.0.0
|
|
289
|
+
* @param locale The language to be used.
|
|
290
|
+
* @param key The key or keys to retrieve the content from.
|
|
291
|
+
* @param options The interpolation options as well as a `defaultValue` for the key and any key/value pairs.
|
|
292
|
+
* @see {@link https://www.i18next.com/overview/api#t}
|
|
293
|
+
* @returns The localized content.
|
|
294
|
+
*/
|
|
295
|
+
format<const Key extends ParseKeys<Ns, TOpt, undefined>, const TOpt extends TOptions = TOptions, Ns extends Namespace = DefaultNamespace, Ret extends TFunctionReturn<Ns, AppendKeyPrefix<Key, undefined>, TOpt> = TOpt['returnObjects'] extends true ? $SpecialObject : string, const ActualOptions extends TOpt & InterpolationMap<Ret> = TOpt & InterpolationMap<Ret>>(locale: string, key: string | string[], options: TOpt & $Dictionary & {
|
|
286
296
|
defaultValue: string;
|
|
287
|
-
}
|
|
297
|
+
}): TFunctionReturnOptionalDetails<Ret, TOpt>;
|
|
298
|
+
/**
|
|
299
|
+
* Localizes a content given one or more keys and i18next options.
|
|
300
|
+
* @since 2.0.0
|
|
301
|
+
* @param locale The language to be used.
|
|
302
|
+
* @param key The key or keys to retrieve the content from.
|
|
303
|
+
* @param defaultValue The default value to use if the key is not found.
|
|
304
|
+
* @param options The interpolation options.
|
|
305
|
+
* @see {@link https://www.i18next.com/overview/api#t}
|
|
306
|
+
* @returns The localized content.
|
|
307
|
+
*/
|
|
308
|
+
format<const Key extends ParseKeys<Ns, TOpt, undefined>, const TOpt extends TOptions = TOptions, Ns extends Namespace = DefaultNamespace, Ret extends TFunctionReturn<Ns, AppendKeyPrefix<Key, undefined>, TOpt> = TOpt['returnObjects'] extends true ? $SpecialObject : string, const ActualOptions extends TOpt & InterpolationMap<Ret> = TOpt & InterpolationMap<Ret>>(locale: string, key: string | string[], defaultValue: string | undefined, options?: TOpt & $Dictionary): TFunctionReturnOptionalDetails<Ret, TOpt>;
|
|
288
309
|
/**
|
|
289
310
|
* @param directory The directory that should be walked.
|
|
290
311
|
* @since 3.0.0
|
|
@@ -331,9 +352,28 @@ declare function fetchT(target: Target): Promise<i18next.TFunction<"translation"
|
|
|
331
352
|
* @param options The options to be passed to TFunction.
|
|
332
353
|
* @returns The data that `key` held, processed by i18next.
|
|
333
354
|
*/
|
|
334
|
-
declare function resolveKey<const Key extends ParseKeys<Ns, TOpt, undefined>, const TOpt extends TOptions = TOptions, Ret extends TFunctionReturn<Ns, AppendKeyPrefix<Key, undefined>, TOpt> = TOpt['returnObjects'] extends true ? $SpecialObject : string, Ns extends Namespace = DefaultNamespace, const ActualOptions extends TOpt & InterpolationMap<Ret> = TOpt & InterpolationMap<Ret>>(target: Target,
|
|
355
|
+
declare function resolveKey<const Key extends ParseKeys<Ns, TOpt, undefined>, const TOpt extends TOptions = TOptions, Ret extends TFunctionReturn<Ns, AppendKeyPrefix<Key, undefined>, TOpt> = TOpt['returnObjects'] extends true ? $SpecialObject : string, Ns extends Namespace = DefaultNamespace, const ActualOptions extends TOpt & InterpolationMap<Ret> = TOpt & InterpolationMap<Ret>>(target: Target, key: Key | Key[], options?: ActualOptions): Promise<TFunctionReturnOptionalDetails<Ret, TOpt>>;
|
|
356
|
+
/**
|
|
357
|
+
* Resolves a key and its parameters.
|
|
358
|
+
* @since 2.0.0
|
|
359
|
+
* @param target The target to fetch the language key from.
|
|
360
|
+
* @param key The i18next key.
|
|
361
|
+
* @param options The interpolation options as well as a `defaultValue` for the key and any key/value pairs.
|
|
362
|
+
* @returns The data that `key` held, processed by i18next.
|
|
363
|
+
*/
|
|
364
|
+
declare function resolveKey<const Key extends ParseKeys<Ns, TOpt, undefined>, const TOpt extends TOptions = TOptions, Ret extends TFunctionReturn<Ns, AppendKeyPrefix<Key, undefined>, TOpt> = TOpt['returnObjects'] extends true ? $SpecialObject : string, Ns extends Namespace = DefaultNamespace, const ActualOptions extends TOpt & InterpolationMap<Ret> = TOpt & InterpolationMap<Ret>>(target: Target, key: string | string[], options: TOpt & $Dictionary & {
|
|
335
365
|
defaultValue: string;
|
|
336
|
-
}
|
|
366
|
+
}): Promise<TFunctionReturnOptionalDetails<Ret, TOpt>>;
|
|
367
|
+
/**
|
|
368
|
+
* Resolves a key and its parameters.
|
|
369
|
+
* @since 2.0.0
|
|
370
|
+
* @param target The target to fetch the language key from.
|
|
371
|
+
* @param key The i18next key.
|
|
372
|
+
* @param defaultValue The default value to use if the key is not found.
|
|
373
|
+
* @param options The interpolation options.
|
|
374
|
+
* @returns The data that `key` held, processed by i18next.
|
|
375
|
+
*/
|
|
376
|
+
declare function resolveKey<const Key extends ParseKeys<Ns, TOpt, undefined>, const TOpt extends TOptions = TOptions, Ret extends TFunctionReturn<Ns, AppendKeyPrefix<Key, undefined>, TOpt> = TOpt['returnObjects'] extends true ? $SpecialObject : string, Ns extends Namespace = DefaultNamespace, const ActualOptions extends TOpt & InterpolationMap<Ret> = TOpt & InterpolationMap<Ret>>(target: Target, key: string | string[], defaultValue: string, options?: TOpt & $Dictionary): Promise<TFunctionReturnOptionalDetails<Ret, TOpt>>;
|
|
337
377
|
/**
|
|
338
378
|
* Gets the value and the localizations from a language key.
|
|
339
379
|
* @param key The key to get the localizations from.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"Augmentations.d.cjs"}
|
|
@@ -16,10 +16,7 @@ var i18next__default = /*#__PURE__*/_interopDefault(i18next);
|
|
|
16
16
|
var __defProp = Object.defineProperty;
|
|
17
17
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
18
18
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
19
|
-
var __publicField = (obj, key, value) =>
|
|
20
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
21
|
-
return value;
|
|
22
|
-
};
|
|
19
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
23
20
|
var _InternationalizationHandler = class _InternationalizationHandler {
|
|
24
21
|
/**
|
|
25
22
|
* @param options The options that `i18next`, `@skyra/i18next-backend`, and {@link InternationalizationHandler} should use.
|
|
@@ -146,10 +143,8 @@ var _InternationalizationHandler = class _InternationalizationHandler {
|
|
|
146
143
|
const formatter = i18next__default.default.services.formatter;
|
|
147
144
|
const formatters = this.options.formatters ?? [];
|
|
148
145
|
for (const { name, format, cached } of formatters) {
|
|
149
|
-
if (cached)
|
|
150
|
-
|
|
151
|
-
else
|
|
152
|
-
formatter.add(name, format);
|
|
146
|
+
if (cached) formatter.addCached(name, format);
|
|
147
|
+
else formatter.add(name, format);
|
|
153
148
|
}
|
|
154
149
|
}
|
|
155
150
|
/**
|
|
@@ -158,28 +153,27 @@ var _InternationalizationHandler = class _InternationalizationHandler {
|
|
|
158
153
|
* @since 1.0.0
|
|
159
154
|
*/
|
|
160
155
|
getT(locale) {
|
|
161
|
-
if (!this.languagesLoaded)
|
|
162
|
-
throw new Error("Cannot call this method until InternationalizationHandler#init has been called");
|
|
156
|
+
if (!this.languagesLoaded) throw new Error("Cannot call this method until InternationalizationHandler#init has been called");
|
|
163
157
|
const t = this.languages.get(locale);
|
|
164
|
-
if (t)
|
|
165
|
-
return t;
|
|
158
|
+
if (t) return t;
|
|
166
159
|
throw new ReferenceError("Invalid language provided");
|
|
167
160
|
}
|
|
168
161
|
/**
|
|
169
162
|
* Localizes a content given one or more keys and i18next options.
|
|
170
163
|
* @since 2.0.0
|
|
171
164
|
* @param locale The language to be used.
|
|
172
|
-
*
|
|
173
|
-
* @
|
|
165
|
+
*
|
|
166
|
+
* @remark This function also has additional parameters for `key`, `defaultValue`, and `options`, however
|
|
167
|
+
* TSDoc does not let us document those while matching proper implementation. See the overloads for this method
|
|
168
|
+
* for the documentation on those parameters.
|
|
169
|
+
*
|
|
174
170
|
* @see {@link https://www.i18next.com/overview/api#t}
|
|
175
171
|
* @returns The localized content.
|
|
176
172
|
*/
|
|
177
173
|
format(locale, ...[key, defaultValueOrOptions, optionsOrUndefined]) {
|
|
178
|
-
if (!this.languagesLoaded)
|
|
179
|
-
throw new Error("Cannot call this method until InternationalizationHandler#init has been called");
|
|
174
|
+
if (!this.languagesLoaded) throw new Error("Cannot call this method until InternationalizationHandler#init has been called");
|
|
180
175
|
const language = this.languages.get(locale);
|
|
181
|
-
if (!language)
|
|
182
|
-
throw new ReferenceError("Invalid language provided");
|
|
176
|
+
if (!language) throw new ReferenceError("Invalid language provided");
|
|
183
177
|
const defaultValue = typeof defaultValueOrOptions === "string" ? defaultValueOrOptions : this.options.defaultMissingKey ? language(this.options.defaultMissingKey, { replace: { key } }) : "";
|
|
184
178
|
return language(key, { defaultValue, ...optionsOrUndefined ?? {} });
|
|
185
179
|
}
|
|
@@ -192,8 +186,7 @@ var _InternationalizationHandler = class _InternationalizationHandler {
|
|
|
192
186
|
const namespaces = /* @__PURE__ */ new Set();
|
|
193
187
|
const dir = await promises.opendir(directory);
|
|
194
188
|
for await (const entry of dir) {
|
|
195
|
-
if (!entry.isDirectory())
|
|
196
|
-
continue;
|
|
189
|
+
if (!entry.isDirectory()) continue;
|
|
197
190
|
languages.add(entry.name);
|
|
198
191
|
for await (const namespace of this.walkLocaleDirectory(path.join(dir.path, entry.name), "")) {
|
|
199
192
|
namespaces.add(namespace);
|
|
@@ -236,5 +229,5 @@ __name(_InternationalizationHandler, "InternationalizationHandler");
|
|
|
236
229
|
var InternationalizationHandler = _InternationalizationHandler;
|
|
237
230
|
|
|
238
231
|
exports.InternationalizationHandler = InternationalizationHandler;
|
|
239
|
-
//# sourceMappingURL=
|
|
232
|
+
//# sourceMappingURL=InternationalizationHandler.cjs.map
|
|
240
233
|
//# sourceMappingURL=InternationalizationHandler.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/InternationalizationHandler.ts"],"names":[],"mappings":";;;;;;;;;AAAA,SAAS,cAAc;AACvB,SAAS,WAAW,mBAAmB;AACvC,SAAS,kBAAkC;AAC3C,SAAS,eAAoC;AAC7C,OAAO,aAUA;AAEP,SAAS,eAAe;AACxB,SAAS,YAAY;AACrB,SAAS,KAAK,qBAAqB;AAO5B,IAAM,+BAAN,MAAM,6BAA4B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EA2CjC,YAAY,SAAuC;AAtC1D;AAAA;AAAA;AAAA;AAAA,wBAAO,mBAAkB;AAMzB;AAAA;AAAA;AAAA;AAAA,w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AA0D,KAAK,CAAC;AAAA,EACrH;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,OAAe,oBAAoB,WAAmB,IAAoC;AACzF,UAAM,MAAM,MAAM,QAAQ,SAAS;AACnC,qBAAiB,SAAS,KAAK;AAC9B,UAAI,MAAM,YAAY,GAAG;AACxB,eAAO,KAAK,oBAAoB,KAAK,IAAI,MAAM,MAAM,IAAI,GAAG,GAAG,EAAE,GAAG,MAAM,IAAI,GAAG;AAAA,MAClF,WAAW,MAAM,OAAO,KAAK,MAAM,KAAK,SAAS,OAAO,GAAG;AAC1D,cAAM,GAAG,EAAE,GAAG,MAAM,KAAK,MAAM,GAAG,EAAE,CAAC;AAAA,MACtC;AAAA,IACD;AAAA,EACD;AACD;AAhQyC;AAAlC,IAAM,8BAAN","sourcesContent":["import { Result } from '@sapphire/framework';\nimport { container, getRootData } from '@sapphire/pieces';\nimport { isFunction, type Awaitable } from '@sapphire/utilities';\nimport { Backend, type PathResolvable } from '@skyra/i18next-backend';\nimport i18next, {\n\ttype AppendKeyPrefix,\n\ttype DefaultNamespace,\n\ttype InterpolationMap,\n\ttype Namespace,\n\ttype ParseKeys,\n\ttype TFunction,\n\ttype TFunctionReturn,\n\ttype TFunctionReturnOptionalDetails,\n\ttype TOptions\n} from 'i18next';\nimport type { PathLike } from 'node:fs';\nimport { opendir } from 'node:fs/promises';\nimport { join } from 'node:path';\nimport { URL, fileURLToPath } from 'node:url';\nimport type { $Dictionary, $SpecialObject, InternationalizationContext, InternationalizationOptions } from './types';\n\n/**\n * A generalized class for handling `i18next` JSON files and their discovery.\n * @since 1.0.0\n */\nexport class InternationalizationHandler {\n\t/**\n\t * Describes whether {@link InternationalizationHandler.init} has been run and languages are loaded in {@link InternationalizationHandler.languages}.\n\t * @since 1.0.0\n\t */\n\tpublic languagesLoaded = false;\n\n\t/**\n\t * A `Set` of initially loaded namespaces.\n\t * @since 1.2.0\n\t */\n\tpublic namespaces = new Set<string>();\n\n\t/**\n\t * A `Map` of `i18next` language functions keyed by their language code.\n\t * @since 1.0.0\n\t */\n\tpublic readonly languages = new Map<string, TFunction>();\n\n\t/**\n\t * The options InternationalizationHandler was initialized with in the client.\n\t * @since 1.0.0\n\t */\n\tpublic readonly options: InternationalizationOptions;\n\n\t/**\n\t * The director passed to `@skyra/i18next-backend`.\n\t * Also used in {@link InternationalizationHandler.walkLanguageDirectory}.\n\t * @since 1.2.0\n\t */\n\tpublic readonly languagesDirectory: string;\n\n\t/**\n\t * The backend options for `@skyra/i18next-backend` used by `i18next`.\n\t * @since 1.0.0\n\t */\n\tprotected readonly backendOptions: Backend.Options;\n\n\t/**\n\t * @param options The options that `i18next`, `@skyra/i18next-backend`, and {@link InternationalizationHandler} should use.\n\t * @since 1.0.0\n\t * @constructor\n\t */\n\tpublic constructor(options?: InternationalizationOptions) {\n\t\tthis.options = options ?? { i18next: { ignoreJSONStructure: false } };\n\n\t\tconst baseUserDirectory =\n\t\t\tcontainer.client?.options?.baseUserDirectory instanceof URL\n\t\t\t\t? fileURLToPath(container.client?.options?.baseUserDirectory)\n\t\t\t\t: container.client?.options?.baseUserDirectory;\n\n\t\tthis.languagesDirectory = this.options.defaultLanguageDirectory ?? join(baseUserDirectory ?? getRootData().root, 'languages');\n\n\t\tconst languagePaths = new Set<PathResolvable>([\n\t\t\tjoin(this.languagesDirectory, '{{lng}}', '{{ns}}.json'), //\n\t\t\t...(options?.backend?.paths ?? [])\n\t\t]);\n\n\t\tthis.backendOptions = {\n\t\t\tpaths: [...languagePaths],\n\t\t\t...this.options.backend\n\t\t};\n\n\t\tif (isFunction(this.options.fetchLanguage)) {\n\t\t\tthis.fetchLanguage = this.options.fetchLanguage;\n\t\t}\n\t}\n\n\t/**\n\t * The method to be overridden by the developer.\n\t *\n\t * @note In the event that fetchLanguage is not defined or returns null / undefined, the defaulting from {@link fetchLanguage} will be used.\n\t * @since 2.0.0\n\t * @return A string for the desired language or null for no match.\n\t * @see {@link fetchLanguage}\n\t * @example\n\t * ```typescript\n\t * // Always use the same language (no per-guild configuration):\n\t * container.i18n.fetchLanguage = () => 'en-US';\n\t * ```\n\t * @example\n\t * ```typescript\n\t * // Retrieving the language from an SQL database:\n\t * container.i18n.fetchLanguage = async (context) => {\n\t * const guild = await driver.getOne('SELECT language FROM public.guild WHERE id = $1', [context.guild.id]);\n\t * return guild?.language ?? 'en-US';\n\t * };\n\t * ```\n\t * @example\n\t * ```typescript\n\t * // Retrieving the language from an ORM:\n\t * container.i18n.fetchLanguage = async (context) => {\n\t * const guild = await driver.getRepository(GuildEntity).findOne({ id: context.guild.id });\n\t * return guild?.language ?? 'en-US';\n\t * };\n\t * ```\n\t * @example\n\t * ```typescript\n\t * // Retrieving the language on a per channel basis, e.g. per user or guild channel (ORM example but same principles apply):\n\t * container.i18n.fetchLanguage = async (context) => {\n\t * const channel = await driver.getRepository(ChannelEntity).findOne({ id: context.channel.id });\n\t * return channel?.language ?? 'en-US';\n\t * };\n\t * ```\n\t */\n\tpublic fetchLanguage: (context: InternationalizationContext) => Awaitable<string | null> = () => null;\n\n\t/**\n\t * Initializes the handler by loading in the namespaces, passing the data to i18next, and filling in the {@link InternationalizationHandler#languages}.\n\t * @since 1.0.0\n\t */\n\tpublic async init() {\n\t\tconst { namespaces, languages } = await this.walkRootDirectory(this.languagesDirectory);\n\t\tconst userOptions = isFunction(this.options.i18next) ? this.options.i18next(namespaces, languages) : this.options.i18next;\n\t\tconst ignoreJSONStructure = userOptions?.ignoreJSONStructure ?? false;\n\t\tconst skipOnVariables = userOptions?.interpolation?.skipOnVariables ?? false;\n\n\t\ti18next.use(Backend);\n\t\tawait i18next.init({\n\t\t\tbackend: this.backendOptions,\n\t\t\tfallbackLng: this.options.defaultName ?? 'en-US',\n\t\t\tinitImmediate: false,\n\t\t\tinterpolation: {\n\t\t\t\tescapeValue: false,\n\t\t\t\t...userOptions?.interpolation,\n\t\t\t\tskipOnVariables\n\t\t\t},\n\t\t\tload: 'all',\n\t\t\tdefaultNS: 'default',\n\t\t\tns: namespaces,\n\t\t\tpreload: languages,\n\t\t\t...userOptions,\n\t\t\tignoreJSONStructure\n\t\t});\n\n\t\tthis.namespaces = new Set(namespaces);\n\t\tfor (const item of languages) {\n\t\t\tthis.languages.set(item, i18next.getFixedT(item));\n\t\t}\n\t\tthis.languagesLoaded = true;\n\n\t\tconst formatter = i18next.services.formatter!;\n\t\tconst formatters = this.options.formatters ?? [];\n\t\tfor (const { name, format, cached } of formatters) {\n\t\t\tif (cached) formatter.addCached(name, format);\n\t\t\telse formatter.add(name, format);\n\t\t}\n\t}\n\n\t/**\n\t * Retrieve a raw TFunction from the passed locale.\n\t * @param locale The language to be used.\n\t * @since 1.0.0\n\t */\n\tpublic getT(locale: string) {\n\t\tif (!this.languagesLoaded) throw new Error('Cannot call this method until InternationalizationHandler#init has been called');\n\n\t\tconst t = this.languages.get(locale);\n\t\tif (t) return t;\n\t\tthrow new ReferenceError('Invalid language provided');\n\t}\n\n\t/**\n\t * Localizes a content given one or more keys and i18next options.\n\t * @since 2.0.0\n\t * @param locale The language to be used.\n\t * @param key The key or keys to retrieve the content from.\n\t * @param options The interpolation options.\n\t * @see {@link https://www.i18next.com/overview/api#t}\n\t * @returns The localized content.\n\t */\n\tpublic format<\n\t\tconst Key extends ParseKeys<Ns, TOpt, undefined>,\n\t\tconst TOpt extends TOptions = TOptions,\n\t\tNs extends Namespace = DefaultNamespace,\n\t\tRet extends TFunctionReturn<Ns, AppendKeyPrefix<Key, undefined>, TOpt> = TOpt['returnObjects'] extends true ? $SpecialObject : string,\n\t\tconst ActualOptions extends TOpt & InterpolationMap<Ret> = TOpt & InterpolationMap<Ret>\n\t>(\n\t\tlocale: string,\n\t\t...[key, defaultValueOrOptions, optionsOrUndefined]:\n\t\t\t| [key: Key | Key[], options?: ActualOptions]\n\t\t\t| [key: string | string[], options: TOpt & $Dictionary & { defaultValue: string }]\n\t\t\t| [key: string | string[], defaultValue: string | undefined, options?: TOpt & $Dictionary]\n\t): TFunctionReturnOptionalDetails<Ret, TOpt> {\n\t\tif (!this.languagesLoaded) throw new Error('Cannot call this method until InternationalizationHandler#init has been called');\n\n\t\tconst language = this.languages.get(locale);\n\t\tif (!language) throw new ReferenceError('Invalid language provided');\n\n\t\tconst defaultValue =\n\t\t\ttypeof defaultValueOrOptions === 'string'\n\t\t\t\t? defaultValueOrOptions\n\t\t\t\t: this.options.defaultMissingKey\n\t\t\t\t\t? language(this.options.defaultMissingKey, { replace: { key } })\n\t\t\t\t\t: '';\n\n\t\treturn language<Key, TOpt, Ret, ActualOptions>(key, { defaultValue, ...((optionsOrUndefined ?? {}) as TOpt) });\n\t}\n\n\t/**\n\t * @param directory The directory that should be walked.\n\t * @since 3.0.0\n\t */\n\tpublic async walkRootDirectory(directory: PathLike) {\n\t\tconst languages = new Set<string>();\n\t\tconst namespaces = new Set<string>();\n\n\t\tconst dir = await opendir(directory);\n\t\tfor await (const entry of dir) {\n\t\t\t// If the entry is not a directory, skip:\n\t\t\tif (!entry.isDirectory()) continue;\n\n\t\t\t// Load the directory:\n\t\t\tlanguages.add(entry.name);\n\n\t\t\tfor await (const namespace of this.walkLocaleDirectory(join(dir.path, entry.name), '')) {\n\t\t\t\tnamespaces.add(namespace);\n\t\t\t}\n\t\t}\n\n\t\treturn { namespaces: [...namespaces], languages: [...languages] };\n\t}\n\n\tpublic async reloadResources() {\n\t\tconst result = await Result.fromAsync(async () => {\n\t\t\tlet languages = this.options.hmr?.languages;\n\t\t\tlet namespaces = this.options.hmr?.namespaces;\n\t\t\tif (!languages || !namespaces) {\n\t\t\t\tconst languageDirectoryResult = await this.walkRootDirectory(this.languagesDirectory);\n\t\t\t\tlanguages ??= languageDirectoryResult.languages;\n\t\t\t\tnamespaces ??= languageDirectoryResult.namespaces;\n\t\t\t}\n\n\t\t\tawait i18next.reloadResources(languages, namespaces);\n\t\t\tcontainer.logger.info('[i18next-Plugin] Reloaded language resources.');\n\t\t});\n\n\t\tresult.inspectErr((error) => container.logger.error('[i18next-Plugin]: Failed to reload language resources.', error));\n\t}\n\n\t/**\n\t * @description Skips any files that don't end with `.json`.\n\t * @param directory The directory that should be walked.\n\t * @param ns The current namespace.\n\t * @since 3.0.0\n\t */\n\tprivate async *walkLocaleDirectory(directory: string, ns: string): AsyncGenerator<string> {\n\t\tconst dir = await opendir(directory);\n\t\tfor await (const entry of dir) {\n\t\t\tif (entry.isDirectory()) {\n\t\t\t\tyield* this.walkLocaleDirectory(join(dir.path, entry.name), `${ns}${entry.name}/`);\n\t\t\t} else if (entry.isFile() && entry.name.endsWith('.json')) {\n\t\t\t\tyield `${ns}${entry.name.slice(0, -5)}`;\n\t\t\t}\n\t\t}\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/InternationalizationHandler.ts"],"names":["container","URL","fileURLToPath","join","getRootData","isFunction","i18next","Backend","opendir","Result"],"mappings":";;;;;;;;;;;;;;;;;;;AAyBO,IAAM,4BAAA,GAAN,MAAM,4BAA4B,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EA2CjC,YAAY,OAAuC,EAAA;AAtC1D;AAAA;AAAA;AAAA;AAAA,IAAA,aAAA,CAAA,IAAA,EAAO,iBAAkB,EAAA,KAAA,CAAA,CAAA;AAMzB;AAAA;AAAA;AAAA;AAAA,IAAO,aAAA,CAAA,IAAA,EAAA,YAAA,sBAAiB,GAAY,EAAA,CAAA,CAAA;AAMpC;AAAA;AAAA;AAAA;AAAA,IAAgB,aAAA,CAAA,IAAA,EAAA,WAAA,sBAAgB,GAAuB,EAAA,CAAA,CAAA;AAMvD;AAAA;AAAA;AAAA;AAAA,IAAgB,aAAA,CAAA,IAAA,EAAA,SAAA,CAAA,CAAA;AAOhB;AAAA;AAAA;AAAA;AAAA;AAAA,IAAgB,aAAA,CAAA,IAAA,EAAA,oBAAA,CAAA,CAAA;AAMhB;AAAA;AAAA;AAAA;AAAA,IAAmB,aAAA,CAAA,IAAA,EAAA,gBAAA,CAAA,CAAA;AAqEnB;AAAA;AAAA;AAA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,EAAG,EAAE,CAAG,EAAA,KAAA,CAAM,KAAK,KAAM,CAAA,CAAA,EAAG,EAAE,CAAC,CAAA,CAAA,CAAA;AAAA,OACtC;AAAA,KACD;AAAA,GACD;AACD,CAAA,CAAA;AA5TyC,MAAA,CAAA,4BAAA,EAAA,6BAAA,CAAA,CAAA;AAAlC,IAAM,2BAAN,GAAA","file":"InternationalizationHandler.cjs","sourcesContent":["import { Result } from '@sapphire/framework';\nimport { container, getRootData } from '@sapphire/pieces';\nimport { isFunction, type Awaitable } from '@sapphire/utilities';\nimport { Backend, type PathResolvable } from '@skyra/i18next-backend';\nimport i18next, {\n\ttype AppendKeyPrefix,\n\ttype DefaultNamespace,\n\ttype InterpolationMap,\n\ttype Namespace,\n\ttype ParseKeys,\n\ttype TFunction,\n\ttype TFunctionReturn,\n\ttype TFunctionReturnOptionalDetails,\n\ttype TOptions\n} from 'i18next';\nimport type { PathLike } from 'node:fs';\nimport { opendir } from 'node:fs/promises';\nimport { join } from 'node:path';\nimport { URL, fileURLToPath } from 'node:url';\nimport type { $Dictionary, $SpecialObject, InternationalizationContext, InternationalizationOptions } from './types';\n\n/**\n * A generalized class for handling `i18next` JSON files and their discovery.\n * @since 1.0.0\n */\nexport class InternationalizationHandler {\n\t/**\n\t * Describes whether {@link InternationalizationHandler.init} has been run and languages are loaded in {@link InternationalizationHandler.languages}.\n\t * @since 1.0.0\n\t */\n\tpublic languagesLoaded = false;\n\n\t/**\n\t * A `Set` of initially loaded namespaces.\n\t * @since 1.2.0\n\t */\n\tpublic namespaces = new Set<string>();\n\n\t/**\n\t * A `Map` of `i18next` language functions keyed by their language code.\n\t * @since 1.0.0\n\t */\n\tpublic readonly languages = new Map<string, TFunction>();\n\n\t/**\n\t * The options InternationalizationHandler was initialized with in the client.\n\t * @since 1.0.0\n\t */\n\tpublic readonly options: InternationalizationOptions;\n\n\t/**\n\t * The director passed to `@skyra/i18next-backend`.\n\t * Also used in {@link InternationalizationHandler.walkLanguageDirectory}.\n\t * @since 1.2.0\n\t */\n\tpublic readonly languagesDirectory: string;\n\n\t/**\n\t * The backend options for `@skyra/i18next-backend` used by `i18next`.\n\t * @since 1.0.0\n\t */\n\tprotected readonly backendOptions: Backend.Options;\n\n\t/**\n\t * @param options The options that `i18next`, `@skyra/i18next-backend`, and {@link InternationalizationHandler} should use.\n\t * @since 1.0.0\n\t * @constructor\n\t */\n\tpublic constructor(options?: InternationalizationOptions) {\n\t\tthis.options = options ?? { i18next: { ignoreJSONStructure: false } };\n\n\t\tconst baseUserDirectory =\n\t\t\tcontainer.client?.options?.baseUserDirectory instanceof URL\n\t\t\t\t? fileURLToPath(container.client?.options?.baseUserDirectory)\n\t\t\t\t: container.client?.options?.baseUserDirectory;\n\n\t\tthis.languagesDirectory = this.options.defaultLanguageDirectory ?? join(baseUserDirectory ?? getRootData().root, 'languages');\n\n\t\tconst languagePaths = new Set<PathResolvable>([\n\t\t\tjoin(this.languagesDirectory, '{{lng}}', '{{ns}}.json'), //\n\t\t\t...(options?.backend?.paths ?? [])\n\t\t]);\n\n\t\tthis.backendOptions = {\n\t\t\tpaths: [...languagePaths],\n\t\t\t...this.options.backend\n\t\t};\n\n\t\tif (isFunction(this.options.fetchLanguage)) {\n\t\t\tthis.fetchLanguage = this.options.fetchLanguage;\n\t\t}\n\t}\n\n\t/**\n\t * The method to be overridden by the developer.\n\t *\n\t * @note In the event that fetchLanguage is not defined or returns null / undefined, the defaulting from {@link fetchLanguage} will be used.\n\t * @since 2.0.0\n\t * @return A string for the desired language or null for no match.\n\t * @see {@link fetchLanguage}\n\t * @example\n\t * ```typescript\n\t * // Always use the same language (no per-guild configuration):\n\t * container.i18n.fetchLanguage = () => 'en-US';\n\t * ```\n\t * @example\n\t * ```typescript\n\t * // Retrieving the language from an SQL database:\n\t * container.i18n.fetchLanguage = async (context) => {\n\t * const guild = await driver.getOne('SELECT language FROM public.guild WHERE id = $1', [context.guild.id]);\n\t * return guild?.language ?? 'en-US';\n\t * };\n\t * ```\n\t * @example\n\t * ```typescript\n\t * // Retrieving the language from an ORM:\n\t * container.i18n.fetchLanguage = async (context) => {\n\t * const guild = await driver.getRepository(GuildEntity).findOne({ id: context.guild.id });\n\t * return guild?.language ?? 'en-US';\n\t * };\n\t * ```\n\t * @example\n\t * ```typescript\n\t * // Retrieving the language on a per channel basis, e.g. per user or guild channel (ORM example but same principles apply):\n\t * container.i18n.fetchLanguage = async (context) => {\n\t * const channel = await driver.getRepository(ChannelEntity).findOne({ id: context.channel.id });\n\t * return channel?.language ?? 'en-US';\n\t * };\n\t * ```\n\t */\n\tpublic fetchLanguage: (context: InternationalizationContext) => Awaitable<string | null> = () => null;\n\n\t/**\n\t * Initializes the handler by loading in the namespaces, passing the data to i18next, and filling in the {@link InternationalizationHandler#languages}.\n\t * @since 1.0.0\n\t */\n\tpublic async init() {\n\t\tconst { namespaces, languages } = await this.walkRootDirectory(this.languagesDirectory);\n\t\tconst userOptions = isFunction(this.options.i18next) ? this.options.i18next(namespaces, languages) : this.options.i18next;\n\t\tconst ignoreJSONStructure = userOptions?.ignoreJSONStructure ?? false;\n\t\tconst skipOnVariables = userOptions?.interpolation?.skipOnVariables ?? false;\n\n\t\ti18next.use(Backend);\n\t\tawait i18next.init({\n\t\t\tbackend: this.backendOptions,\n\t\t\tfallbackLng: this.options.defaultName ?? 'en-US',\n\t\t\tinitImmediate: false,\n\t\t\tinterpolation: {\n\t\t\t\tescapeValue: false,\n\t\t\t\t...userOptions?.interpolation,\n\t\t\t\tskipOnVariables\n\t\t\t},\n\t\t\tload: 'all',\n\t\t\tdefaultNS: 'default',\n\t\t\tns: namespaces,\n\t\t\tpreload: languages,\n\t\t\t...userOptions,\n\t\t\tignoreJSONStructure\n\t\t});\n\n\t\tthis.namespaces = new Set(namespaces);\n\t\tfor (const item of languages) {\n\t\t\tthis.languages.set(item, i18next.getFixedT(item));\n\t\t}\n\t\tthis.languagesLoaded = true;\n\n\t\tconst formatter = i18next.services.formatter!;\n\t\tconst formatters = this.options.formatters ?? [];\n\t\tfor (const { name, format, cached } of formatters) {\n\t\t\tif (cached) formatter.addCached(name, format);\n\t\t\telse formatter.add(name, format);\n\t\t}\n\t}\n\n\t/**\n\t * Retrieve a raw TFunction from the passed locale.\n\t * @param locale The language to be used.\n\t * @since 1.0.0\n\t */\n\tpublic getT(locale: string) {\n\t\tif (!this.languagesLoaded) throw new Error('Cannot call this method until InternationalizationHandler#init has been called');\n\n\t\tconst t = this.languages.get(locale);\n\t\tif (t) return t;\n\t\tthrow new ReferenceError('Invalid language provided');\n\t}\n\n\t/**\n\t * Localizes a content given one or more keys and i18next options.\n\t * @since 2.0.0\n\t * @param locale The language to be used.\n\t * @param key The key or keys to retrieve the content from.\n\t * @param options The interpolation options.\n\t * @see {@link https://www.i18next.com/overview/api#t}\n\t * @returns The localized content.\n\t */\n\tpublic format<\n\t\tconst Key extends ParseKeys<Ns, TOpt, undefined>,\n\t\tconst TOpt extends TOptions = TOptions,\n\t\tNs extends Namespace = DefaultNamespace,\n\t\tRet extends TFunctionReturn<Ns, AppendKeyPrefix<Key, undefined>, TOpt> = TOpt['returnObjects'] extends true ? $SpecialObject : string,\n\t\tconst ActualOptions extends TOpt & InterpolationMap<Ret> = TOpt & InterpolationMap<Ret>\n\t>(locale: string, key: Key | Key[], options?: ActualOptions): TFunctionReturnOptionalDetails<Ret, TOpt>;\n\n\t/**\n\t * Localizes a content given one or more keys and i18next options.\n\t * @since 2.0.0\n\t * @param locale The language to be used.\n\t * @param key The key or keys to retrieve the content from.\n\t * @param options The interpolation options as well as a `defaultValue` for the key and any key/value pairs.\n\t * @see {@link https://www.i18next.com/overview/api#t}\n\t * @returns The localized content.\n\t */\n\tpublic format<\n\t\tconst Key extends ParseKeys<Ns, TOpt, undefined>,\n\t\tconst TOpt extends TOptions = TOptions,\n\t\tNs extends Namespace = DefaultNamespace,\n\t\tRet extends TFunctionReturn<Ns, AppendKeyPrefix<Key, undefined>, TOpt> = TOpt['returnObjects'] extends true ? $SpecialObject : string,\n\t\tconst ActualOptions extends TOpt & InterpolationMap<Ret> = TOpt & InterpolationMap<Ret>\n\t>(locale: string, key: string | string[], options: TOpt & $Dictionary & { defaultValue: string }): TFunctionReturnOptionalDetails<Ret, TOpt>;\n\n\t/**\n\t * Localizes a content given one or more keys and i18next options.\n\t * @since 2.0.0\n\t * @param locale The language to be used.\n\t * @param key The key or keys to retrieve the content from.\n\t * @param defaultValue The default value to use if the key is not found.\n\t * @param options The interpolation options.\n\t * @see {@link https://www.i18next.com/overview/api#t}\n\t * @returns The localized content.\n\t */\n\tpublic format<\n\t\tconst Key extends ParseKeys<Ns, TOpt, undefined>,\n\t\tconst TOpt extends TOptions = TOptions,\n\t\tNs extends Namespace = DefaultNamespace,\n\t\tRet extends TFunctionReturn<Ns, AppendKeyPrefix<Key, undefined>, TOpt> = TOpt['returnObjects'] extends true ? $SpecialObject : string,\n\t\tconst ActualOptions extends TOpt & InterpolationMap<Ret> = TOpt & InterpolationMap<Ret>\n\t>(\n\t\tlocale: string,\n\t\tkey: string | string[],\n\t\tdefaultValue: string | undefined,\n\t\toptions?: TOpt & $Dictionary\n\t): TFunctionReturnOptionalDetails<Ret, TOpt>;\n\n\t/**\n\t * Localizes a content given one or more keys and i18next options.\n\t * @since 2.0.0\n\t * @param locale The language to be used.\n\t *\n\t * @remark This function also has additional parameters for `key`, `defaultValue`, and `options`, however\n\t * TSDoc does not let us document those while matching proper implementation. See the overloads for this method\n\t * for the documentation on those parameters.\n\t *\n\t * @see {@link https://www.i18next.com/overview/api#t}\n\t * @returns The localized content.\n\t */\n\tpublic format<\n\t\tconst Key extends ParseKeys<Ns, TOpt, undefined>,\n\t\tconst TOpt extends TOptions = TOptions,\n\t\tNs extends Namespace = DefaultNamespace,\n\t\tRet extends TFunctionReturn<Ns, AppendKeyPrefix<Key, undefined>, TOpt> = TOpt['returnObjects'] extends true ? $SpecialObject : string,\n\t\tconst ActualOptions extends TOpt & InterpolationMap<Ret> = TOpt & InterpolationMap<Ret>\n\t>(\n\t\tlocale: string,\n\t\t...[key, defaultValueOrOptions, optionsOrUndefined]:\n\t\t\t| [key: Key | Key[], options?: ActualOptions]\n\t\t\t| [key: string | string[], options: TOpt & $Dictionary & { defaultValue: string }]\n\t\t\t| [key: string | string[], defaultValue: string | undefined, options?: TOpt & $Dictionary]\n\t): TFunctionReturnOptionalDetails<Ret, TOpt> {\n\t\tif (!this.languagesLoaded) throw new Error('Cannot call this method until InternationalizationHandler#init has been called');\n\n\t\tconst language = this.languages.get(locale);\n\t\tif (!language) throw new ReferenceError('Invalid language provided');\n\n\t\tconst defaultValue =\n\t\t\ttypeof defaultValueOrOptions === 'string'\n\t\t\t\t? defaultValueOrOptions\n\t\t\t\t: this.options.defaultMissingKey\n\t\t\t\t\t? language(this.options.defaultMissingKey, { replace: { key } })\n\t\t\t\t\t: '';\n\n\t\treturn language<Key, TOpt, Ret, ActualOptions>(key, { defaultValue, ...((optionsOrUndefined ?? {}) as TOpt) });\n\t}\n\n\t/**\n\t * @param directory The directory that should be walked.\n\t * @since 3.0.0\n\t */\n\tpublic async walkRootDirectory(directory: PathLike) {\n\t\tconst languages = new Set<string>();\n\t\tconst namespaces = new Set<string>();\n\n\t\tconst dir = await opendir(directory);\n\t\tfor await (const entry of dir) {\n\t\t\t// If the entry is not a directory, skip:\n\t\t\tif (!entry.isDirectory()) continue;\n\n\t\t\t// Load the directory:\n\t\t\tlanguages.add(entry.name);\n\n\t\t\tfor await (const namespace of this.walkLocaleDirectory(join(dir.path, entry.name), '')) {\n\t\t\t\tnamespaces.add(namespace);\n\t\t\t}\n\t\t}\n\n\t\treturn { namespaces: [...namespaces], languages: [...languages] };\n\t}\n\n\tpublic async reloadResources() {\n\t\tconst result = await Result.fromAsync(async () => {\n\t\t\tlet languages = this.options.hmr?.languages;\n\t\t\tlet namespaces = this.options.hmr?.namespaces;\n\t\t\tif (!languages || !namespaces) {\n\t\t\t\tconst languageDirectoryResult = await this.walkRootDirectory(this.languagesDirectory);\n\t\t\t\tlanguages ??= languageDirectoryResult.languages;\n\t\t\t\tnamespaces ??= languageDirectoryResult.namespaces;\n\t\t\t}\n\n\t\t\tawait i18next.reloadResources(languages, namespaces);\n\t\t\tcontainer.logger.info('[i18next-Plugin] Reloaded language resources.');\n\t\t});\n\n\t\tresult.inspectErr((error) => container.logger.error('[i18next-Plugin]: Failed to reload language resources.', error));\n\t}\n\n\t/**\n\t * @description Skips any files that don't end with `.json`.\n\t * @param directory The directory that should be walked.\n\t * @param ns The current namespace.\n\t * @since 3.0.0\n\t */\n\tprivate async *walkLocaleDirectory(directory: string, ns: string): AsyncGenerator<string> {\n\t\tconst dir = await opendir(directory);\n\t\tfor await (const entry of dir) {\n\t\t\tif (entry.isDirectory()) {\n\t\t\t\tyield* this.walkLocaleDirectory(join(dir.path, entry.name), `${ns}${entry.name}/`);\n\t\t\t} else if (entry.isFile() && entry.name.endsWith('.json')) {\n\t\t\t\tyield `${ns}${entry.name.slice(0, -5)}`;\n\t\t\t}\n\t\t}\n\t}\n}\n"]}
|
|
@@ -121,5 +121,5 @@ exports.fetchLanguage = fetchLanguage;
|
|
|
121
121
|
exports.fetchT = fetchT;
|
|
122
122
|
exports.getLocalizedData = getLocalizedData;
|
|
123
123
|
exports.resolveKey = resolveKey;
|
|
124
|
-
//# sourceMappingURL=
|
|
124
|
+
//# sourceMappingURL=functions.cjs.map
|
|
125
125
|
//# sourceMappingURL=functions.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/functions.ts"],"names":[],"mappings":";;;;AAAA,SAAS,iBAAiB;AAC1B,SAAS,YAAY;AACrB,SAAS,iBAAiB,aAAa,OAAO,QAAQ,eAA0E;AAkCzH,SAAS,cAAc,QAAiC;AAE9D,MAAI,kBAAkB,iBAAiB;AACtC,WAAO,gBAAgB;AAAA,MACtB,MAAM,OAAO;AAAA,MACb,SAAS,OAAO;AAAA,MAChB,OAAO,OAAO;AAAA,MACd,wBAAwB,OAAO;AAAA,MAC/B,mBAAmB,OAAO;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BAA4B,OAAO,aAAa;AAC7F;AARgB;AA8DT,SAAS,sBAKd,YAAe,QAA6G;AAG7H,QAAM,CAAC,YAAY,iBAAiB,IACnC,OAAO,WAAW,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC,QAAyB,GAAG,OAAO,CAAC,CAAC,aAA8B,IAAI;AAE3G,4BAA0B,SAAS,UAAU;AAC7C,mCAAiC,SAAS,iBAAiB;AAE3D,SAAO;AACR;AAfgB;AA4CT,SAAS,sBAMf,KACA,SAC+C;AAC/C,QAAM,SAAS,iBAAiB,GAAG;AAEnC,SAAO;AAAA,IACN,GAAG;AAAA,IACH,MAAM,OAAO;AAAA,IACb,oBAAoB,OAAO;AAAA,EAC5B;AACD;AAhBgB","sourcesContent":["import { container } from '@sapphire/pieces';\nimport { lazy } from '@sapphire/utilities';\nimport { BaseInteraction, ChannelType, Guild, Locale, Message, type APIApplicationCommandOptionChoice, type LocaleString } from 'discord.js';\nimport type {\n\tAppendKeyPrefix,\n\tDefaultNamespace,\n\tInterpolationMap,\n\tNamespace,\n\tParseKeys,\n\tTFunctionReturn,\n\tTFunctionReturnOptionalDetails,\n\tTOptions\n} from 'i18next';\nimport type {\n\t$Dictionary,\n\t$SpecialObject,\n\tBuilderWithDescription,\n\tBuilderWithName,\n\tBuilderWithNameAndDescription,\n\tInternationalizationContext,\n\tLocalizedData,\n\tTarget\n} from './types';\n\n/**\n * Retrieves the language name for a specific target, using {@link InternationalizationHandler.fetchLanguage}.\n * If {@link InternationalizationHandler.fetchLanguage} is not defined or this function returns a nullish value,\n * then there will be a series of fallback attempts in the following descending order:\n * 1. Returns {@link Guild.preferredLocale}.\n * 2. Returns {@link InternationalizationOptions.defaultName} if no guild was provided.\n * 3. Returns `'en-US'` if nothing else was found.\n * @since 2.0.0\n * @param target The target to fetch the language from.\n * @see {@link resolveLanguage}\n * @returns The name of the language key.\n */\nexport function fetchLanguage(target: Target): Promise<string> {\n\t// Handle Interactions:\n\tif (target instanceof BaseInteraction) {\n\t\treturn resolveLanguage({\n\t\t\tuser: target.user,\n\t\t\tchannel: target.channel,\n\t\t\tguild: target.guild,\n\t\t\tinteractionGuildLocale: target.guildLocale,\n\t\t\tinteractionLocale: target.locale\n\t\t});\n\t}\n\n\t// Handle Message:\n\tif (target instanceof Message) {\n\t\treturn resolveLanguage({ user: target.author, channel: target.channel, guild: target.guild });\n\t}\n\n\t// Handle Guild:\n\tif (target instanceof Guild) {\n\t\treturn resolveLanguage({ user: null, channel: null, guild: target });\n\t}\n\n\t// Handle DMChannel:\n\tif (target.type === ChannelType.DM) {\n\t\treturn resolveLanguage({ user: null, channel: target, guild: null });\n\t}\n\n\t// Handle any other channel:\n\treturn resolveLanguage({ user: null, channel: target, guild: target.guild });\n}\n\n/**\n * Retrieves the language-assigned function from i18next designated to a target's preferred language code.\n * @since 2.0.0\n * @param target The target to fetch the language from.\n * @returns The language function from i18next.\n */\nexport async function fetchT(target: Target) {\n\treturn container.i18n.getT(await fetchLanguage(target));\n}\n\n/**\n * Resolves a key and its parameters.\n * @since 2.0.0\n * @param target The target to fetch the language key from.\n * @param key The i18next key.\n * @param options The options to be passed to TFunction.\n * @returns The data that `key` held, processed by i18next.\n */\nexport async function resolveKey<\n\tconst Key extends ParseKeys<Ns, TOpt, undefined>,\n\tconst TOpt extends TOptions = TOptions,\n\tRet extends TFunctionReturn<Ns, AppendKeyPrefix<Key, undefined>, TOpt> = TOpt['returnObjects'] extends true ? $SpecialObject : string,\n\tNs extends Namespace = DefaultNamespace,\n\tconst ActualOptions extends TOpt & InterpolationMap<Ret> = TOpt & InterpolationMap<Ret>\n>(\n\ttarget: Target,\n\t...[key, defaultValueOrOptions, optionsOrUndefined]:\n\t\t| [key: Key | Key[], options?: ActualOptions]\n\t\t| [key: string | string[], options: TOpt & $Dictionary & { defaultValue: string }]\n\t\t| [key: string | string[], defaultValue: string, options?: TOpt & $Dictionary]\n): Promise<TFunctionReturnOptionalDetails<Ret, TOpt>> {\n\tconst parsedOptions = typeof defaultValueOrOptions === 'string' ? optionsOrUndefined : defaultValueOrOptions;\n\tconst language = typeof parsedOptions?.lng === 'string' ? parsedOptions.lng : await fetchLanguage(target);\n\n\tif (typeof defaultValueOrOptions === 'string') {\n\t\treturn container.i18n.format<Key, TOpt, Ns, Ret, ActualOptions>(language, key, defaultValueOrOptions, optionsOrUndefined);\n\t}\n\n\treturn container.i18n.format<Key, TOpt, Ns, Ret, ActualOptions>(language, key, undefined, defaultValueOrOptions);\n}\n\n/**\n * @internal\n */\nasync function resolveLanguage(context: InternationalizationContext): Promise<string> {\n\tconst lang = await container.i18n.fetchLanguage(context);\n\treturn lang ?? context.guild?.preferredLocale ?? container.i18n.options.defaultName ?? 'en-US';\n}\n\nconst supportedLanguages = new Set(Object.values(Locale)) as ReadonlySet<LocaleString>;\n\nfunction isSupportedDiscordLocale(language: string): language is LocaleString {\n\treturn supportedLanguages.has(language as LocaleString);\n}\n\nconst getLocales = lazy(() => {\n\tconst locales = new Map(container.i18n.languages);\n\n\tfor (const [locale] of locales) {\n\t\tif (!isSupportedDiscordLocale(locale)) {\n\t\t\tprocess.emitWarning('Unsupported Discord locale', {\n\t\t\t\tcode: 'UNSUPPORTED_LOCALE',\n\t\t\t\tdetail: `'${locale}' needs to be one of: ${[...locales.keys()]}`\n\t\t\t});\n\n\t\t\tlocales.delete(locale);\n\t\t}\n\n\t\tcontinue;\n\t}\n\n\treturn locales;\n});\n\nconst getDefaultT = lazy(() => {\n\tconst defaultLocale = container.i18n.options.defaultName ?? 'en-US';\n\n\tif (!isSupportedDiscordLocale(defaultLocale)) {\n\t\tthrow new TypeError(`Unsupported Discord locale found:\\n'${defaultLocale}' is not within the list of ${[...supportedLanguages]}`);\n\t}\n\n\tconst defaultT = getLocales().get(defaultLocale);\n\n\tif (defaultT) {\n\t\treturn defaultT;\n\t}\n\n\tthrow new TypeError(`Could not find ${defaultLocale}`);\n});\n\n/**\n * Gets the value and the localizations from a language key.\n * @param key The key to get the localizations from.\n * @returns The retrieved data.\n * @remarks This should be called **strictly** after loading the locales.\n */\nexport function getLocalizedData<const TOpt extends TOptions = TOptions, Ns extends Namespace = DefaultNamespace, KPrefix = undefined>(\n\tkey: ParseKeys<Ns, TOpt, KPrefix>\n): LocalizedData {\n\tconst locales = getLocales();\n\tconst defaultT = getDefaultT();\n\n\treturn {\n\t\tvalue: defaultT(key),\n\t\tlocalizations: Object.fromEntries(Array.from(locales, ([locale, t]) => [locale, t(key)]))\n\t};\n}\n\n/**\n * Applies the localized names on the builder, calling `setName` and `setNameLocalizations`.\n * @param builder The builder to apply the localizations to.\n * @param key The key to get the localizations from.\n * @returns The updated builder.\n */\nexport function applyNameLocalizedBuilder<\n\tT extends BuilderWithName,\n\tconst TOpt extends TOptions = TOptions,\n\tNs extends Namespace = DefaultNamespace,\n\tKPrefix = undefined\n>(builder: T, key: ParseKeys<Ns, TOpt, KPrefix>) {\n\tconst result = getLocalizedData(key);\n\treturn builder.setName(result.value).setNameLocalizations(result.localizations);\n}\n\n/**\n * Applies the localized descriptions on the builder, calling `setDescription` and `setDescriptionLocalizations`.\n * @param builder The builder to apply the localizations to.\n * @param key The key to get the localizations from.\n * @returns The updated builder.\n */\nexport function applyDescriptionLocalizedBuilder<\n\tT extends BuilderWithDescription,\n\tconst TOpt extends TOptions = TOptions,\n\tNs extends Namespace = DefaultNamespace,\n\tKPrefix = undefined\n>(builder: T, key: ParseKeys<Ns, TOpt, KPrefix>) {\n\tconst result = getLocalizedData(key);\n\treturn builder.setDescription(result.value).setDescriptionLocalizations(result.localizations);\n}\n\n/**\n * Applies the localized names and descriptions on the builder, calling {@link applyNameLocalizedBuilder} and\n * {@link applyDescriptionLocalizedBuilder}.\n *\n * @param builder The builder to apply the localizations to.\n *\n * @param params The root key or the key for the name and description keys.\n * This needs to be either 1 or 2 parameters.\n * See examples below for more information.\n *\n * @returns The updated builder. You can chain subsequent builder methods on this.\n *\n * @remarks If only 2 parameters were passed, then this function will automatically append `Name` and `Description`\n * to the root-key (wherein `root-key` is second parameter in the function, after `builder`)\n * passed through the second parameter.\n *\n * For example given `applyLocalizedBuilder(builder, 'userinfo')` the localized options will use the i18next keys\n * `userinfoName` and `userinfoDescription`.\n *\n * In the following example we provide all parameters and add a User Option\n * `applyLocalizedBuilder` needs either\n * @example\n * ```typescript\n * class UserInfoCommand extends Command {\n * public registerApplicationCommands(registry: ChatInputCommand.Registry) {\n * registry.registerChatInputCommand(\n * (builder) =>\n * applyLocalizedBuilder(builder, 'commands/names:userinfo', 'commands/descriptions:userinfo')\n * .addUserOption(\n * (input) => applyLocalizedBuilder(input, 'commands/options:userinfo-name', 'commands/options:userinfo-description').setRequired(true)\n * )\n * );\n * }\n * }\n * ```\n *\n * In the following example we provide single root keys which means `Name` and `Description` get appended as mentioned above.\n * @example\n * ```typescript\n * class UserInfoCommand extends Command {\n * public registerApplicationCommands(registry: ChatInputCommand.Registry) {\n * registry.registerChatInputCommand(\n * (builder) =>\n * applyLocalizedBuilder(builder, 'commands:userinfo')\n * .addUserOption(\n * (input) => applyLocalizedBuilder(input, 'options:userinfo').setRequired(true)\n * )\n * );\n * }\n * }\n * ```\n */\nexport function applyLocalizedBuilder<\n\tT extends BuilderWithNameAndDescription,\n\tconst TOpt extends TOptions = TOptions,\n\tNs extends Namespace = DefaultNamespace,\n\tKPrefix = undefined\n>(builder: T, ...params: [root: string] | [name: ParseKeys<Ns, TOpt, KPrefix>, description: ParseKeys<Ns, TOpt, KPrefix>]): T {\n\ttype LocalKeysType = ParseKeys<Ns, TOpt, KPrefix>;\n\n\tconst [localeName, localeDescription] =\n\t\tparams.length === 1 ? [`${params[0]}Name` as LocalKeysType, `${params[0]}Description` as LocalKeysType] : params;\n\n\tapplyNameLocalizedBuilder(builder, localeName);\n\tapplyDescriptionLocalizedBuilder(builder, localeDescription);\n\n\treturn builder;\n}\n\n/**\n * Constructs an object that can be passed into `setChoices` for String or Number option with localized names.\n *\n * @param key The i18next key for the name of the select option name.\n * @param options The additional Select Menu options. This should _at least_ include the `value` key.\n * @returns An object with anything provided through {@link createLocalizedChoice.options} with `name` and `name_localizations` added.\n *\n * @example\n * ```typescript\n * export class TypeCommand extends Command {\n * public override registerApplicationCommands(registry: ChatInputCommand.Registry) {\n * registry.registerChatInputCommand((builder) =>\n * applyLocalizedBuilder(builder, 'commands/names:type').addStringOption((option) =>\n * applyLocalizedBuilder(option, 'commands/options:type')\n * .setRequired(true)\n * .setChoices(\n * createLocalizedChoice('selects/pokemon:type-grass', { value: 'grass' }),\n * createLocalizedChoice('selects/pokemon:type-water', { value: 'water' }),\n * createLocalizedChoice('selects/pokemon:type-fire', { value: 'fire' }),\n * createLocalizedChoice('selects/pokemon:type-electric', { value: 'electric' })\n * )\n * )\n * );\n * }\n * }\n * ```\n */\nexport function createLocalizedChoice<\n\tValueType = string | number,\n\tconst TOpt extends TOptions = TOptions,\n\tNs extends Namespace = DefaultNamespace,\n\tKPrefix = undefined\n>(\n\tkey: ParseKeys<Ns, TOpt, KPrefix>,\n\toptions: Omit<APIApplicationCommandOptionChoice<ValueType>, 'name' | 'name_localizations'>\n): APIApplicationCommandOptionChoice<ValueType> {\n\tconst result = getLocalizedData(key);\n\n\treturn {\n\t\t...options,\n\t\tname: result.value,\n\t\tname_localizations: result.localizations\n\t};\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/functions.ts"],"names":["BaseInteraction","Message","Guild","ChannelType","container","Locale","lazy"],"mappings":";;;;;;;;AAoCO,SAAS,cAAc,MAAiC,EAAA;AAE9D,EAAA,IAAI,kBAAkBA,0BAAiB,EAAA;AACtC,IAAA,OAAO,eAAgB,CAAA;AAAA,MACtB,MAAM,MAAO,CAAA,IAAA;AAAA,MACb,SAAS,MAAO,CAAA,OAAA;AAAA,MAChB,OAAO,MAAO,CAAA,KAAA;AAAA,MACd,wBAAwB,MAAO,CAAA,WAAA;AAAA,MAC/B,mBAAmB,MAAO,CAAA,MAAA;AAAA,KAC1B,CAAA,CAAA;AAAA,GACF;AAGA,EAAA,IAAI,kBAAkBC,kBAA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,CAAA,aAAA;AAAA,GAC5B,CAAA;AACD,CAAA;AAhBgB,MAAA,CAAA,qBAAA,EAAA,uBAAA,CAAA","file":"functions.cjs","sourcesContent":["import { container } from '@sapphire/pieces';\nimport { lazy } from '@sapphire/utilities';\nimport { BaseInteraction, ChannelType, Guild, Locale, Message, type APIApplicationCommandOptionChoice, type LocaleString } from 'discord.js';\nimport type {\n\tAppendKeyPrefix,\n\tDefaultNamespace,\n\tInterpolationMap,\n\tNamespace,\n\tParseKeys,\n\tTFunctionReturn,\n\tTFunctionReturnOptionalDetails,\n\tTOptions\n} from 'i18next';\nimport type {\n\t$Dictionary,\n\t$SpecialObject,\n\tBuilderWithDescription,\n\tBuilderWithName,\n\tBuilderWithNameAndDescription,\n\tInternationalizationContext,\n\tLocalizedData,\n\tTarget\n} from './types';\n\n/**\n * Retrieves the language name for a specific target, using {@link InternationalizationHandler.fetchLanguage}.\n * If {@link InternationalizationHandler.fetchLanguage} is not defined or this function returns a nullish value,\n * then there will be a series of fallback attempts in the following descending order:\n * 1. Returns {@link Guild.preferredLocale}.\n * 2. Returns {@link InternationalizationOptions.defaultName} if no guild was provided.\n * 3. Returns `'en-US'` if nothing else was found.\n * @since 2.0.0\n * @param target The target to fetch the language from.\n * @see {@link resolveLanguage}\n * @returns The name of the language key.\n */\nexport function fetchLanguage(target: Target): Promise<string> {\n\t// Handle Interactions:\n\tif (target instanceof BaseInteraction) {\n\t\treturn resolveLanguage({\n\t\t\tuser: target.user,\n\t\t\tchannel: target.channel,\n\t\t\tguild: target.guild,\n\t\t\tinteractionGuildLocale: target.guildLocale,\n\t\t\tinteractionLocale: target.locale\n\t\t});\n\t}\n\n\t// Handle Message:\n\tif (target instanceof Message) {\n\t\treturn resolveLanguage({ user: target.author, channel: target.channel, guild: target.guild });\n\t}\n\n\t// Handle Guild:\n\tif (target instanceof Guild) {\n\t\treturn resolveLanguage({ user: null, channel: null, guild: target });\n\t}\n\n\t// Handle DMChannel:\n\tif (target.type === ChannelType.DM) {\n\t\treturn resolveLanguage({ user: null, channel: target, guild: null });\n\t}\n\n\t// Handle any other channel:\n\treturn resolveLanguage({ user: null, channel: target, guild: target.guild });\n}\n\n/**\n * Retrieves the language-assigned function from i18next designated to a target's preferred language code.\n * @since 2.0.0\n * @param target The target to fetch the language from.\n * @returns The language function from i18next.\n */\nexport async function fetchT(target: Target) {\n\treturn container.i18n.getT(await fetchLanguage(target));\n}\n\n/**\n * Resolves a key and its parameters.\n * @since 2.0.0\n * @param target The target to fetch the language key from.\n * @param key The i18next key.\n * @param options The options to be passed to TFunction.\n * @returns The data that `key` held, processed by i18next.\n */\nexport async function resolveKey<\n\tconst Key extends ParseKeys<Ns, TOpt, undefined>,\n\tconst TOpt extends TOptions = TOptions,\n\tRet extends TFunctionReturn<Ns, AppendKeyPrefix<Key, undefined>, TOpt> = TOpt['returnObjects'] extends true ? $SpecialObject : string,\n\tNs extends Namespace = DefaultNamespace,\n\tconst ActualOptions extends TOpt & InterpolationMap<Ret> = TOpt & InterpolationMap<Ret>\n>(target: Target, key: Key | Key[], options?: ActualOptions): Promise<TFunctionReturnOptionalDetails<Ret, TOpt>>;\n\n/**\n * Resolves a key and its parameters.\n * @since 2.0.0\n * @param target The target to fetch the language key from.\n * @param key The i18next key.\n * @param options The interpolation options as well as a `defaultValue` for the key and any key/value pairs.\n * @returns The data that `key` held, processed by i18next.\n */\nexport async function resolveKey<\n\tconst Key extends ParseKeys<Ns, TOpt, undefined>,\n\tconst TOpt extends TOptions = TOptions,\n\tRet extends TFunctionReturn<Ns, AppendKeyPrefix<Key, undefined>, TOpt> = TOpt['returnObjects'] extends true ? $SpecialObject : string,\n\tNs extends Namespace = DefaultNamespace,\n\tconst ActualOptions extends TOpt & InterpolationMap<Ret> = TOpt & InterpolationMap<Ret>\n>(target: Target, key: string | string[], options: TOpt & $Dictionary & { defaultValue: string }): Promise<TFunctionReturnOptionalDetails<Ret, TOpt>>;\n\n/**\n * Resolves a key and its parameters.\n * @since 2.0.0\n * @param target The target to fetch the language key from.\n * @param key The i18next key.\n * @param defaultValue The default value to use if the key is not found.\n * @param options The interpolation options.\n * @returns The data that `key` held, processed by i18next.\n */\nexport async function resolveKey<\n\tconst Key extends ParseKeys<Ns, TOpt, undefined>,\n\tconst TOpt extends TOptions = TOptions,\n\tRet extends TFunctionReturn<Ns, AppendKeyPrefix<Key, undefined>, TOpt> = TOpt['returnObjects'] extends true ? $SpecialObject : string,\n\tNs extends Namespace = DefaultNamespace,\n\tconst ActualOptions extends TOpt & InterpolationMap<Ret> = TOpt & InterpolationMap<Ret>\n>(target: Target, key: string | string[], defaultValue: string, options?: TOpt & $Dictionary): Promise<TFunctionReturnOptionalDetails<Ret, TOpt>>;\n\n/**\n * Resolves a key and its parameters.\n * @since 2.0.0\n * @param target The target to fetch the language key from.\n *\n * @remark This function also has additional parameters for `key`, `defaultValue`, and `options`, however\n * TSDoc does not let us document those while matching proper implementation. See the overloads for this method\n * for the documentation on those parameters.\n *\n * @returns The data that `key` held, processed by i18next.\n */\nexport async function resolveKey<\n\tconst Key extends ParseKeys<Ns, TOpt, undefined>,\n\tconst TOpt extends TOptions = TOptions,\n\tRet extends TFunctionReturn<Ns, AppendKeyPrefix<Key, undefined>, TOpt> = TOpt['returnObjects'] extends true ? $SpecialObject : string,\n\tNs extends Namespace = DefaultNamespace,\n\tconst ActualOptions extends TOpt & InterpolationMap<Ret> = TOpt & InterpolationMap<Ret>\n>(\n\ttarget: Target,\n\t...[key, defaultValueOrOptions, optionsOrUndefined]:\n\t\t| [key: Key | Key[], options?: ActualOptions]\n\t\t| [key: string | string[], options: TOpt & $Dictionary & { defaultValue: string }]\n\t\t| [key: string | string[], defaultValue: string, options?: TOpt & $Dictionary]\n): Promise<TFunctionReturnOptionalDetails<Ret, TOpt>> {\n\tconst parsedOptions = typeof defaultValueOrOptions === 'string' ? optionsOrUndefined : defaultValueOrOptions;\n\tconst language = typeof parsedOptions?.lng === 'string' ? parsedOptions.lng : await fetchLanguage(target);\n\n\tif (typeof defaultValueOrOptions === 'string') {\n\t\treturn container.i18n.format<Key, TOpt, Ns, Ret, ActualOptions>(language, key, defaultValueOrOptions, optionsOrUndefined);\n\t}\n\n\treturn container.i18n.format<Key, TOpt, Ns, Ret, ActualOptions>(language, key, undefined, defaultValueOrOptions);\n}\n\n/**\n * @internal\n */\nasync function resolveLanguage(context: InternationalizationContext): Promise<string> {\n\tconst lang = await container.i18n.fetchLanguage(context);\n\treturn lang ?? context.guild?.preferredLocale ?? container.i18n.options.defaultName ?? 'en-US';\n}\n\nconst supportedLanguages = new Set(Object.values(Locale)) as ReadonlySet<LocaleString>;\n\nfunction isSupportedDiscordLocale(language: string): language is LocaleString {\n\treturn supportedLanguages.has(language as LocaleString);\n}\n\nconst getLocales = lazy(() => {\n\tconst locales = new Map(container.i18n.languages);\n\n\tfor (const [locale] of locales) {\n\t\tif (!isSupportedDiscordLocale(locale)) {\n\t\t\tprocess.emitWarning('Unsupported Discord locale', {\n\t\t\t\tcode: 'UNSUPPORTED_LOCALE',\n\t\t\t\tdetail: `'${locale}' needs to be one of: ${[...locales.keys()]}`\n\t\t\t});\n\n\t\t\tlocales.delete(locale);\n\t\t}\n\n\t\tcontinue;\n\t}\n\n\treturn locales;\n});\n\nconst getDefaultT = lazy(() => {\n\tconst defaultLocale = container.i18n.options.defaultName ?? 'en-US';\n\n\tif (!isSupportedDiscordLocale(defaultLocale)) {\n\t\tthrow new TypeError(`Unsupported Discord locale found:\\n'${defaultLocale}' is not within the list of ${[...supportedLanguages]}`);\n\t}\n\n\tconst defaultT = getLocales().get(defaultLocale);\n\n\tif (defaultT) {\n\t\treturn defaultT;\n\t}\n\n\tthrow new TypeError(`Could not find ${defaultLocale}`);\n});\n\n/**\n * Gets the value and the localizations from a language key.\n * @param key The key to get the localizations from.\n * @returns The retrieved data.\n * @remarks This should be called **strictly** after loading the locales.\n */\nexport function getLocalizedData<const TOpt extends TOptions = TOptions, Ns extends Namespace = DefaultNamespace, KPrefix = undefined>(\n\tkey: ParseKeys<Ns, TOpt, KPrefix>\n): LocalizedData {\n\tconst locales = getLocales();\n\tconst defaultT = getDefaultT();\n\n\treturn {\n\t\tvalue: defaultT(key),\n\t\tlocalizations: Object.fromEntries(Array.from(locales, ([locale, t]) => [locale, t(key)]))\n\t};\n}\n\n/**\n * Applies the localized names on the builder, calling `setName` and `setNameLocalizations`.\n * @param builder The builder to apply the localizations to.\n * @param key The key to get the localizations from.\n * @returns The updated builder.\n */\nexport function applyNameLocalizedBuilder<\n\tT extends BuilderWithName,\n\tconst TOpt extends TOptions = TOptions,\n\tNs extends Namespace = DefaultNamespace,\n\tKPrefix = undefined\n>(builder: T, key: ParseKeys<Ns, TOpt, KPrefix>) {\n\tconst result = getLocalizedData(key);\n\treturn builder.setName(result.value).setNameLocalizations(result.localizations);\n}\n\n/**\n * Applies the localized descriptions on the builder, calling `setDescription` and `setDescriptionLocalizations`.\n * @param builder The builder to apply the localizations to.\n * @param key The key to get the localizations from.\n * @returns The updated builder.\n */\nexport function applyDescriptionLocalizedBuilder<\n\tT extends BuilderWithDescription,\n\tconst TOpt extends TOptions = TOptions,\n\tNs extends Namespace = DefaultNamespace,\n\tKPrefix = undefined\n>(builder: T, key: ParseKeys<Ns, TOpt, KPrefix>) {\n\tconst result = getLocalizedData(key);\n\treturn builder.setDescription(result.value).setDescriptionLocalizations(result.localizations);\n}\n\n/**\n * Applies the localized names and descriptions on the builder, calling {@link applyNameLocalizedBuilder} and\n * {@link applyDescriptionLocalizedBuilder}.\n *\n * @param builder The builder to apply the localizations to.\n *\n * @param params The root key or the key for the name and description keys.\n * This needs to be either 1 or 2 parameters.\n * See examples below for more information.\n *\n * @returns The updated builder. You can chain subsequent builder methods on this.\n *\n * @remarks If only 2 parameters were passed, then this function will automatically append `Name` and `Description`\n * to the root-key (wherein `root-key` is second parameter in the function, after `builder`)\n * passed through the second parameter.\n *\n * For example given `applyLocalizedBuilder(builder, 'userinfo')` the localized options will use the i18next keys\n * `userinfoName` and `userinfoDescription`.\n *\n * In the following example we provide all parameters and add a User Option\n * `applyLocalizedBuilder` needs either\n * @example\n * ```typescript\n * class UserInfoCommand extends Command {\n * public registerApplicationCommands(registry: ChatInputCommand.Registry) {\n * registry.registerChatInputCommand(\n * (builder) =>\n * applyLocalizedBuilder(builder, 'commands/names:userinfo', 'commands/descriptions:userinfo')\n * .addUserOption(\n * (input) => applyLocalizedBuilder(input, 'commands/options:userinfo-name', 'commands/options:userinfo-description').setRequired(true)\n * )\n * );\n * }\n * }\n * ```\n *\n * In the following example we provide single root keys which means `Name` and `Description` get appended as mentioned above.\n * @example\n * ```typescript\n * class UserInfoCommand extends Command {\n * public registerApplicationCommands(registry: ChatInputCommand.Registry) {\n * registry.registerChatInputCommand(\n * (builder) =>\n * applyLocalizedBuilder(builder, 'commands:userinfo')\n * .addUserOption(\n * (input) => applyLocalizedBuilder(input, 'options:userinfo').setRequired(true)\n * )\n * );\n * }\n * }\n * ```\n */\nexport function applyLocalizedBuilder<\n\tT extends BuilderWithNameAndDescription,\n\tconst TOpt extends TOptions = TOptions,\n\tNs extends Namespace = DefaultNamespace,\n\tKPrefix = undefined\n>(builder: T, ...params: [root: string] | [name: ParseKeys<Ns, TOpt, KPrefix>, description: ParseKeys<Ns, TOpt, KPrefix>]): T {\n\ttype LocalKeysType = ParseKeys<Ns, TOpt, KPrefix>;\n\n\tconst [localeName, localeDescription] =\n\t\tparams.length === 1 ? [`${params[0]}Name` as LocalKeysType, `${params[0]}Description` as LocalKeysType] : params;\n\n\tapplyNameLocalizedBuilder(builder, localeName);\n\tapplyDescriptionLocalizedBuilder(builder, localeDescription);\n\n\treturn builder;\n}\n\n/**\n * Constructs an object that can be passed into `setChoices` for String or Number option with localized names.\n *\n * @param key The i18next key for the name of the select option name.\n * @param options The additional Select Menu options. This should _at least_ include the `value` key.\n * @returns An object with anything provided through {@link createLocalizedChoice.options} with `name` and `name_localizations` added.\n *\n * @example\n * ```typescript\n * export class TypeCommand extends Command {\n * public override registerApplicationCommands(registry: ChatInputCommand.Registry) {\n * registry.registerChatInputCommand((builder) =>\n * applyLocalizedBuilder(builder, 'commands/names:type').addStringOption((option) =>\n * applyLocalizedBuilder(option, 'commands/options:type')\n * .setRequired(true)\n * .setChoices(\n * createLocalizedChoice('selects/pokemon:type-grass', { value: 'grass' }),\n * createLocalizedChoice('selects/pokemon:type-water', { value: 'water' }),\n * createLocalizedChoice('selects/pokemon:type-fire', { value: 'fire' }),\n * createLocalizedChoice('selects/pokemon:type-electric', { value: 'electric' })\n * )\n * )\n * );\n * }\n * }\n * ```\n */\nexport function createLocalizedChoice<\n\tValueType = string | number,\n\tconst TOpt extends TOptions = TOptions,\n\tNs extends Namespace = DefaultNamespace,\n\tKPrefix = undefined\n>(\n\tkey: ParseKeys<Ns, TOpt, KPrefix>,\n\toptions: Omit<APIApplicationCommandOptionChoice<ValueType>, 'name' | 'name_localizations'>\n): APIApplicationCommandOptionChoice<ValueType> {\n\tconst result = getLocalizedData(key);\n\n\treturn {\n\t\t...options,\n\t\tname: result.value,\n\t\tname_localizations: result.localizations\n\t};\n}\n"]}
|
package/dist/cjs/lib/types.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"types.cjs"}
|
package/dist/cjs/register.cjs
CHANGED
|
@@ -17,8 +17,7 @@ var _I18nextPlugin = class _I18nextPlugin extends framework.Plugin {
|
|
|
17
17
|
if (this.options.i18n?.hmr?.enabled) {
|
|
18
18
|
framework.container.logger.info("[i18next-Plugin]: HMR enabled. Watching for languages changes.");
|
|
19
19
|
const hmr = chokidar.watch(framework.container.i18n.languagesDirectory, this.options.i18n.hmr.options);
|
|
20
|
-
for (const event of ["change", "unlink"])
|
|
21
|
-
hmr.on(event, () => framework.container.i18n.reloadResources());
|
|
20
|
+
for (const event of ["change", "unlink"]) hmr.on(event, () => framework.container.i18n.reloadResources());
|
|
22
21
|
}
|
|
23
22
|
}
|
|
24
23
|
};
|
|
@@ -29,5 +28,5 @@ framework.SapphireClient.plugins.registerPreLoginHook(I18nextPlugin[framework.pr
|
|
|
29
28
|
framework.SapphireClient.plugins.registerPostLoginHook(I18nextPlugin[framework.postLogin], "I18next-PostLogin");
|
|
30
29
|
|
|
31
30
|
exports.I18nextPlugin = I18nextPlugin;
|
|
32
|
-
//# sourceMappingURL=
|
|
31
|
+
//# sourceMappingURL=register.cjs.map
|
|
33
32
|
//# sourceMappingURL=register.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/register.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../src/register.ts"],"names":["Plugin","preGenericsInitialization","container","InternationalizationHandler","preLogin","postLogin","watch","SapphireClient"],"mappings":";;;;;;;;AAOO,IAAM,cAAA,GAAN,MAAM,cAAA,SAAsBA,gBAAO,CAAA;AAAA,EACzC,QAAeC,mCAAyB,CAAA,CAAwB,OAA8B,EAAA;AAC7F,IAAAC,mBAAA,CAAU,IAAO,GAAA,IAAIC,qCAA4B,CAAA,OAAA,CAAQ,IAAI,CAAA,CAAA;AAAA,GAC9D;AAAA,EAEA,cAAqBC,kBAAQ,CAAuC,GAAA;AACnE,IAAM,MAAAF,mBAAA,CAAU,KAAK,IAAK,EAAA,CAAA;AAAA,GAC3B;AAAA,EAEA,QAAeG,mBAAS,CAA8B,GAAA;AACrD,IAAA,IAAI,IAAK,CAAA,OAAA,CAAQ,IAAM,EAAA,GAAA,EAAK,OAAS,EAAA;AACpC,MAAUH,mBAAA,CAAA,MAAA,CAAO,KAAK,gEAAgE,CAAA,CAAA;AACtF,MAAM,MAAA,GAAA,GAAMI,eAAMJ,mBAAU,CAAA,IAAA,CAAK,oBAAoB,IAAK,CAAA,OAAA,CAAQ,IAAK,CAAA,GAAA,CAAI,OAAO,CAAA,CAAA;AAElF,MAAA,KAAA,MAAW,KAAS,IAAA,CAAC,QAAU,EAAA,QAAQ,CAAG,EAAA,GAAA,CAAI,EAAG,CAAA,KAAA,EAAO,MAAMA,mBAAA,CAAU,IAAK,CAAA,eAAA,EAAiB,CAAA,CAAA;AAAA,KAC/F;AAAA,GACD;AACD,CAAA,CAAA;AAjB0C,MAAA,CAAA,cAAA,EAAA,eAAA,CAAA,CAAA;AAAnC,IAAM,aAAN,GAAA,eAAA;AAmBPK,wBAAA,CAAe,OAAQ,CAAA,8BAAA,CAA+B,aAAc,CAAAN,mCAAyB,GAAG,mCAAmC,CAAA,CAAA;AACnIM,wBAAA,CAAe,OAAQ,CAAA,oBAAA,CAAqB,aAAc,CAAAH,kBAAQ,GAAG,kBAAkB,CAAA,CAAA;AACvFG,wBAAA,CAAe,OAAQ,CAAA,qBAAA,CAAsB,aAAc,CAAAF,mBAAS,GAAG,mBAAmB,CAAA","file":"register.cjs","sourcesContent":["import './index';\n\nimport { Plugin, SapphireClient, container, postLogin, preGenericsInitialization, preLogin } from '@sapphire/framework';\nimport { watch } from 'chokidar';\nimport type { ClientOptions } from 'discord.js';\nimport { InternationalizationHandler } from './index';\n\nexport class I18nextPlugin extends Plugin {\n\tpublic static [preGenericsInitialization](this: SapphireClient, options: ClientOptions): void {\n\t\tcontainer.i18n = new InternationalizationHandler(options.i18n);\n\t}\n\n\tpublic static async [preLogin](this: SapphireClient): Promise<void> {\n\t\tawait container.i18n.init();\n\t}\n\n\tpublic static [postLogin](this: SapphireClient): void {\n\t\tif (this.options.i18n?.hmr?.enabled) {\n\t\t\tcontainer.logger.info('[i18next-Plugin]: HMR enabled. Watching for languages changes.');\n\t\t\tconst hmr = watch(container.i18n.languagesDirectory, this.options.i18n.hmr.options);\n\n\t\t\tfor (const event of ['change', 'unlink']) hmr.on(event, () => container.i18n.reloadResources());\n\t\t}\n\t}\n}\n\nSapphireClient.plugins.registerPostInitializationHook(I18nextPlugin[preGenericsInitialization], 'I18next-PreGenericsInitialization');\nSapphireClient.plugins.registerPreLoginHook(I18nextPlugin[preLogin], 'I18next-PreLogin');\nSapphireClient.plugins.registerPostLoginHook(I18nextPlugin[postLogin], 'I18next-PostLogin');\n"]}
|
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
3
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
4
|
-
var __publicField = (obj, key, value) =>
|
|
5
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
6
|
-
return value;
|
|
7
|
-
};
|
|
4
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
8
5
|
|
|
9
6
|
export { __name, __publicField };
|
|
10
|
-
//# sourceMappingURL=
|
|
11
|
-
//# sourceMappingURL=chunk-
|
|
7
|
+
//# sourceMappingURL=chunk-2JTKI4GS.mjs.map
|
|
8
|
+
//# sourceMappingURL=chunk-2JTKI4GS.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"chunk-2JTKI4GS.mjs"}
|
package/dist/esm/index.d.mts
CHANGED
|
@@ -282,9 +282,30 @@ declare class InternationalizationHandler {
|
|
|
282
282
|
* @see {@link https://www.i18next.com/overview/api#t}
|
|
283
283
|
* @returns The localized content.
|
|
284
284
|
*/
|
|
285
|
-
format<const Key extends ParseKeys<Ns, TOpt, undefined>, const TOpt extends TOptions = TOptions, Ns extends Namespace = DefaultNamespace, Ret extends TFunctionReturn<Ns, AppendKeyPrefix<Key, undefined>, TOpt> = TOpt['returnObjects'] extends true ? $SpecialObject : string, const ActualOptions extends TOpt & InterpolationMap<Ret> = TOpt & InterpolationMap<Ret>>(locale: string,
|
|
285
|
+
format<const Key extends ParseKeys<Ns, TOpt, undefined>, const TOpt extends TOptions = TOptions, Ns extends Namespace = DefaultNamespace, Ret extends TFunctionReturn<Ns, AppendKeyPrefix<Key, undefined>, TOpt> = TOpt['returnObjects'] extends true ? $SpecialObject : string, const ActualOptions extends TOpt & InterpolationMap<Ret> = TOpt & InterpolationMap<Ret>>(locale: string, key: Key | Key[], options?: ActualOptions): TFunctionReturnOptionalDetails<Ret, TOpt>;
|
|
286
|
+
/**
|
|
287
|
+
* Localizes a content given one or more keys and i18next options.
|
|
288
|
+
* @since 2.0.0
|
|
289
|
+
* @param locale The language to be used.
|
|
290
|
+
* @param key The key or keys to retrieve the content from.
|
|
291
|
+
* @param options The interpolation options as well as a `defaultValue` for the key and any key/value pairs.
|
|
292
|
+
* @see {@link https://www.i18next.com/overview/api#t}
|
|
293
|
+
* @returns The localized content.
|
|
294
|
+
*/
|
|
295
|
+
format<const Key extends ParseKeys<Ns, TOpt, undefined>, const TOpt extends TOptions = TOptions, Ns extends Namespace = DefaultNamespace, Ret extends TFunctionReturn<Ns, AppendKeyPrefix<Key, undefined>, TOpt> = TOpt['returnObjects'] extends true ? $SpecialObject : string, const ActualOptions extends TOpt & InterpolationMap<Ret> = TOpt & InterpolationMap<Ret>>(locale: string, key: string | string[], options: TOpt & $Dictionary & {
|
|
286
296
|
defaultValue: string;
|
|
287
|
-
}
|
|
297
|
+
}): TFunctionReturnOptionalDetails<Ret, TOpt>;
|
|
298
|
+
/**
|
|
299
|
+
* Localizes a content given one or more keys and i18next options.
|
|
300
|
+
* @since 2.0.0
|
|
301
|
+
* @param locale The language to be used.
|
|
302
|
+
* @param key The key or keys to retrieve the content from.
|
|
303
|
+
* @param defaultValue The default value to use if the key is not found.
|
|
304
|
+
* @param options The interpolation options.
|
|
305
|
+
* @see {@link https://www.i18next.com/overview/api#t}
|
|
306
|
+
* @returns The localized content.
|
|
307
|
+
*/
|
|
308
|
+
format<const Key extends ParseKeys<Ns, TOpt, undefined>, const TOpt extends TOptions = TOptions, Ns extends Namespace = DefaultNamespace, Ret extends TFunctionReturn<Ns, AppendKeyPrefix<Key, undefined>, TOpt> = TOpt['returnObjects'] extends true ? $SpecialObject : string, const ActualOptions extends TOpt & InterpolationMap<Ret> = TOpt & InterpolationMap<Ret>>(locale: string, key: string | string[], defaultValue: string | undefined, options?: TOpt & $Dictionary): TFunctionReturnOptionalDetails<Ret, TOpt>;
|
|
288
309
|
/**
|
|
289
310
|
* @param directory The directory that should be walked.
|
|
290
311
|
* @since 3.0.0
|
|
@@ -331,9 +352,28 @@ declare function fetchT(target: Target): Promise<i18next.TFunction<"translation"
|
|
|
331
352
|
* @param options The options to be passed to TFunction.
|
|
332
353
|
* @returns The data that `key` held, processed by i18next.
|
|
333
354
|
*/
|
|
334
|
-
declare function resolveKey<const Key extends ParseKeys<Ns, TOpt, undefined>, const TOpt extends TOptions = TOptions, Ret extends TFunctionReturn<Ns, AppendKeyPrefix<Key, undefined>, TOpt> = TOpt['returnObjects'] extends true ? $SpecialObject : string, Ns extends Namespace = DefaultNamespace, const ActualOptions extends TOpt & InterpolationMap<Ret> = TOpt & InterpolationMap<Ret>>(target: Target,
|
|
355
|
+
declare function resolveKey<const Key extends ParseKeys<Ns, TOpt, undefined>, const TOpt extends TOptions = TOptions, Ret extends TFunctionReturn<Ns, AppendKeyPrefix<Key, undefined>, TOpt> = TOpt['returnObjects'] extends true ? $SpecialObject : string, Ns extends Namespace = DefaultNamespace, const ActualOptions extends TOpt & InterpolationMap<Ret> = TOpt & InterpolationMap<Ret>>(target: Target, key: Key | Key[], options?: ActualOptions): Promise<TFunctionReturnOptionalDetails<Ret, TOpt>>;
|
|
356
|
+
/**
|
|
357
|
+
* Resolves a key and its parameters.
|
|
358
|
+
* @since 2.0.0
|
|
359
|
+
* @param target The target to fetch the language key from.
|
|
360
|
+
* @param key The i18next key.
|
|
361
|
+
* @param options The interpolation options as well as a `defaultValue` for the key and any key/value pairs.
|
|
362
|
+
* @returns The data that `key` held, processed by i18next.
|
|
363
|
+
*/
|
|
364
|
+
declare function resolveKey<const Key extends ParseKeys<Ns, TOpt, undefined>, const TOpt extends TOptions = TOptions, Ret extends TFunctionReturn<Ns, AppendKeyPrefix<Key, undefined>, TOpt> = TOpt['returnObjects'] extends true ? $SpecialObject : string, Ns extends Namespace = DefaultNamespace, const ActualOptions extends TOpt & InterpolationMap<Ret> = TOpt & InterpolationMap<Ret>>(target: Target, key: string | string[], options: TOpt & $Dictionary & {
|
|
335
365
|
defaultValue: string;
|
|
336
|
-
}
|
|
366
|
+
}): Promise<TFunctionReturnOptionalDetails<Ret, TOpt>>;
|
|
367
|
+
/**
|
|
368
|
+
* Resolves a key and its parameters.
|
|
369
|
+
* @since 2.0.0
|
|
370
|
+
* @param target The target to fetch the language key from.
|
|
371
|
+
* @param key The i18next key.
|
|
372
|
+
* @param defaultValue The default value to use if the key is not found.
|
|
373
|
+
* @param options The interpolation options.
|
|
374
|
+
* @returns The data that `key` held, processed by i18next.
|
|
375
|
+
*/
|
|
376
|
+
declare function resolveKey<const Key extends ParseKeys<Ns, TOpt, undefined>, const TOpt extends TOptions = TOptions, Ret extends TFunctionReturn<Ns, AppendKeyPrefix<Key, undefined>, TOpt> = TOpt['returnObjects'] extends true ? $SpecialObject : string, Ns extends Namespace = DefaultNamespace, const ActualOptions extends TOpt & InterpolationMap<Ret> = TOpt & InterpolationMap<Ret>>(target: Target, key: string | string[], defaultValue: string, options?: TOpt & $Dictionary): Promise<TFunctionReturnOptionalDetails<Ret, TOpt>>;
|
|
337
377
|
/**
|
|
338
378
|
* Gets the value and the localizations from a language key.
|
|
339
379
|
* @param key The key to get the localizations from.
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import './chunk-
|
|
1
|
+
import './chunk-2JTKI4GS.mjs';
|
|
2
2
|
export { default as i18next } from 'i18next';
|
|
3
3
|
export * from './lib/InternationalizationHandler.mjs';
|
|
4
4
|
export * from './lib/functions.mjs';
|
|
5
5
|
export * from './lib/types.mjs';
|
|
6
6
|
|
|
7
|
-
var version = "7.1.3-next.
|
|
7
|
+
var version = "7.1.3-next.fc8c5ba";
|
|
8
8
|
|
|
9
9
|
export { version };
|
|
10
|
-
//# sourceMappingURL=
|
|
10
|
+
//# sourceMappingURL=index.mjs.map
|
|
11
11
|
//# sourceMappingURL=index.mjs.map
|
package/dist/esm/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts"],"names":[
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;AAyBO,IAAM,OAAkB,GAAA","file":"index.mjs","sourcesContent":["import type { InternationalizationHandler } from './lib/InternationalizationHandler';\nimport type { InternationalizationClientOptions } from './lib/types';\n\nexport { default as i18next, type TFunction, type TOptions } from 'i18next';\nexport * from './lib/InternationalizationHandler';\nexport * from './lib/functions';\nexport * from './lib/types';\n\ndeclare module '@sapphire/pieces' {\n\tinterface Container {\n\t\ti18n: InternationalizationHandler;\n\t}\n}\n\ndeclare module 'discord.js' {\n\texport interface ClientOptions extends InternationalizationClientOptions {}\n}\n\n/**\n * The [@sapphire/plugin-i18next](https://github.com/sapphiredev/plugins/blob/main/packages/i18next) version that you are currently using.\n * An example use of this is showing it of in a bot information command.\n *\n * Note to Sapphire developers: This needs to explicitly be `string` so it is not typed as the string that gets replaced by esbuild\n */\n// eslint-disable-next-line @typescript-eslint/no-inferrable-types\nexport const version: string = '7.1.3-next.fc8c5ba';\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"Augmentations.d.mjs"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { __name, __publicField } from '../chunk-
|
|
1
|
+
import { __name, __publicField } from '../chunk-2JTKI4GS.mjs';
|
|
2
2
|
import { Result } from '@sapphire/framework';
|
|
3
3
|
import { container, getRootData } from '@sapphire/pieces';
|
|
4
4
|
import { isFunction } from '@sapphire/utilities';
|
|
@@ -134,10 +134,8 @@ var _InternationalizationHandler = class _InternationalizationHandler {
|
|
|
134
134
|
const formatter = i18next.services.formatter;
|
|
135
135
|
const formatters = this.options.formatters ?? [];
|
|
136
136
|
for (const { name, format, cached } of formatters) {
|
|
137
|
-
if (cached)
|
|
138
|
-
|
|
139
|
-
else
|
|
140
|
-
formatter.add(name, format);
|
|
137
|
+
if (cached) formatter.addCached(name, format);
|
|
138
|
+
else formatter.add(name, format);
|
|
141
139
|
}
|
|
142
140
|
}
|
|
143
141
|
/**
|
|
@@ -146,28 +144,27 @@ var _InternationalizationHandler = class _InternationalizationHandler {
|
|
|
146
144
|
* @since 1.0.0
|
|
147
145
|
*/
|
|
148
146
|
getT(locale) {
|
|
149
|
-
if (!this.languagesLoaded)
|
|
150
|
-
throw new Error("Cannot call this method until InternationalizationHandler#init has been called");
|
|
147
|
+
if (!this.languagesLoaded) throw new Error("Cannot call this method until InternationalizationHandler#init has been called");
|
|
151
148
|
const t = this.languages.get(locale);
|
|
152
|
-
if (t)
|
|
153
|
-
return t;
|
|
149
|
+
if (t) return t;
|
|
154
150
|
throw new ReferenceError("Invalid language provided");
|
|
155
151
|
}
|
|
156
152
|
/**
|
|
157
153
|
* Localizes a content given one or more keys and i18next options.
|
|
158
154
|
* @since 2.0.0
|
|
159
155
|
* @param locale The language to be used.
|
|
160
|
-
*
|
|
161
|
-
* @
|
|
156
|
+
*
|
|
157
|
+
* @remark This function also has additional parameters for `key`, `defaultValue`, and `options`, however
|
|
158
|
+
* TSDoc does not let us document those while matching proper implementation. See the overloads for this method
|
|
159
|
+
* for the documentation on those parameters.
|
|
160
|
+
*
|
|
162
161
|
* @see {@link https://www.i18next.com/overview/api#t}
|
|
163
162
|
* @returns The localized content.
|
|
164
163
|
*/
|
|
165
164
|
format(locale, ...[key, defaultValueOrOptions, optionsOrUndefined]) {
|
|
166
|
-
if (!this.languagesLoaded)
|
|
167
|
-
throw new Error("Cannot call this method until InternationalizationHandler#init has been called");
|
|
165
|
+
if (!this.languagesLoaded) throw new Error("Cannot call this method until InternationalizationHandler#init has been called");
|
|
168
166
|
const language = this.languages.get(locale);
|
|
169
|
-
if (!language)
|
|
170
|
-
throw new ReferenceError("Invalid language provided");
|
|
167
|
+
if (!language) throw new ReferenceError("Invalid language provided");
|
|
171
168
|
const defaultValue = typeof defaultValueOrOptions === "string" ? defaultValueOrOptions : this.options.defaultMissingKey ? language(this.options.defaultMissingKey, { replace: { key } }) : "";
|
|
172
169
|
return language(key, { defaultValue, ...optionsOrUndefined ?? {} });
|
|
173
170
|
}
|
|
@@ -180,8 +177,7 @@ var _InternationalizationHandler = class _InternationalizationHandler {
|
|
|
180
177
|
const namespaces = /* @__PURE__ */ new Set();
|
|
181
178
|
const dir = await opendir(directory);
|
|
182
179
|
for await (const entry of dir) {
|
|
183
|
-
if (!entry.isDirectory())
|
|
184
|
-
continue;
|
|
180
|
+
if (!entry.isDirectory()) continue;
|
|
185
181
|
languages.add(entry.name);
|
|
186
182
|
for await (const namespace of this.walkLocaleDirectory(join(dir.path, entry.name), "")) {
|
|
187
183
|
namespaces.add(namespace);
|
|
@@ -224,5 +220,5 @@ __name(_InternationalizationHandler, "InternationalizationHandler");
|
|
|
224
220
|
var InternationalizationHandler = _InternationalizationHandler;
|
|
225
221
|
|
|
226
222
|
export { InternationalizationHandler };
|
|
227
|
-
//# sourceMappingURL=
|
|
223
|
+
//# sourceMappingURL=InternationalizationHandler.mjs.map
|
|
228
224
|
//# sourceMappingURL=InternationalizationHandler.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/InternationalizationHandler.ts"],"names":[],"mappings":";;;;;;AAAA,SAAS,cAAc;AACvB,SAAS,WAAW,mBAAmB;AACvC,SAAS,kBAAkC;AAC3C,SAAS,eAAoC;AAC7C,OAAO,aAUA;AAEP,SAAS,eAAe;AACxB,SAAS,YAAY;AACrB,SAAS,KAAK,qBAAqB;AAO5B,IAAM,+BAAN,MAAM,6BAA4B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EA2CjC,YAAY,SAAuC;AAtC1D;AAAA;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AAA,IACtE,CAAC;AAED,WAAO,WAAW,CAAC,UAAU,UAAU,OAAO,MAAM,0DAA0D,KAAK,CAAC;AAAA,EACrH;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,OAAe,oBAAoB,WAAmB,IAAoC;AACzF,UAAM,MAAM,MAAM,QAAQ,SAAS;AACnC,qBAAiB,SAAS,KAAK;AAC9B,UAAI,MAAM,YAAY,GAAG;AACxB,eAAO,KAAK,oBAAoB,KAAK,IAAI,MAAM,MAAM,IAAI,GAAG,GAAG,EAAE,GAAG,MAAM,IAAI,GAAG;AAAA,MAClF,WAAW,MAAM,OAAO,KAAK,MAAM,KAAK,SAAS,OAAO,GAAG;AAC1D,cAAM,GAAG,EAAE,GAAG,MAAM,KAAK,MAAM,GAAG,EAAE,CAAC;AAAA,MACtC;AAAA,IACD;AAAA,EACD;AACD;AAhQyC;AAAlC,IAAM,8BAAN","sourcesContent":["import { Result } from '@sapphire/framework';\nimport { container, getRootData } from '@sapphire/pieces';\nimport { isFunction, type Awaitable } from '@sapphire/utilities';\nimport { Backend, type PathResolvable } from '@skyra/i18next-backend';\nimport i18next, {\n\ttype AppendKeyPrefix,\n\ttype DefaultNamespace,\n\ttype InterpolationMap,\n\ttype Namespace,\n\ttype ParseKeys,\n\ttype TFunction,\n\ttype TFunctionReturn,\n\ttype TFunctionReturnOptionalDetails,\n\ttype TOptions\n} from 'i18next';\nimport type { PathLike } from 'node:fs';\nimport { opendir } from 'node:fs/promises';\nimport { join } from 'node:path';\nimport { URL, fileURLToPath } from 'node:url';\nimport type { $Dictionary, $SpecialObject, InternationalizationContext, InternationalizationOptions } from './types';\n\n/**\n * A generalized class for handling `i18next` JSON files and their discovery.\n * @since 1.0.0\n */\nexport class InternationalizationHandler {\n\t/**\n\t * Describes whether {@link InternationalizationHandler.init} has been run and languages are loaded in {@link InternationalizationHandler.languages}.\n\t * @since 1.0.0\n\t */\n\tpublic languagesLoaded = false;\n\n\t/**\n\t * A `Set` of initially loaded namespaces.\n\t * @since 1.2.0\n\t */\n\tpublic namespaces = new Set<string>();\n\n\t/**\n\t * A `Map` of `i18next` language functions keyed by their language code.\n\t * @since 1.0.0\n\t */\n\tpublic readonly languages = new Map<string, TFunction>();\n\n\t/**\n\t * The options InternationalizationHandler was initialized with in the client.\n\t * @since 1.0.0\n\t */\n\tpublic readonly options: InternationalizationOptions;\n\n\t/**\n\t * The director passed to `@skyra/i18next-backend`.\n\t * Also used in {@link InternationalizationHandler.walkLanguageDirectory}.\n\t * @since 1.2.0\n\t */\n\tpublic readonly languagesDirectory: string;\n\n\t/**\n\t * The backend options for `@skyra/i18next-backend` used by `i18next`.\n\t * @since 1.0.0\n\t */\n\tprotected readonly backendOptions: Backend.Options;\n\n\t/**\n\t * @param options The options that `i18next`, `@skyra/i18next-backend`, and {@link InternationalizationHandler} should use.\n\t * @since 1.0.0\n\t * @constructor\n\t */\n\tpublic constructor(options?: InternationalizationOptions) {\n\t\tthis.options = options ?? { i18next: { ignoreJSONStructure: false } };\n\n\t\tconst baseUserDirectory =\n\t\t\tcontainer.client?.options?.baseUserDirectory instanceof URL\n\t\t\t\t? fileURLToPath(container.client?.options?.baseUserDirectory)\n\t\t\t\t: container.client?.options?.baseUserDirectory;\n\n\t\tthis.languagesDirectory = this.options.defaultLanguageDirectory ?? join(baseUserDirectory ?? getRootData().root, 'languages');\n\n\t\tconst languagePaths = new Set<PathResolvable>([\n\t\t\tjoin(this.languagesDirectory, '{{lng}}', '{{ns}}.json'), //\n\t\t\t...(options?.backend?.paths ?? [])\n\t\t]);\n\n\t\tthis.backendOptions = {\n\t\t\tpaths: [...languagePaths],\n\t\t\t...this.options.backend\n\t\t};\n\n\t\tif (isFunction(this.options.fetchLanguage)) {\n\t\t\tthis.fetchLanguage = this.options.fetchLanguage;\n\t\t}\n\t}\n\n\t/**\n\t * The method to be overridden by the developer.\n\t *\n\t * @note In the event that fetchLanguage is not defined or returns null / undefined, the defaulting from {@link fetchLanguage} will be used.\n\t * @since 2.0.0\n\t * @return A string for the desired language or null for no match.\n\t * @see {@link fetchLanguage}\n\t * @example\n\t * ```typescript\n\t * // Always use the same language (no per-guild configuration):\n\t * container.i18n.fetchLanguage = () => 'en-US';\n\t * ```\n\t * @example\n\t * ```typescript\n\t * // Retrieving the language from an SQL database:\n\t * container.i18n.fetchLanguage = async (context) => {\n\t * const guild = await driver.getOne('SELECT language FROM public.guild WHERE id = $1', [context.guild.id]);\n\t * return guild?.language ?? 'en-US';\n\t * };\n\t * ```\n\t * @example\n\t * ```typescript\n\t * // Retrieving the language from an ORM:\n\t * container.i18n.fetchLanguage = async (context) => {\n\t * const guild = await driver.getRepository(GuildEntity).findOne({ id: context.guild.id });\n\t * return guild?.language ?? 'en-US';\n\t * };\n\t * ```\n\t * @example\n\t * ```typescript\n\t * // Retrieving the language on a per channel basis, e.g. per user or guild channel (ORM example but same principles apply):\n\t * container.i18n.fetchLanguage = async (context) => {\n\t * const channel = await driver.getRepository(ChannelEntity).findOne({ id: context.channel.id });\n\t * return channel?.language ?? 'en-US';\n\t * };\n\t * ```\n\t */\n\tpublic fetchLanguage: (context: InternationalizationContext) => Awaitable<string | null> = () => null;\n\n\t/**\n\t * Initializes the handler by loading in the namespaces, passing the data to i18next, and filling in the {@link InternationalizationHandler#languages}.\n\t * @since 1.0.0\n\t */\n\tpublic async init() {\n\t\tconst { namespaces, languages } = await this.walkRootDirectory(this.languagesDirectory);\n\t\tconst userOptions = isFunction(this.options.i18next) ? this.options.i18next(namespaces, languages) : this.options.i18next;\n\t\tconst ignoreJSONStructure = userOptions?.ignoreJSONStructure ?? false;\n\t\tconst skipOnVariables = userOptions?.interpolation?.skipOnVariables ?? false;\n\n\t\ti18next.use(Backend);\n\t\tawait i18next.init({\n\t\t\tbackend: this.backendOptions,\n\t\t\tfallbackLng: this.options.defaultName ?? 'en-US',\n\t\t\tinitImmediate: false,\n\t\t\tinterpolation: {\n\t\t\t\tescapeValue: false,\n\t\t\t\t...userOptions?.interpolation,\n\t\t\t\tskipOnVariables\n\t\t\t},\n\t\t\tload: 'all',\n\t\t\tdefaultNS: 'default',\n\t\t\tns: namespaces,\n\t\t\tpreload: languages,\n\t\t\t...userOptions,\n\t\t\tignoreJSONStructure\n\t\t});\n\n\t\tthis.namespaces = new Set(namespaces);\n\t\tfor (const item of languages) {\n\t\t\tthis.languages.set(item, i18next.getFixedT(item));\n\t\t}\n\t\tthis.languagesLoaded = true;\n\n\t\tconst formatter = i18next.services.formatter!;\n\t\tconst formatters = this.options.formatters ?? [];\n\t\tfor (const { name, format, cached } of formatters) {\n\t\t\tif (cached) formatter.addCached(name, format);\n\t\t\telse formatter.add(name, format);\n\t\t}\n\t}\n\n\t/**\n\t * Retrieve a raw TFunction from the passed locale.\n\t * @param locale The language to be used.\n\t * @since 1.0.0\n\t */\n\tpublic getT(locale: string) {\n\t\tif (!this.languagesLoaded) throw new Error('Cannot call this method until InternationalizationHandler#init has been called');\n\n\t\tconst t = this.languages.get(locale);\n\t\tif (t) return t;\n\t\tthrow new ReferenceError('Invalid language provided');\n\t}\n\n\t/**\n\t * Localizes a content given one or more keys and i18next options.\n\t * @since 2.0.0\n\t * @param locale The language to be used.\n\t * @param key The key or keys to retrieve the content from.\n\t * @param options The interpolation options.\n\t * @see {@link https://www.i18next.com/overview/api#t}\n\t * @returns The localized content.\n\t */\n\tpublic format<\n\t\tconst Key extends ParseKeys<Ns, TOpt, undefined>,\n\t\tconst TOpt extends TOptions = TOptions,\n\t\tNs extends Namespace = DefaultNamespace,\n\t\tRet extends TFunctionReturn<Ns, AppendKeyPrefix<Key, undefined>, TOpt> = TOpt['returnObjects'] extends true ? $SpecialObject : string,\n\t\tconst ActualOptions extends TOpt & InterpolationMap<Ret> = TOpt & InterpolationMap<Ret>\n\t>(\n\t\tlocale: string,\n\t\t...[key, defaultValueOrOptions, optionsOrUndefined]:\n\t\t\t| [key: Key | Key[], options?: ActualOptions]\n\t\t\t| [key: string | string[], options: TOpt & $Dictionary & { defaultValue: string }]\n\t\t\t| [key: string | string[], defaultValue: string | undefined, options?: TOpt & $Dictionary]\n\t): TFunctionReturnOptionalDetails<Ret, TOpt> {\n\t\tif (!this.languagesLoaded) throw new Error('Cannot call this method until InternationalizationHandler#init has been called');\n\n\t\tconst language = this.languages.get(locale);\n\t\tif (!language) throw new ReferenceError('Invalid language provided');\n\n\t\tconst defaultValue =\n\t\t\ttypeof defaultValueOrOptions === 'string'\n\t\t\t\t? defaultValueOrOptions\n\t\t\t\t: this.options.defaultMissingKey\n\t\t\t\t\t? language(this.options.defaultMissingKey, { replace: { key } })\n\t\t\t\t\t: '';\n\n\t\treturn language<Key, TOpt, Ret, ActualOptions>(key, { defaultValue, ...((optionsOrUndefined ?? {}) as TOpt) });\n\t}\n\n\t/**\n\t * @param directory The directory that should be walked.\n\t * @since 3.0.0\n\t */\n\tpublic async walkRootDirectory(directory: PathLike) {\n\t\tconst languages = new Set<string>();\n\t\tconst namespaces = new Set<string>();\n\n\t\tconst dir = await opendir(directory);\n\t\tfor await (const entry of dir) {\n\t\t\t// If the entry is not a directory, skip:\n\t\t\tif (!entry.isDirectory()) continue;\n\n\t\t\t// Load the directory:\n\t\t\tlanguages.add(entry.name);\n\n\t\t\tfor await (const namespace of this.walkLocaleDirectory(join(dir.path, entry.name), '')) {\n\t\t\t\tnamespaces.add(namespace);\n\t\t\t}\n\t\t}\n\n\t\treturn { namespaces: [...namespaces], languages: [...languages] };\n\t}\n\n\tpublic async reloadResources() {\n\t\tconst result = await Result.fromAsync(async () => {\n\t\t\tlet languages = this.options.hmr?.languages;\n\t\t\tlet namespaces = this.options.hmr?.namespaces;\n\t\t\tif (!languages || !namespaces) {\n\t\t\t\tconst languageDirectoryResult = await this.walkRootDirectory(this.languagesDirectory);\n\t\t\t\tlanguages ??= languageDirectoryResult.languages;\n\t\t\t\tnamespaces ??= languageDirectoryResult.namespaces;\n\t\t\t}\n\n\t\t\tawait i18next.reloadResources(languages, namespaces);\n\t\t\tcontainer.logger.info('[i18next-Plugin] Reloaded language resources.');\n\t\t});\n\n\t\tresult.inspectErr((error) => container.logger.error('[i18next-Plugin]: Failed to reload language resources.', error));\n\t}\n\n\t/**\n\t * @description Skips any files that don't end with `.json`.\n\t * @param directory The directory that should be walked.\n\t * @param ns The current namespace.\n\t * @since 3.0.0\n\t */\n\tprivate async *walkLocaleDirectory(directory: string, ns: string): AsyncGenerator<string> {\n\t\tconst dir = await opendir(directory);\n\t\tfor await (const entry of dir) {\n\t\t\tif (entry.isDirectory()) {\n\t\t\t\tyield* this.walkLocaleDirectory(join(dir.path, entry.name), `${ns}${entry.name}/`);\n\t\t\t} else if (entry.isFile() && entry.name.endsWith('.json')) {\n\t\t\t\tyield `${ns}${entry.name.slice(0, -5)}`;\n\t\t\t}\n\t\t}\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/InternationalizationHandler.ts"],"names":[],"mappings":";;;;;;;;;;AAyBO,IAAM,4BAAA,GAAN,MAAM,4BAA4B,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EA2CjC,YAAY,OAAuC,EAAA;AAtC1D;AAAA;AAAA;AAAA;AAAA,IAAA,aAAA,CAAA,IAAA,EAAO,iBAAkB,EAAA,KAAA,CAAA,CAAA;AAMzB;AAAA;AAAA;AAAA;AAAA,IAAO,aAAA,CAAA,IAAA,EAAA,YAAA,sBAAiB,GAAY,EAAA,CAAA,CAAA;AAMpC;AAAA;AAAA;AAAA;AAAA,IAAgB,aAAA,CAAA,IAAA,EAAA,WAAA,sBAAgB,GAAuB,EAAA,CAAA,CAAA;AAMvD;AAAA;AAAA;AAAA;AAAA,IAAgB,aAAA,CAAA,IAAA,EAAA,SAAA,CAAA,CAAA;AAOhB;AAAA;AAAA;AAAA;AAAA;AAAA,IAAgB,aAAA,CAAA,IAAA,EAAA,oBAAA,CAAA,CAAA;AAMhB;AAAA;AAAA;AAAA;AAAA,IAAmB,aAAA,CAAA,IAAA,EAAA,gBAAA,CAAA,CAAA;AAqEnB;AAAA;AA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,KAAM,CAAA,CAAA,EAAG,EAAE,CAAC,CAAA,CAAA,CAAA;AAAA,OACtC;AAAA,KACD;AAAA,GACD;AACD,CAAA,CAAA;AA5TyC,MAAA,CAAA,4BAAA,EAAA,6BAAA,CAAA,CAAA;AAAlC,IAAM,2BAAN,GAAA","file":"InternationalizationHandler.mjs","sourcesContent":["import { Result } from '@sapphire/framework';\nimport { container, getRootData } from '@sapphire/pieces';\nimport { isFunction, type Awaitable } from '@sapphire/utilities';\nimport { Backend, type PathResolvable } from '@skyra/i18next-backend';\nimport i18next, {\n\ttype AppendKeyPrefix,\n\ttype DefaultNamespace,\n\ttype InterpolationMap,\n\ttype Namespace,\n\ttype ParseKeys,\n\ttype TFunction,\n\ttype TFunctionReturn,\n\ttype TFunctionReturnOptionalDetails,\n\ttype TOptions\n} from 'i18next';\nimport type { PathLike } from 'node:fs';\nimport { opendir } from 'node:fs/promises';\nimport { join } from 'node:path';\nimport { URL, fileURLToPath } from 'node:url';\nimport type { $Dictionary, $SpecialObject, InternationalizationContext, InternationalizationOptions } from './types';\n\n/**\n * A generalized class for handling `i18next` JSON files and their discovery.\n * @since 1.0.0\n */\nexport class InternationalizationHandler {\n\t/**\n\t * Describes whether {@link InternationalizationHandler.init} has been run and languages are loaded in {@link InternationalizationHandler.languages}.\n\t * @since 1.0.0\n\t */\n\tpublic languagesLoaded = false;\n\n\t/**\n\t * A `Set` of initially loaded namespaces.\n\t * @since 1.2.0\n\t */\n\tpublic namespaces = new Set<string>();\n\n\t/**\n\t * A `Map` of `i18next` language functions keyed by their language code.\n\t * @since 1.0.0\n\t */\n\tpublic readonly languages = new Map<string, TFunction>();\n\n\t/**\n\t * The options InternationalizationHandler was initialized with in the client.\n\t * @since 1.0.0\n\t */\n\tpublic readonly options: InternationalizationOptions;\n\n\t/**\n\t * The director passed to `@skyra/i18next-backend`.\n\t * Also used in {@link InternationalizationHandler.walkLanguageDirectory}.\n\t * @since 1.2.0\n\t */\n\tpublic readonly languagesDirectory: string;\n\n\t/**\n\t * The backend options for `@skyra/i18next-backend` used by `i18next`.\n\t * @since 1.0.0\n\t */\n\tprotected readonly backendOptions: Backend.Options;\n\n\t/**\n\t * @param options The options that `i18next`, `@skyra/i18next-backend`, and {@link InternationalizationHandler} should use.\n\t * @since 1.0.0\n\t * @constructor\n\t */\n\tpublic constructor(options?: InternationalizationOptions) {\n\t\tthis.options = options ?? { i18next: { ignoreJSONStructure: false } };\n\n\t\tconst baseUserDirectory =\n\t\t\tcontainer.client?.options?.baseUserDirectory instanceof URL\n\t\t\t\t? fileURLToPath(container.client?.options?.baseUserDirectory)\n\t\t\t\t: container.client?.options?.baseUserDirectory;\n\n\t\tthis.languagesDirectory = this.options.defaultLanguageDirectory ?? join(baseUserDirectory ?? getRootData().root, 'languages');\n\n\t\tconst languagePaths = new Set<PathResolvable>([\n\t\t\tjoin(this.languagesDirectory, '{{lng}}', '{{ns}}.json'), //\n\t\t\t...(options?.backend?.paths ?? [])\n\t\t]);\n\n\t\tthis.backendOptions = {\n\t\t\tpaths: [...languagePaths],\n\t\t\t...this.options.backend\n\t\t};\n\n\t\tif (isFunction(this.options.fetchLanguage)) {\n\t\t\tthis.fetchLanguage = this.options.fetchLanguage;\n\t\t}\n\t}\n\n\t/**\n\t * The method to be overridden by the developer.\n\t *\n\t * @note In the event that fetchLanguage is not defined or returns null / undefined, the defaulting from {@link fetchLanguage} will be used.\n\t * @since 2.0.0\n\t * @return A string for the desired language or null for no match.\n\t * @see {@link fetchLanguage}\n\t * @example\n\t * ```typescript\n\t * // Always use the same language (no per-guild configuration):\n\t * container.i18n.fetchLanguage = () => 'en-US';\n\t * ```\n\t * @example\n\t * ```typescript\n\t * // Retrieving the language from an SQL database:\n\t * container.i18n.fetchLanguage = async (context) => {\n\t * const guild = await driver.getOne('SELECT language FROM public.guild WHERE id = $1', [context.guild.id]);\n\t * return guild?.language ?? 'en-US';\n\t * };\n\t * ```\n\t * @example\n\t * ```typescript\n\t * // Retrieving the language from an ORM:\n\t * container.i18n.fetchLanguage = async (context) => {\n\t * const guild = await driver.getRepository(GuildEntity).findOne({ id: context.guild.id });\n\t * return guild?.language ?? 'en-US';\n\t * };\n\t * ```\n\t * @example\n\t * ```typescript\n\t * // Retrieving the language on a per channel basis, e.g. per user or guild channel (ORM example but same principles apply):\n\t * container.i18n.fetchLanguage = async (context) => {\n\t * const channel = await driver.getRepository(ChannelEntity).findOne({ id: context.channel.id });\n\t * return channel?.language ?? 'en-US';\n\t * };\n\t * ```\n\t */\n\tpublic fetchLanguage: (context: InternationalizationContext) => Awaitable<string | null> = () => null;\n\n\t/**\n\t * Initializes the handler by loading in the namespaces, passing the data to i18next, and filling in the {@link InternationalizationHandler#languages}.\n\t * @since 1.0.0\n\t */\n\tpublic async init() {\n\t\tconst { namespaces, languages } = await this.walkRootDirectory(this.languagesDirectory);\n\t\tconst userOptions = isFunction(this.options.i18next) ? this.options.i18next(namespaces, languages) : this.options.i18next;\n\t\tconst ignoreJSONStructure = userOptions?.ignoreJSONStructure ?? false;\n\t\tconst skipOnVariables = userOptions?.interpolation?.skipOnVariables ?? false;\n\n\t\ti18next.use(Backend);\n\t\tawait i18next.init({\n\t\t\tbackend: this.backendOptions,\n\t\t\tfallbackLng: this.options.defaultName ?? 'en-US',\n\t\t\tinitImmediate: false,\n\t\t\tinterpolation: {\n\t\t\t\tescapeValue: false,\n\t\t\t\t...userOptions?.interpolation,\n\t\t\t\tskipOnVariables\n\t\t\t},\n\t\t\tload: 'all',\n\t\t\tdefaultNS: 'default',\n\t\t\tns: namespaces,\n\t\t\tpreload: languages,\n\t\t\t...userOptions,\n\t\t\tignoreJSONStructure\n\t\t});\n\n\t\tthis.namespaces = new Set(namespaces);\n\t\tfor (const item of languages) {\n\t\t\tthis.languages.set(item, i18next.getFixedT(item));\n\t\t}\n\t\tthis.languagesLoaded = true;\n\n\t\tconst formatter = i18next.services.formatter!;\n\t\tconst formatters = this.options.formatters ?? [];\n\t\tfor (const { name, format, cached } of formatters) {\n\t\t\tif (cached) formatter.addCached(name, format);\n\t\t\telse formatter.add(name, format);\n\t\t}\n\t}\n\n\t/**\n\t * Retrieve a raw TFunction from the passed locale.\n\t * @param locale The language to be used.\n\t * @since 1.0.0\n\t */\n\tpublic getT(locale: string) {\n\t\tif (!this.languagesLoaded) throw new Error('Cannot call this method until InternationalizationHandler#init has been called');\n\n\t\tconst t = this.languages.get(locale);\n\t\tif (t) return t;\n\t\tthrow new ReferenceError('Invalid language provided');\n\t}\n\n\t/**\n\t * Localizes a content given one or more keys and i18next options.\n\t * @since 2.0.0\n\t * @param locale The language to be used.\n\t * @param key The key or keys to retrieve the content from.\n\t * @param options The interpolation options.\n\t * @see {@link https://www.i18next.com/overview/api#t}\n\t * @returns The localized content.\n\t */\n\tpublic format<\n\t\tconst Key extends ParseKeys<Ns, TOpt, undefined>,\n\t\tconst TOpt extends TOptions = TOptions,\n\t\tNs extends Namespace = DefaultNamespace,\n\t\tRet extends TFunctionReturn<Ns, AppendKeyPrefix<Key, undefined>, TOpt> = TOpt['returnObjects'] extends true ? $SpecialObject : string,\n\t\tconst ActualOptions extends TOpt & InterpolationMap<Ret> = TOpt & InterpolationMap<Ret>\n\t>(locale: string, key: Key | Key[], options?: ActualOptions): TFunctionReturnOptionalDetails<Ret, TOpt>;\n\n\t/**\n\t * Localizes a content given one or more keys and i18next options.\n\t * @since 2.0.0\n\t * @param locale The language to be used.\n\t * @param key The key or keys to retrieve the content from.\n\t * @param options The interpolation options as well as a `defaultValue` for the key and any key/value pairs.\n\t * @see {@link https://www.i18next.com/overview/api#t}\n\t * @returns The localized content.\n\t */\n\tpublic format<\n\t\tconst Key extends ParseKeys<Ns, TOpt, undefined>,\n\t\tconst TOpt extends TOptions = TOptions,\n\t\tNs extends Namespace = DefaultNamespace,\n\t\tRet extends TFunctionReturn<Ns, AppendKeyPrefix<Key, undefined>, TOpt> = TOpt['returnObjects'] extends true ? $SpecialObject : string,\n\t\tconst ActualOptions extends TOpt & InterpolationMap<Ret> = TOpt & InterpolationMap<Ret>\n\t>(locale: string, key: string | string[], options: TOpt & $Dictionary & { defaultValue: string }): TFunctionReturnOptionalDetails<Ret, TOpt>;\n\n\t/**\n\t * Localizes a content given one or more keys and i18next options.\n\t * @since 2.0.0\n\t * @param locale The language to be used.\n\t * @param key The key or keys to retrieve the content from.\n\t * @param defaultValue The default value to use if the key is not found.\n\t * @param options The interpolation options.\n\t * @see {@link https://www.i18next.com/overview/api#t}\n\t * @returns The localized content.\n\t */\n\tpublic format<\n\t\tconst Key extends ParseKeys<Ns, TOpt, undefined>,\n\t\tconst TOpt extends TOptions = TOptions,\n\t\tNs extends Namespace = DefaultNamespace,\n\t\tRet extends TFunctionReturn<Ns, AppendKeyPrefix<Key, undefined>, TOpt> = TOpt['returnObjects'] extends true ? $SpecialObject : string,\n\t\tconst ActualOptions extends TOpt & InterpolationMap<Ret> = TOpt & InterpolationMap<Ret>\n\t>(\n\t\tlocale: string,\n\t\tkey: string | string[],\n\t\tdefaultValue: string | undefined,\n\t\toptions?: TOpt & $Dictionary\n\t): TFunctionReturnOptionalDetails<Ret, TOpt>;\n\n\t/**\n\t * Localizes a content given one or more keys and i18next options.\n\t * @since 2.0.0\n\t * @param locale The language to be used.\n\t *\n\t * @remark This function also has additional parameters for `key`, `defaultValue`, and `options`, however\n\t * TSDoc does not let us document those while matching proper implementation. See the overloads for this method\n\t * for the documentation on those parameters.\n\t *\n\t * @see {@link https://www.i18next.com/overview/api#t}\n\t * @returns The localized content.\n\t */\n\tpublic format<\n\t\tconst Key extends ParseKeys<Ns, TOpt, undefined>,\n\t\tconst TOpt extends TOptions = TOptions,\n\t\tNs extends Namespace = DefaultNamespace,\n\t\tRet extends TFunctionReturn<Ns, AppendKeyPrefix<Key, undefined>, TOpt> = TOpt['returnObjects'] extends true ? $SpecialObject : string,\n\t\tconst ActualOptions extends TOpt & InterpolationMap<Ret> = TOpt & InterpolationMap<Ret>\n\t>(\n\t\tlocale: string,\n\t\t...[key, defaultValueOrOptions, optionsOrUndefined]:\n\t\t\t| [key: Key | Key[], options?: ActualOptions]\n\t\t\t| [key: string | string[], options: TOpt & $Dictionary & { defaultValue: string }]\n\t\t\t| [key: string | string[], defaultValue: string | undefined, options?: TOpt & $Dictionary]\n\t): TFunctionReturnOptionalDetails<Ret, TOpt> {\n\t\tif (!this.languagesLoaded) throw new Error('Cannot call this method until InternationalizationHandler#init has been called');\n\n\t\tconst language = this.languages.get(locale);\n\t\tif (!language) throw new ReferenceError('Invalid language provided');\n\n\t\tconst defaultValue =\n\t\t\ttypeof defaultValueOrOptions === 'string'\n\t\t\t\t? defaultValueOrOptions\n\t\t\t\t: this.options.defaultMissingKey\n\t\t\t\t\t? language(this.options.defaultMissingKey, { replace: { key } })\n\t\t\t\t\t: '';\n\n\t\treturn language<Key, TOpt, Ret, ActualOptions>(key, { defaultValue, ...((optionsOrUndefined ?? {}) as TOpt) });\n\t}\n\n\t/**\n\t * @param directory The directory that should be walked.\n\t * @since 3.0.0\n\t */\n\tpublic async walkRootDirectory(directory: PathLike) {\n\t\tconst languages = new Set<string>();\n\t\tconst namespaces = new Set<string>();\n\n\t\tconst dir = await opendir(directory);\n\t\tfor await (const entry of dir) {\n\t\t\t// If the entry is not a directory, skip:\n\t\t\tif (!entry.isDirectory()) continue;\n\n\t\t\t// Load the directory:\n\t\t\tlanguages.add(entry.name);\n\n\t\t\tfor await (const namespace of this.walkLocaleDirectory(join(dir.path, entry.name), '')) {\n\t\t\t\tnamespaces.add(namespace);\n\t\t\t}\n\t\t}\n\n\t\treturn { namespaces: [...namespaces], languages: [...languages] };\n\t}\n\n\tpublic async reloadResources() {\n\t\tconst result = await Result.fromAsync(async () => {\n\t\t\tlet languages = this.options.hmr?.languages;\n\t\t\tlet namespaces = this.options.hmr?.namespaces;\n\t\t\tif (!languages || !namespaces) {\n\t\t\t\tconst languageDirectoryResult = await this.walkRootDirectory(this.languagesDirectory);\n\t\t\t\tlanguages ??= languageDirectoryResult.languages;\n\t\t\t\tnamespaces ??= languageDirectoryResult.namespaces;\n\t\t\t}\n\n\t\t\tawait i18next.reloadResources(languages, namespaces);\n\t\t\tcontainer.logger.info('[i18next-Plugin] Reloaded language resources.');\n\t\t});\n\n\t\tresult.inspectErr((error) => container.logger.error('[i18next-Plugin]: Failed to reload language resources.', error));\n\t}\n\n\t/**\n\t * @description Skips any files that don't end with `.json`.\n\t * @param directory The directory that should be walked.\n\t * @param ns The current namespace.\n\t * @since 3.0.0\n\t */\n\tprivate async *walkLocaleDirectory(directory: string, ns: string): AsyncGenerator<string> {\n\t\tconst dir = await opendir(directory);\n\t\tfor await (const entry of dir) {\n\t\t\tif (entry.isDirectory()) {\n\t\t\t\tyield* this.walkLocaleDirectory(join(dir.path, entry.name), `${ns}${entry.name}/`);\n\t\t\t} else if (entry.isFile() && entry.name.endsWith('.json')) {\n\t\t\t\tyield `${ns}${entry.name.slice(0, -5)}`;\n\t\t\t}\n\t\t}\n\t}\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { __name } from '../chunk-
|
|
1
|
+
import { __name } from '../chunk-2JTKI4GS.mjs';
|
|
2
2
|
import { container } from '@sapphire/pieces';
|
|
3
3
|
import { lazy } from '@sapphire/utilities';
|
|
4
4
|
import { Locale, BaseInteraction, Message, Guild, ChannelType } from 'discord.js';
|
|
@@ -111,5 +111,5 @@ function createLocalizedChoice(key, options) {
|
|
|
111
111
|
__name(createLocalizedChoice, "createLocalizedChoice");
|
|
112
112
|
|
|
113
113
|
export { applyDescriptionLocalizedBuilder, applyLocalizedBuilder, applyNameLocalizedBuilder, createLocalizedChoice, fetchLanguage, fetchT, getLocalizedData, resolveKey };
|
|
114
|
-
//# sourceMappingURL=
|
|
114
|
+
//# sourceMappingURL=functions.mjs.map
|
|
115
115
|
//# sourceMappingURL=functions.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/functions.ts"],"names":[],"mappings":";;;;;AAAA,SAAS,iBAAiB;AAC1B,SAAS,YAAY;AACr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AS,0BAKd,SAAY,KAAmC;AAChD,QAAM,SAAS,iBAAiB,GAAG;AACnC,SAAO,QAAQ,QAAQ,OAAO,KAAK,EAAE,qBAAqB,OAAO,aAAa;AAC/E;AARgB;AAgBT,SAAS,iCAKd,SAAY,KAAmC;AAChD,QAAM,SAAS,iBAAiB,GAAG;AACnC,SAAO,QAAQ,eAAe,OAAO,KAAK,EAAE,4BAA4B,OAAO,aAAa;AAC7F;AARgB;AA8DT,SAAS,sBAKd,YAAe,QAA6G;AAG7H,QAAM,CAAC,YAAY,iBAAiB,IACnC,OAAO,WAAW,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC,QAAyB,GAAG,OAAO,CAAC,CAAC,aAA8B,IAAI;AAE3G,4BAA0B,SAAS,UAAU;AAC7C,mCAAiC,SAAS,iBAAiB;AAE3D,SAAO;AACR;AAfgB;AA4CT,SAAS,sBAMf,KACA,SAC+C;AAC/C,QAAM,SAAS,iBAAiB,GAAG;AAEnC,SAAO;AAAA,IACN,GAAG;AAAA,IACH,MAAM,OAAO;AAAA,IACb,oBAAoB,OAAO;AAAA,EAC5B;AACD;AAhBgB","sourcesContent":["import { container } from '@sapphire/pieces';\nimport { lazy } from '@sapphire/utilities';\nimport { BaseInteraction, ChannelType, Guild, Locale, Message, type APIApplicationCommandOptionChoice, type LocaleString } from 'discord.js';\nimport type {\n\tAppendKeyPrefix,\n\tDefaultNamespace,\n\tInterpolationMap,\n\tNamespace,\n\tParseKeys,\n\tTFunctionReturn,\n\tTFunctionReturnOptionalDetails,\n\tTOptions\n} from 'i18next';\nimport type {\n\t$Dictionary,\n\t$SpecialObject,\n\tBuilderWithDescription,\n\tBuilderWithName,\n\tBuilderWithNameAndDescription,\n\tInternationalizationContext,\n\tLocalizedData,\n\tTarget\n} from './types';\n\n/**\n * Retrieves the language name for a specific target, using {@link InternationalizationHandler.fetchLanguage}.\n * If {@link InternationalizationHandler.fetchLanguage} is not defined or this function returns a nullish value,\n * then there will be a series of fallback attempts in the following descending order:\n * 1. Returns {@link Guild.preferredLocale}.\n * 2. Returns {@link InternationalizationOptions.defaultName} if no guild was provided.\n * 3. Returns `'en-US'` if nothing else was found.\n * @since 2.0.0\n * @param target The target to fetch the language from.\n * @see {@link resolveLanguage}\n * @returns The name of the language key.\n */\nexport function fetchLanguage(target: Target): Promise<string> {\n\t// Handle Interactions:\n\tif (target instanceof BaseInteraction) {\n\t\treturn resolveLanguage({\n\t\t\tuser: target.user,\n\t\t\tchannel: target.channel,\n\t\t\tguild: target.guild,\n\t\t\tinteractionGuildLocale: target.guildLocale,\n\t\t\tinteractionLocale: target.locale\n\t\t});\n\t}\n\n\t// Handle Message:\n\tif (target instanceof Message) {\n\t\treturn resolveLanguage({ user: target.author, channel: target.channel, guild: target.guild });\n\t}\n\n\t// Handle Guild:\n\tif (target instanceof Guild) {\n\t\treturn resolveLanguage({ user: null, channel: null, guild: target });\n\t}\n\n\t// Handle DMChannel:\n\tif (target.type === ChannelType.DM) {\n\t\treturn resolveLanguage({ user: null, channel: target, guild: null });\n\t}\n\n\t// Handle any other channel:\n\treturn resolveLanguage({ user: null, channel: target, guild: target.guild });\n}\n\n/**\n * Retrieves the language-assigned function from i18next designated to a target's preferred language code.\n * @since 2.0.0\n * @param target The target to fetch the language from.\n * @returns The language function from i18next.\n */\nexport async function fetchT(target: Target) {\n\treturn container.i18n.getT(await fetchLanguage(target));\n}\n\n/**\n * Resolves a key and its parameters.\n * @since 2.0.0\n * @param target The target to fetch the language key from.\n * @param key The i18next key.\n * @param options The options to be passed to TFunction.\n * @returns The data that `key` held, processed by i18next.\n */\nexport async function resolveKey<\n\tconst Key extends ParseKeys<Ns, TOpt, undefined>,\n\tconst TOpt extends TOptions = TOptions,\n\tRet extends TFunctionReturn<Ns, AppendKeyPrefix<Key, undefined>, TOpt> = TOpt['returnObjects'] extends true ? $SpecialObject : string,\n\tNs extends Namespace = DefaultNamespace,\n\tconst ActualOptions extends TOpt & InterpolationMap<Ret> = TOpt & InterpolationMap<Ret>\n>(\n\ttarget: Target,\n\t...[key, defaultValueOrOptions, optionsOrUndefined]:\n\t\t| [key: Key | Key[], options?: ActualOptions]\n\t\t| [key: string | string[], options: TOpt & $Dictionary & { defaultValue: string }]\n\t\t| [key: string | string[], defaultValue: string, options?: TOpt & $Dictionary]\n): Promise<TFunctionReturnOptionalDetails<Ret, TOpt>> {\n\tconst parsedOptions = typeof defaultValueOrOptions === 'string' ? optionsOrUndefined : defaultValueOrOptions;\n\tconst language = typeof parsedOptions?.lng === 'string' ? parsedOptions.lng : await fetchLanguage(target);\n\n\tif (typeof defaultValueOrOptions === 'string') {\n\t\treturn container.i18n.format<Key, TOpt, Ns, Ret, ActualOptions>(language, key, defaultValueOrOptions, optionsOrUndefined);\n\t}\n\n\treturn container.i18n.format<Key, TOpt, Ns, Ret, ActualOptions>(language, key, undefined, defaultValueOrOptions);\n}\n\n/**\n * @internal\n */\nasync function resolveLanguage(context: InternationalizationContext): Promise<string> {\n\tconst lang = await container.i18n.fetchLanguage(context);\n\treturn lang ?? context.guild?.preferredLocale ?? container.i18n.options.defaultName ?? 'en-US';\n}\n\nconst supportedLanguages = new Set(Object.values(Locale)) as ReadonlySet<LocaleString>;\n\nfunction isSupportedDiscordLocale(language: string): language is LocaleString {\n\treturn supportedLanguages.has(language as LocaleString);\n}\n\nconst getLocales = lazy(() => {\n\tconst locales = new Map(container.i18n.languages);\n\n\tfor (const [locale] of locales) {\n\t\tif (!isSupportedDiscordLocale(locale)) {\n\t\t\tprocess.emitWarning('Unsupported Discord locale', {\n\t\t\t\tcode: 'UNSUPPORTED_LOCALE',\n\t\t\t\tdetail: `'${locale}' needs to be one of: ${[...locales.keys()]}`\n\t\t\t});\n\n\t\t\tlocales.delete(locale);\n\t\t}\n\n\t\tcontinue;\n\t}\n\n\treturn locales;\n});\n\nconst getDefaultT = lazy(() => {\n\tconst defaultLocale = container.i18n.options.defaultName ?? 'en-US';\n\n\tif (!isSupportedDiscordLocale(defaultLocale)) {\n\t\tthrow new TypeError(`Unsupported Discord locale found:\\n'${defaultLocale}' is not within the list of ${[...supportedLanguages]}`);\n\t}\n\n\tconst defaultT = getLocales().get(defaultLocale);\n\n\tif (defaultT) {\n\t\treturn defaultT;\n\t}\n\n\tthrow new TypeError(`Could not find ${defaultLocale}`);\n});\n\n/**\n * Gets the value and the localizations from a language key.\n * @param key The key to get the localizations from.\n * @returns The retrieved data.\n * @remarks This should be called **strictly** after loading the locales.\n */\nexport function getLocalizedData<const TOpt extends TOptions = TOptions, Ns extends Namespace = DefaultNamespace, KPrefix = undefined>(\n\tkey: ParseKeys<Ns, TOpt, KPrefix>\n): LocalizedData {\n\tconst locales = getLocales();\n\tconst defaultT = getDefaultT();\n\n\treturn {\n\t\tvalue: defaultT(key),\n\t\tlocalizations: Object.fromEntries(Array.from(locales, ([locale, t]) => [locale, t(key)]))\n\t};\n}\n\n/**\n * Applies the localized names on the builder, calling `setName` and `setNameLocalizations`.\n * @param builder The builder to apply the localizations to.\n * @param key The key to get the localizations from.\n * @returns The updated builder.\n */\nexport function applyNameLocalizedBuilder<\n\tT extends BuilderWithName,\n\tconst TOpt extends TOptions = TOptions,\n\tNs extends Namespace = DefaultNamespace,\n\tKPrefix = undefined\n>(builder: T, key: ParseKeys<Ns, TOpt, KPrefix>) {\n\tconst result = getLocalizedData(key);\n\treturn builder.setName(result.value).setNameLocalizations(result.localizations);\n}\n\n/**\n * Applies the localized descriptions on the builder, calling `setDescription` and `setDescriptionLocalizations`.\n * @param builder The builder to apply the localizations to.\n * @param key The key to get the localizations from.\n * @returns The updated builder.\n */\nexport function applyDescriptionLocalizedBuilder<\n\tT extends BuilderWithDescription,\n\tconst TOpt extends TOptions = TOptions,\n\tNs extends Namespace = DefaultNamespace,\n\tKPrefix = undefined\n>(builder: T, key: ParseKeys<Ns, TOpt, KPrefix>) {\n\tconst result = getLocalizedData(key);\n\treturn builder.setDescription(result.value).setDescriptionLocalizations(result.localizations);\n}\n\n/**\n * Applies the localized names and descriptions on the builder, calling {@link applyNameLocalizedBuilder} and\n * {@link applyDescriptionLocalizedBuilder}.\n *\n * @param builder The builder to apply the localizations to.\n *\n * @param params The root key or the key for the name and description keys.\n * This needs to be either 1 or 2 parameters.\n * See examples below for more information.\n *\n * @returns The updated builder. You can chain subsequent builder methods on this.\n *\n * @remarks If only 2 parameters were passed, then this function will automatically append `Name` and `Description`\n * to the root-key (wherein `root-key` is second parameter in the function, after `builder`)\n * passed through the second parameter.\n *\n * For example given `applyLocalizedBuilder(builder, 'userinfo')` the localized options will use the i18next keys\n * `userinfoName` and `userinfoDescription`.\n *\n * In the following example we provide all parameters and add a User Option\n * `applyLocalizedBuilder` needs either\n * @example\n * ```typescript\n * class UserInfoCommand extends Command {\n * public registerApplicationCommands(registry: ChatInputCommand.Registry) {\n * registry.registerChatInputCommand(\n * (builder) =>\n * applyLocalizedBuilder(builder, 'commands/names:userinfo', 'commands/descriptions:userinfo')\n * .addUserOption(\n * (input) => applyLocalizedBuilder(input, 'commands/options:userinfo-name', 'commands/options:userinfo-description').setRequired(true)\n * )\n * );\n * }\n * }\n * ```\n *\n * In the following example we provide single root keys which means `Name` and `Description` get appended as mentioned above.\n * @example\n * ```typescript\n * class UserInfoCommand extends Command {\n * public registerApplicationCommands(registry: ChatInputCommand.Registry) {\n * registry.registerChatInputCommand(\n * (builder) =>\n * applyLocalizedBuilder(builder, 'commands:userinfo')\n * .addUserOption(\n * (input) => applyLocalizedBuilder(input, 'options:userinfo').setRequired(true)\n * )\n * );\n * }\n * }\n * ```\n */\nexport function applyLocalizedBuilder<\n\tT extends BuilderWithNameAndDescription,\n\tconst TOpt extends TOptions = TOptions,\n\tNs extends Namespace = DefaultNamespace,\n\tKPrefix = undefined\n>(builder: T, ...params: [root: string] | [name: ParseKeys<Ns, TOpt, KPrefix>, description: ParseKeys<Ns, TOpt, KPrefix>]): T {\n\ttype LocalKeysType = ParseKeys<Ns, TOpt, KPrefix>;\n\n\tconst [localeName, localeDescription] =\n\t\tparams.length === 1 ? [`${params[0]}Name` as LocalKeysType, `${params[0]}Description` as LocalKeysType] : params;\n\n\tapplyNameLocalizedBuilder(builder, localeName);\n\tapplyDescriptionLocalizedBuilder(builder, localeDescription);\n\n\treturn builder;\n}\n\n/**\n * Constructs an object that can be passed into `setChoices` for String or Number option with localized names.\n *\n * @param key The i18next key for the name of the select option name.\n * @param options The additional Select Menu options. This should _at least_ include the `value` key.\n * @returns An object with anything provided through {@link createLocalizedChoice.options} with `name` and `name_localizations` added.\n *\n * @example\n * ```typescript\n * export class TypeCommand extends Command {\n * public override registerApplicationCommands(registry: ChatInputCommand.Registry) {\n * registry.registerChatInputCommand((builder) =>\n * applyLocalizedBuilder(builder, 'commands/names:type').addStringOption((option) =>\n * applyLocalizedBuilder(option, 'commands/options:type')\n * .setRequired(true)\n * .setChoices(\n * createLocalizedChoice('selects/pokemon:type-grass', { value: 'grass' }),\n * createLocalizedChoice('selects/pokemon:type-water', { value: 'water' }),\n * createLocalizedChoice('selects/pokemon:type-fire', { value: 'fire' }),\n * createLocalizedChoice('selects/pokemon:type-electric', { value: 'electric' })\n * )\n * )\n * );\n * }\n * }\n * ```\n */\nexport function createLocalizedChoice<\n\tValueType = string | number,\n\tconst TOpt extends TOptions = TOptions,\n\tNs extends Namespace = DefaultNamespace,\n\tKPrefix = undefined\n>(\n\tkey: ParseKeys<Ns, TOpt, KPrefix>,\n\toptions: Omit<APIApplicationCommandOptionChoice<ValueType>, 'name' | 'name_localizations'>\n): APIApplicationCommandOptionChoice<ValueType> {\n\tconst result = getLocalizedData(key);\n\n\treturn {\n\t\t...options,\n\t\tname: result.value,\n\t\tname_localizations: result.localizations\n\t};\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/functions.ts"],"names":[],"mappings":";;;;;AAoCO,SAAS,cAAc,MAAiC,EAAA;AAE9D,EAAA,IAAI,kBAAkB,eAAiB,EAAA;AACtC,IAAA,OAAO,eAAgB,CAAA;AAAA,MACtB,MAAM,MAAO,CAAA,IAAA;AAAA,MACb,SAA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,OAC+C,EAAA;AAC/C,EAAM,MAAA,MAAA,GAAS,iBAAiB,GAAG,CAAA,CAAA;AAEnC,EAAO,OAAA;AAAA,IACN,GAAG,OAAA;AAAA,IACH,MAAM,MAAO,CAAA,KAAA;AAAA,IACb,oBAAoB,MAAO,CAAA,aAAA;AAAA,GAC5B,CAAA;AACD,CAAA;AAhBgB,MAAA,CAAA,qBAAA,EAAA,uBAAA,CAAA","file":"functions.mjs","sourcesContent":["import { container } from '@sapphire/pieces';\nimport { lazy } from '@sapphire/utilities';\nimport { BaseInteraction, ChannelType, Guild, Locale, Message, type APIApplicationCommandOptionChoice, type LocaleString } from 'discord.js';\nimport type {\n\tAppendKeyPrefix,\n\tDefaultNamespace,\n\tInterpolationMap,\n\tNamespace,\n\tParseKeys,\n\tTFunctionReturn,\n\tTFunctionReturnOptionalDetails,\n\tTOptions\n} from 'i18next';\nimport type {\n\t$Dictionary,\n\t$SpecialObject,\n\tBuilderWithDescription,\n\tBuilderWithName,\n\tBuilderWithNameAndDescription,\n\tInternationalizationContext,\n\tLocalizedData,\n\tTarget\n} from './types';\n\n/**\n * Retrieves the language name for a specific target, using {@link InternationalizationHandler.fetchLanguage}.\n * If {@link InternationalizationHandler.fetchLanguage} is not defined or this function returns a nullish value,\n * then there will be a series of fallback attempts in the following descending order:\n * 1. Returns {@link Guild.preferredLocale}.\n * 2. Returns {@link InternationalizationOptions.defaultName} if no guild was provided.\n * 3. Returns `'en-US'` if nothing else was found.\n * @since 2.0.0\n * @param target The target to fetch the language from.\n * @see {@link resolveLanguage}\n * @returns The name of the language key.\n */\nexport function fetchLanguage(target: Target): Promise<string> {\n\t// Handle Interactions:\n\tif (target instanceof BaseInteraction) {\n\t\treturn resolveLanguage({\n\t\t\tuser: target.user,\n\t\t\tchannel: target.channel,\n\t\t\tguild: target.guild,\n\t\t\tinteractionGuildLocale: target.guildLocale,\n\t\t\tinteractionLocale: target.locale\n\t\t});\n\t}\n\n\t// Handle Message:\n\tif (target instanceof Message) {\n\t\treturn resolveLanguage({ user: target.author, channel: target.channel, guild: target.guild });\n\t}\n\n\t// Handle Guild:\n\tif (target instanceof Guild) {\n\t\treturn resolveLanguage({ user: null, channel: null, guild: target });\n\t}\n\n\t// Handle DMChannel:\n\tif (target.type === ChannelType.DM) {\n\t\treturn resolveLanguage({ user: null, channel: target, guild: null });\n\t}\n\n\t// Handle any other channel:\n\treturn resolveLanguage({ user: null, channel: target, guild: target.guild });\n}\n\n/**\n * Retrieves the language-assigned function from i18next designated to a target's preferred language code.\n * @since 2.0.0\n * @param target The target to fetch the language from.\n * @returns The language function from i18next.\n */\nexport async function fetchT(target: Target) {\n\treturn container.i18n.getT(await fetchLanguage(target));\n}\n\n/**\n * Resolves a key and its parameters.\n * @since 2.0.0\n * @param target The target to fetch the language key from.\n * @param key The i18next key.\n * @param options The options to be passed to TFunction.\n * @returns The data that `key` held, processed by i18next.\n */\nexport async function resolveKey<\n\tconst Key extends ParseKeys<Ns, TOpt, undefined>,\n\tconst TOpt extends TOptions = TOptions,\n\tRet extends TFunctionReturn<Ns, AppendKeyPrefix<Key, undefined>, TOpt> = TOpt['returnObjects'] extends true ? $SpecialObject : string,\n\tNs extends Namespace = DefaultNamespace,\n\tconst ActualOptions extends TOpt & InterpolationMap<Ret> = TOpt & InterpolationMap<Ret>\n>(target: Target, key: Key | Key[], options?: ActualOptions): Promise<TFunctionReturnOptionalDetails<Ret, TOpt>>;\n\n/**\n * Resolves a key and its parameters.\n * @since 2.0.0\n * @param target The target to fetch the language key from.\n * @param key The i18next key.\n * @param options The interpolation options as well as a `defaultValue` for the key and any key/value pairs.\n * @returns The data that `key` held, processed by i18next.\n */\nexport async function resolveKey<\n\tconst Key extends ParseKeys<Ns, TOpt, undefined>,\n\tconst TOpt extends TOptions = TOptions,\n\tRet extends TFunctionReturn<Ns, AppendKeyPrefix<Key, undefined>, TOpt> = TOpt['returnObjects'] extends true ? $SpecialObject : string,\n\tNs extends Namespace = DefaultNamespace,\n\tconst ActualOptions extends TOpt & InterpolationMap<Ret> = TOpt & InterpolationMap<Ret>\n>(target: Target, key: string | string[], options: TOpt & $Dictionary & { defaultValue: string }): Promise<TFunctionReturnOptionalDetails<Ret, TOpt>>;\n\n/**\n * Resolves a key and its parameters.\n * @since 2.0.0\n * @param target The target to fetch the language key from.\n * @param key The i18next key.\n * @param defaultValue The default value to use if the key is not found.\n * @param options The interpolation options.\n * @returns The data that `key` held, processed by i18next.\n */\nexport async function resolveKey<\n\tconst Key extends ParseKeys<Ns, TOpt, undefined>,\n\tconst TOpt extends TOptions = TOptions,\n\tRet extends TFunctionReturn<Ns, AppendKeyPrefix<Key, undefined>, TOpt> = TOpt['returnObjects'] extends true ? $SpecialObject : string,\n\tNs extends Namespace = DefaultNamespace,\n\tconst ActualOptions extends TOpt & InterpolationMap<Ret> = TOpt & InterpolationMap<Ret>\n>(target: Target, key: string | string[], defaultValue: string, options?: TOpt & $Dictionary): Promise<TFunctionReturnOptionalDetails<Ret, TOpt>>;\n\n/**\n * Resolves a key and its parameters.\n * @since 2.0.0\n * @param target The target to fetch the language key from.\n *\n * @remark This function also has additional parameters for `key`, `defaultValue`, and `options`, however\n * TSDoc does not let us document those while matching proper implementation. See the overloads for this method\n * for the documentation on those parameters.\n *\n * @returns The data that `key` held, processed by i18next.\n */\nexport async function resolveKey<\n\tconst Key extends ParseKeys<Ns, TOpt, undefined>,\n\tconst TOpt extends TOptions = TOptions,\n\tRet extends TFunctionReturn<Ns, AppendKeyPrefix<Key, undefined>, TOpt> = TOpt['returnObjects'] extends true ? $SpecialObject : string,\n\tNs extends Namespace = DefaultNamespace,\n\tconst ActualOptions extends TOpt & InterpolationMap<Ret> = TOpt & InterpolationMap<Ret>\n>(\n\ttarget: Target,\n\t...[key, defaultValueOrOptions, optionsOrUndefined]:\n\t\t| [key: Key | Key[], options?: ActualOptions]\n\t\t| [key: string | string[], options: TOpt & $Dictionary & { defaultValue: string }]\n\t\t| [key: string | string[], defaultValue: string, options?: TOpt & $Dictionary]\n): Promise<TFunctionReturnOptionalDetails<Ret, TOpt>> {\n\tconst parsedOptions = typeof defaultValueOrOptions === 'string' ? optionsOrUndefined : defaultValueOrOptions;\n\tconst language = typeof parsedOptions?.lng === 'string' ? parsedOptions.lng : await fetchLanguage(target);\n\n\tif (typeof defaultValueOrOptions === 'string') {\n\t\treturn container.i18n.format<Key, TOpt, Ns, Ret, ActualOptions>(language, key, defaultValueOrOptions, optionsOrUndefined);\n\t}\n\n\treturn container.i18n.format<Key, TOpt, Ns, Ret, ActualOptions>(language, key, undefined, defaultValueOrOptions);\n}\n\n/**\n * @internal\n */\nasync function resolveLanguage(context: InternationalizationContext): Promise<string> {\n\tconst lang = await container.i18n.fetchLanguage(context);\n\treturn lang ?? context.guild?.preferredLocale ?? container.i18n.options.defaultName ?? 'en-US';\n}\n\nconst supportedLanguages = new Set(Object.values(Locale)) as ReadonlySet<LocaleString>;\n\nfunction isSupportedDiscordLocale(language: string): language is LocaleString {\n\treturn supportedLanguages.has(language as LocaleString);\n}\n\nconst getLocales = lazy(() => {\n\tconst locales = new Map(container.i18n.languages);\n\n\tfor (const [locale] of locales) {\n\t\tif (!isSupportedDiscordLocale(locale)) {\n\t\t\tprocess.emitWarning('Unsupported Discord locale', {\n\t\t\t\tcode: 'UNSUPPORTED_LOCALE',\n\t\t\t\tdetail: `'${locale}' needs to be one of: ${[...locales.keys()]}`\n\t\t\t});\n\n\t\t\tlocales.delete(locale);\n\t\t}\n\n\t\tcontinue;\n\t}\n\n\treturn locales;\n});\n\nconst getDefaultT = lazy(() => {\n\tconst defaultLocale = container.i18n.options.defaultName ?? 'en-US';\n\n\tif (!isSupportedDiscordLocale(defaultLocale)) {\n\t\tthrow new TypeError(`Unsupported Discord locale found:\\n'${defaultLocale}' is not within the list of ${[...supportedLanguages]}`);\n\t}\n\n\tconst defaultT = getLocales().get(defaultLocale);\n\n\tif (defaultT) {\n\t\treturn defaultT;\n\t}\n\n\tthrow new TypeError(`Could not find ${defaultLocale}`);\n});\n\n/**\n * Gets the value and the localizations from a language key.\n * @param key The key to get the localizations from.\n * @returns The retrieved data.\n * @remarks This should be called **strictly** after loading the locales.\n */\nexport function getLocalizedData<const TOpt extends TOptions = TOptions, Ns extends Namespace = DefaultNamespace, KPrefix = undefined>(\n\tkey: ParseKeys<Ns, TOpt, KPrefix>\n): LocalizedData {\n\tconst locales = getLocales();\n\tconst defaultT = getDefaultT();\n\n\treturn {\n\t\tvalue: defaultT(key),\n\t\tlocalizations: Object.fromEntries(Array.from(locales, ([locale, t]) => [locale, t(key)]))\n\t};\n}\n\n/**\n * Applies the localized names on the builder, calling `setName` and `setNameLocalizations`.\n * @param builder The builder to apply the localizations to.\n * @param key The key to get the localizations from.\n * @returns The updated builder.\n */\nexport function applyNameLocalizedBuilder<\n\tT extends BuilderWithName,\n\tconst TOpt extends TOptions = TOptions,\n\tNs extends Namespace = DefaultNamespace,\n\tKPrefix = undefined\n>(builder: T, key: ParseKeys<Ns, TOpt, KPrefix>) {\n\tconst result = getLocalizedData(key);\n\treturn builder.setName(result.value).setNameLocalizations(result.localizations);\n}\n\n/**\n * Applies the localized descriptions on the builder, calling `setDescription` and `setDescriptionLocalizations`.\n * @param builder The builder to apply the localizations to.\n * @param key The key to get the localizations from.\n * @returns The updated builder.\n */\nexport function applyDescriptionLocalizedBuilder<\n\tT extends BuilderWithDescription,\n\tconst TOpt extends TOptions = TOptions,\n\tNs extends Namespace = DefaultNamespace,\n\tKPrefix = undefined\n>(builder: T, key: ParseKeys<Ns, TOpt, KPrefix>) {\n\tconst result = getLocalizedData(key);\n\treturn builder.setDescription(result.value).setDescriptionLocalizations(result.localizations);\n}\n\n/**\n * Applies the localized names and descriptions on the builder, calling {@link applyNameLocalizedBuilder} and\n * {@link applyDescriptionLocalizedBuilder}.\n *\n * @param builder The builder to apply the localizations to.\n *\n * @param params The root key or the key for the name and description keys.\n * This needs to be either 1 or 2 parameters.\n * See examples below for more information.\n *\n * @returns The updated builder. You can chain subsequent builder methods on this.\n *\n * @remarks If only 2 parameters were passed, then this function will automatically append `Name` and `Description`\n * to the root-key (wherein `root-key` is second parameter in the function, after `builder`)\n * passed through the second parameter.\n *\n * For example given `applyLocalizedBuilder(builder, 'userinfo')` the localized options will use the i18next keys\n * `userinfoName` and `userinfoDescription`.\n *\n * In the following example we provide all parameters and add a User Option\n * `applyLocalizedBuilder` needs either\n * @example\n * ```typescript\n * class UserInfoCommand extends Command {\n * public registerApplicationCommands(registry: ChatInputCommand.Registry) {\n * registry.registerChatInputCommand(\n * (builder) =>\n * applyLocalizedBuilder(builder, 'commands/names:userinfo', 'commands/descriptions:userinfo')\n * .addUserOption(\n * (input) => applyLocalizedBuilder(input, 'commands/options:userinfo-name', 'commands/options:userinfo-description').setRequired(true)\n * )\n * );\n * }\n * }\n * ```\n *\n * In the following example we provide single root keys which means `Name` and `Description` get appended as mentioned above.\n * @example\n * ```typescript\n * class UserInfoCommand extends Command {\n * public registerApplicationCommands(registry: ChatInputCommand.Registry) {\n * registry.registerChatInputCommand(\n * (builder) =>\n * applyLocalizedBuilder(builder, 'commands:userinfo')\n * .addUserOption(\n * (input) => applyLocalizedBuilder(input, 'options:userinfo').setRequired(true)\n * )\n * );\n * }\n * }\n * ```\n */\nexport function applyLocalizedBuilder<\n\tT extends BuilderWithNameAndDescription,\n\tconst TOpt extends TOptions = TOptions,\n\tNs extends Namespace = DefaultNamespace,\n\tKPrefix = undefined\n>(builder: T, ...params: [root: string] | [name: ParseKeys<Ns, TOpt, KPrefix>, description: ParseKeys<Ns, TOpt, KPrefix>]): T {\n\ttype LocalKeysType = ParseKeys<Ns, TOpt, KPrefix>;\n\n\tconst [localeName, localeDescription] =\n\t\tparams.length === 1 ? [`${params[0]}Name` as LocalKeysType, `${params[0]}Description` as LocalKeysType] : params;\n\n\tapplyNameLocalizedBuilder(builder, localeName);\n\tapplyDescriptionLocalizedBuilder(builder, localeDescription);\n\n\treturn builder;\n}\n\n/**\n * Constructs an object that can be passed into `setChoices` for String or Number option with localized names.\n *\n * @param key The i18next key for the name of the select option name.\n * @param options The additional Select Menu options. This should _at least_ include the `value` key.\n * @returns An object with anything provided through {@link createLocalizedChoice.options} with `name` and `name_localizations` added.\n *\n * @example\n * ```typescript\n * export class TypeCommand extends Command {\n * public override registerApplicationCommands(registry: ChatInputCommand.Registry) {\n * registry.registerChatInputCommand((builder) =>\n * applyLocalizedBuilder(builder, 'commands/names:type').addStringOption((option) =>\n * applyLocalizedBuilder(option, 'commands/options:type')\n * .setRequired(true)\n * .setChoices(\n * createLocalizedChoice('selects/pokemon:type-grass', { value: 'grass' }),\n * createLocalizedChoice('selects/pokemon:type-water', { value: 'water' }),\n * createLocalizedChoice('selects/pokemon:type-fire', { value: 'fire' }),\n * createLocalizedChoice('selects/pokemon:type-electric', { value: 'electric' })\n * )\n * )\n * );\n * }\n * }\n * ```\n */\nexport function createLocalizedChoice<\n\tValueType = string | number,\n\tconst TOpt extends TOptions = TOptions,\n\tNs extends Namespace = DefaultNamespace,\n\tKPrefix = undefined\n>(\n\tkey: ParseKeys<Ns, TOpt, KPrefix>,\n\toptions: Omit<APIApplicationCommandOptionChoice<ValueType>, 'name' | 'name_localizations'>\n): APIApplicationCommandOptionChoice<ValueType> {\n\tconst result = getLocalizedData(key);\n\n\treturn {\n\t\t...options,\n\t\tname: result.value,\n\t\tname_localizations: result.localizations\n\t};\n}\n"]}
|
package/dist/esm/lib/types.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"types.mjs"}
|
package/dist/esm/register.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { __name } from './chunk-
|
|
1
|
+
import { __name } from './chunk-2JTKI4GS.mjs';
|
|
2
2
|
import { InternationalizationHandler } from './index.mjs';
|
|
3
3
|
import { SapphireClient, preGenericsInitialization, preLogin, postLogin, Plugin, container } from '@sapphire/framework';
|
|
4
4
|
import { watch } from 'chokidar';
|
|
@@ -14,8 +14,7 @@ var _I18nextPlugin = class _I18nextPlugin extends Plugin {
|
|
|
14
14
|
if (this.options.i18n?.hmr?.enabled) {
|
|
15
15
|
container.logger.info("[i18next-Plugin]: HMR enabled. Watching for languages changes.");
|
|
16
16
|
const hmr = watch(container.i18n.languagesDirectory, this.options.i18n.hmr.options);
|
|
17
|
-
for (const event of ["change", "unlink"])
|
|
18
|
-
hmr.on(event, () => container.i18n.reloadResources());
|
|
17
|
+
for (const event of ["change", "unlink"]) hmr.on(event, () => container.i18n.reloadResources());
|
|
19
18
|
}
|
|
20
19
|
}
|
|
21
20
|
};
|
|
@@ -26,5 +25,5 @@ SapphireClient.plugins.registerPreLoginHook(I18nextPlugin[preLogin], "I18next-Pr
|
|
|
26
25
|
SapphireClient.plugins.registerPostLoginHook(I18nextPlugin[postLogin], "I18next-PostLogin");
|
|
27
26
|
|
|
28
27
|
export { I18nextPlugin };
|
|
29
|
-
//# sourceMappingURL=
|
|
28
|
+
//# sourceMappingURL=register.mjs.map
|
|
30
29
|
//# sourceMappingURL=register.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/register.ts"],"names":[],"mappings":";;;;;
|
|
1
|
+
{"version":3,"sources":["../../src/register.ts"],"names":[],"mappings":";;;;;AAOO,IAAM,cAAA,GAAN,MAAM,cAAA,SAAsB,MAAO,CAAA;AAAA,EACzC,QAAe,yBAAyB,CAAA,CAAwB,OAA8B,EAAA;AAC7F,IAAA,SAAA,CAAU,IAAO,GAAA,IAAI,2BAA4B,CAAA,OAAA,CAAQ,IAAI,CAAA,CAAA;AAAA,GAC9D;AAAA,EAEA,cAAqB,QAAQ,CAAuC,GAAA;AACnE,IAAM,MAAA,SAAA,CAAU,KAAK,IAAK,EAAA,CAAA;AAAA,GAC3B;AAAA,EAEA,QAAe,SAAS,CAA8B,GAAA;AACrD,IAAA,IAAI,IAAK,CAAA,OAAA,CAAQ,IAAM,EAAA,GAAA,EAAK,OAAS,EAAA;AACpC,MAAU,SAAA,CAAA,MAAA,CAAO,KAAK,gEAAgE,CAAA,CAAA;AACtF,MAAM,MAAA,GAAA,GAAM,MAAM,SAAU,CAAA,IAAA,CAAK,oBAAoB,IAAK,CAAA,OAAA,CAAQ,IAAK,CAAA,GAAA,CAAI,OAAO,CAAA,CAAA;AAElF,MAAA,KAAA,MAAW,KAAS,IAAA,CAAC,QAAU,EAAA,QAAQ,CAAG,EAAA,GAAA,CAAI,EAAG,CAAA,KAAA,EAAO,MAAM,SAAA,CAAU,IAAK,CAAA,eAAA,EAAiB,CAAA,CAAA;AAAA,KAC/F;AAAA,GACD;AACD,CAAA,CAAA;AAjB0C,MAAA,CAAA,cAAA,EAAA,eAAA,CAAA,CAAA;AAAnC,IAAM,aAAN,GAAA,eAAA;AAmBP,cAAA,CAAe,OAAQ,CAAA,8BAAA,CAA+B,aAAc,CAAA,yBAAyB,GAAG,mCAAmC,CAAA,CAAA;AACnI,cAAA,CAAe,OAAQ,CAAA,oBAAA,CAAqB,aAAc,CAAA,QAAQ,GAAG,kBAAkB,CAAA,CAAA;AACvF,cAAA,CAAe,OAAQ,CAAA,qBAAA,CAAsB,aAAc,CAAA,SAAS,GAAG,mBAAmB,CAAA","file":"register.mjs","sourcesContent":["import './index';\n\nimport { Plugin, SapphireClient, container, postLogin, preGenericsInitialization, preLogin } from '@sapphire/framework';\nimport { watch } from 'chokidar';\nimport type { ClientOptions } from 'discord.js';\nimport { InternationalizationHandler } from './index';\n\nexport class I18nextPlugin extends Plugin {\n\tpublic static [preGenericsInitialization](this: SapphireClient, options: ClientOptions): void {\n\t\tcontainer.i18n = new InternationalizationHandler(options.i18n);\n\t}\n\n\tpublic static async [preLogin](this: SapphireClient): Promise<void> {\n\t\tawait container.i18n.init();\n\t}\n\n\tpublic static [postLogin](this: SapphireClient): void {\n\t\tif (this.options.i18n?.hmr?.enabled) {\n\t\t\tcontainer.logger.info('[i18next-Plugin]: HMR enabled. Watching for languages changes.');\n\t\t\tconst hmr = watch(container.i18n.languagesDirectory, this.options.i18n.hmr.options);\n\n\t\t\tfor (const event of ['change', 'unlink']) hmr.on(event, () => container.i18n.reloadResources());\n\t\t}\n\t}\n}\n\nSapphireClient.plugins.registerPostInitializationHook(I18nextPlugin[preGenericsInitialization], 'I18next-PreGenericsInitialization');\nSapphireClient.plugins.registerPreLoginHook(I18nextPlugin[preLogin], 'I18next-PreLogin');\nSapphireClient.plugins.registerPostLoginHook(I18nextPlugin[postLogin], 'I18next-PostLogin');\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sapphire/plugin-i18next",
|
|
3
|
-
"version": "7.1.3-next.
|
|
3
|
+
"version": "7.1.3-next.fc8c5ba",
|
|
4
4
|
"description": "Plugin for @sapphire/framework to support i18next.",
|
|
5
5
|
"author": "@sapphire",
|
|
6
6
|
"license": "MIT",
|
|
@@ -50,10 +50,10 @@
|
|
|
50
50
|
"check-update": "cliff-jumper --dry-run"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"@sapphire/utilities": "^3.
|
|
53
|
+
"@sapphire/utilities": "^3.17.0",
|
|
54
54
|
"@skyra/i18next-backend": "^2.0.5",
|
|
55
55
|
"chokidar": "^3.6.0",
|
|
56
|
-
"i18next": "^23.
|
|
56
|
+
"i18next": "^23.12.2"
|
|
57
57
|
},
|
|
58
58
|
"repository": {
|
|
59
59
|
"type": "git",
|
|
@@ -86,13 +86,13 @@
|
|
|
86
86
|
"access": "public"
|
|
87
87
|
},
|
|
88
88
|
"devDependencies": {
|
|
89
|
-
"@favware/cliff-jumper": "^
|
|
89
|
+
"@favware/cliff-jumper": "^4.0.3",
|
|
90
90
|
"@favware/rollup-type-bundler": "^3.3.0",
|
|
91
91
|
"concurrently": "^8.2.2",
|
|
92
|
-
"tsup": "^8.
|
|
93
|
-
"tsx": "^4.
|
|
92
|
+
"tsup": "^8.2.4",
|
|
93
|
+
"tsx": "^4.17.0",
|
|
94
94
|
"typedoc": "^0.25.13",
|
|
95
95
|
"typedoc-json-parser": "^10.0.0",
|
|
96
|
-
"typescript": "
|
|
96
|
+
"typescript": "~5.4.5"
|
|
97
97
|
}
|
|
98
98
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[]}
|