@sapphire/plugin-i18next 6.1.1-next.eccc557.0 → 7.0.0-next.1f2cccc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.cjs +39 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/cjs/index.d.ts +428 -0
- package/dist/cjs/lib/Augmentations.d.cjs +4 -0
- package/dist/cjs/lib/Augmentations.d.cjs.map +1 -0
- package/dist/cjs/lib/InternationalizationHandler.cjs +236 -0
- package/dist/cjs/lib/InternationalizationHandler.cjs.map +1 -0
- package/dist/cjs/lib/functions.cjs +125 -0
- package/dist/cjs/lib/functions.cjs.map +1 -0
- package/dist/cjs/lib/types.cjs +4 -0
- package/dist/cjs/lib/types.cjs.map +1 -0
- package/dist/cjs/register.cjs +33 -0
- package/dist/cjs/register.cjs.map +1 -0
- package/dist/cjs/register.d.ts +10 -0
- package/dist/esm/chunk-6QB3UK4Q.mjs +11 -0
- package/dist/esm/chunk-6QB3UK4Q.mjs.map +1 -0
- package/dist/esm/index.d.mts +428 -0
- package/dist/esm/index.mjs +11 -0
- package/dist/esm/index.mjs.map +1 -0
- package/dist/esm/lib/Augmentations.d.mjs +3 -0
- package/dist/esm/lib/Augmentations.d.mjs.map +1 -0
- package/dist/esm/lib/InternationalizationHandler.mjs +224 -0
- package/dist/esm/lib/InternationalizationHandler.mjs.map +1 -0
- package/dist/esm/lib/functions.mjs +115 -0
- package/dist/esm/lib/functions.mjs.map +1 -0
- package/dist/esm/lib/types.mjs +3 -0
- package/dist/esm/lib/types.mjs.map +1 -0
- package/dist/esm/register.d.mts +10 -0
- package/dist/esm/register.mjs +30 -0
- package/dist/esm/register.mjs.map +1 -0
- package/package.json +37 -22
- package/dist/index.d.ts +0 -16
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -26
- package/dist/index.js.map +0 -1
- package/dist/index.mjs +0 -13
- package/dist/lib/InternationalizationHandler.d.ts +0 -127
- package/dist/lib/InternationalizationHandler.d.ts.map +0 -1
- package/dist/lib/InternationalizationHandler.js +0 -271
- package/dist/lib/InternationalizationHandler.js.map +0 -1
- package/dist/lib/functions.d.ts +0 -137
- package/dist/lib/functions.d.ts.map +0 -1
- package/dist/lib/functions.js +0 -241
- package/dist/lib/functions.js.map +0 -1
- package/dist/lib/types.d.ts +0 -151
- package/dist/lib/types.d.ts.map +0 -1
- package/dist/lib/types.js +0 -3
- package/dist/lib/types.js.map +0 -1
- package/dist/register.d.ts +0 -9
- package/dist/register.d.ts.map +0 -1
- package/dist/register.js +0 -28
- package/dist/register.js.map +0 -1
- package/dist/register.mjs +0 -4
|
@@ -0,0 +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,aASA;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,wBAAO,cAAa,oBAAI,IAAY;AAMpC;AAAA;AAAA;AAAA;AAAA,wBAAgB,aAAY,oBAAI,IAAuB;AAMvD;AAAA;AAAA;AAAA;AAAA,wBAAgB;AAOhB;AAAA;AAAA;AAAA;AAAA;AAAA,wBAAgB;AAMhB;AAAA;AAAA;AAAA;AAAA,wBAAmB;AAqEnB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;A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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 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, 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 formatters = this.options.formatters ?? [];\n\t\tfor (const { name, format } of formatters) {\n\t\t\ti18next.services.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,\n\t\tNs extends Namespace,\n\t\tRet extends TFunctionReturn<Ns, AppendKeyPrefix<Key, undefined>, TOpt>,\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 ? language(this.options.defaultMissingKey, { replace: { key } })\n\t\t\t\t : '';\n\n\t\treturn language<Key, TOpt, Ret, ActualOptions>(key, defaultValue, optionsOrUndefined);\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"]}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { __name } from '../chunk-6QB3UK4Q.mjs';
|
|
2
|
+
import { container } from '@sapphire/pieces';
|
|
3
|
+
import { lazy } from '@sapphire/utilities';
|
|
4
|
+
import { Locale, BaseInteraction, Message, Guild, ChannelType } from 'discord.js';
|
|
5
|
+
|
|
6
|
+
function fetchLanguage(target) {
|
|
7
|
+
if (target instanceof BaseInteraction) {
|
|
8
|
+
return resolveLanguage({
|
|
9
|
+
user: target.user,
|
|
10
|
+
channel: target.channel,
|
|
11
|
+
guild: target.guild,
|
|
12
|
+
interactionGuildLocale: target.guildLocale,
|
|
13
|
+
interactionLocale: target.locale
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
if (target instanceof Message) {
|
|
17
|
+
return resolveLanguage({ user: target.author, channel: target.channel, guild: target.guild });
|
|
18
|
+
}
|
|
19
|
+
if (target instanceof Guild) {
|
|
20
|
+
return resolveLanguage({ user: null, channel: null, guild: target });
|
|
21
|
+
}
|
|
22
|
+
if (target.type === ChannelType.DM) {
|
|
23
|
+
return resolveLanguage({ user: null, channel: target, guild: null });
|
|
24
|
+
}
|
|
25
|
+
return resolveLanguage({ user: null, channel: target, guild: target.guild });
|
|
26
|
+
}
|
|
27
|
+
__name(fetchLanguage, "fetchLanguage");
|
|
28
|
+
async function fetchT(target) {
|
|
29
|
+
return container.i18n.getT(await fetchLanguage(target));
|
|
30
|
+
}
|
|
31
|
+
__name(fetchT, "fetchT");
|
|
32
|
+
async function resolveKey(target, ...[key, defaultValueOrOptions, optionsOrUndefined]) {
|
|
33
|
+
const parsedOptions = typeof defaultValueOrOptions === "string" ? optionsOrUndefined : defaultValueOrOptions;
|
|
34
|
+
const language = typeof parsedOptions?.lng === "string" ? parsedOptions.lng : await fetchLanguage(target);
|
|
35
|
+
if (typeof defaultValueOrOptions === "string") {
|
|
36
|
+
return container.i18n.format(language, key, defaultValueOrOptions, optionsOrUndefined);
|
|
37
|
+
}
|
|
38
|
+
return container.i18n.format(language, key, void 0, defaultValueOrOptions);
|
|
39
|
+
}
|
|
40
|
+
__name(resolveKey, "resolveKey");
|
|
41
|
+
async function resolveLanguage(context) {
|
|
42
|
+
const lang = await container.i18n.fetchLanguage(context);
|
|
43
|
+
return lang ?? context.guild?.preferredLocale ?? container.i18n.options.defaultName ?? "en-US";
|
|
44
|
+
}
|
|
45
|
+
__name(resolveLanguage, "resolveLanguage");
|
|
46
|
+
var supportedLanguages = new Set(Object.values(Locale));
|
|
47
|
+
function isSupportedDiscordLocale(language) {
|
|
48
|
+
return supportedLanguages.has(language);
|
|
49
|
+
}
|
|
50
|
+
__name(isSupportedDiscordLocale, "isSupportedDiscordLocale");
|
|
51
|
+
var getLocales = lazy(() => {
|
|
52
|
+
const locales = new Map(container.i18n.languages);
|
|
53
|
+
for (const [locale] of locales) {
|
|
54
|
+
if (!isSupportedDiscordLocale(locale)) {
|
|
55
|
+
process.emitWarning("Unsupported Discord locale", {
|
|
56
|
+
code: "UNSUPPORTED_LOCALE",
|
|
57
|
+
detail: `'${locale}' needs to be one of: ${[...locales.keys()]}`
|
|
58
|
+
});
|
|
59
|
+
locales.delete(locale);
|
|
60
|
+
}
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
return locales;
|
|
64
|
+
});
|
|
65
|
+
var getDefaultT = lazy(() => {
|
|
66
|
+
const defaultLocale = container.i18n.options.defaultName ?? "en-US";
|
|
67
|
+
if (!isSupportedDiscordLocale(defaultLocale)) {
|
|
68
|
+
throw new TypeError(`Unsupported Discord locale found:
|
|
69
|
+
'${defaultLocale}' is not within the list of ${[...supportedLanguages]}`);
|
|
70
|
+
}
|
|
71
|
+
const defaultT = getLocales().get(defaultLocale);
|
|
72
|
+
if (defaultT) {
|
|
73
|
+
return defaultT;
|
|
74
|
+
}
|
|
75
|
+
throw new TypeError(`Could not find ${defaultLocale}`);
|
|
76
|
+
});
|
|
77
|
+
function getLocalizedData(key) {
|
|
78
|
+
const locales = getLocales();
|
|
79
|
+
const defaultT = getDefaultT();
|
|
80
|
+
return {
|
|
81
|
+
value: defaultT(key),
|
|
82
|
+
localizations: Object.fromEntries(Array.from(locales, ([locale, t]) => [locale, t(key)]))
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
__name(getLocalizedData, "getLocalizedData");
|
|
86
|
+
function applyNameLocalizedBuilder(builder, key) {
|
|
87
|
+
const result = getLocalizedData(key);
|
|
88
|
+
return builder.setName(result.value).setNameLocalizations(result.localizations);
|
|
89
|
+
}
|
|
90
|
+
__name(applyNameLocalizedBuilder, "applyNameLocalizedBuilder");
|
|
91
|
+
function applyDescriptionLocalizedBuilder(builder, key) {
|
|
92
|
+
const result = getLocalizedData(key);
|
|
93
|
+
return builder.setDescription(result.value).setDescriptionLocalizations(result.localizations);
|
|
94
|
+
}
|
|
95
|
+
__name(applyDescriptionLocalizedBuilder, "applyDescriptionLocalizedBuilder");
|
|
96
|
+
function applyLocalizedBuilder(builder, ...params) {
|
|
97
|
+
const [localeName, localeDescription] = params.length === 1 ? [`${params[0]}Name`, `${params[0]}Description`] : params;
|
|
98
|
+
applyNameLocalizedBuilder(builder, localeName);
|
|
99
|
+
applyDescriptionLocalizedBuilder(builder, localeDescription);
|
|
100
|
+
return builder;
|
|
101
|
+
}
|
|
102
|
+
__name(applyLocalizedBuilder, "applyLocalizedBuilder");
|
|
103
|
+
function createLocalizedChoice(key, options) {
|
|
104
|
+
const result = getLocalizedData(key);
|
|
105
|
+
return {
|
|
106
|
+
...options,
|
|
107
|
+
name: result.value,
|
|
108
|
+
name_localizations: result.localizations
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
__name(createLocalizedChoice, "createLocalizedChoice");
|
|
112
|
+
|
|
113
|
+
export { applyDescriptionLocalizedBuilder, applyLocalizedBuilder, applyNameLocalizedBuilder, createLocalizedChoice, fetchLanguage, fetchT, getLocalizedData, resolveKey };
|
|
114
|
+
//# sourceMappingURL=out.js.map
|
|
115
|
+
//# sourceMappingURL=functions.mjs.map
|
|
@@ -0,0 +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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qB,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"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Plugin, preGenericsInitialization, SapphireClient, preLogin, postLogin } from '@sapphire/framework';
|
|
2
|
+
import { ClientOptions } from 'discord.js';
|
|
3
|
+
|
|
4
|
+
declare class I18nextPlugin extends Plugin {
|
|
5
|
+
static [preGenericsInitialization](this: SapphireClient, options: ClientOptions): void;
|
|
6
|
+
static [preLogin](this: SapphireClient): Promise<void>;
|
|
7
|
+
static [postLogin](this: SapphireClient): void;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export { I18nextPlugin };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { __name } from './chunk-6QB3UK4Q.mjs';
|
|
2
|
+
import { SapphireClient, preGenericsInitialization, preLogin, postLogin, Plugin, container } from '@sapphire/framework';
|
|
3
|
+
import { watch } from 'chokidar';
|
|
4
|
+
import { InternationalizationHandler } from './index.mjs';
|
|
5
|
+
|
|
6
|
+
var _I18nextPlugin = class _I18nextPlugin extends Plugin {
|
|
7
|
+
static [preGenericsInitialization](options) {
|
|
8
|
+
container.i18n = new InternationalizationHandler(options.i18n);
|
|
9
|
+
}
|
|
10
|
+
static async [preLogin]() {
|
|
11
|
+
await container.i18n.init();
|
|
12
|
+
}
|
|
13
|
+
static [postLogin]() {
|
|
14
|
+
if (this.options.i18n?.hmr?.enabled) {
|
|
15
|
+
container.logger.info("[i18next-Plugin]: HMR enabled. Watching for languages changes.");
|
|
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());
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
__name(_I18nextPlugin, "I18nextPlugin");
|
|
23
|
+
var I18nextPlugin = _I18nextPlugin;
|
|
24
|
+
SapphireClient.plugins.registerPostInitializationHook(I18nextPlugin[preGenericsInitialization], "I18next-PreGenericsInitialization");
|
|
25
|
+
SapphireClient.plugins.registerPreLoginHook(I18nextPlugin[preLogin], "I18next-PreLogin");
|
|
26
|
+
SapphireClient.plugins.registerPostLoginHook(I18nextPlugin[postLogin], "I18next-PostLogin");
|
|
27
|
+
|
|
28
|
+
export { I18nextPlugin };
|
|
29
|
+
//# sourceMappingURL=out.js.map
|
|
30
|
+
//# sourceMappingURL=register.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/register.ts"],"names":[],"mappings":";;;;;AAAA,SAAS,QAAQ,gBAAgB,WAAW,WAAW,2BAA2B,gBAAgB;AAClG,SAAS,aAAa;AAEtB,SAAS,mCAAmC;AAErC,IAAM,iBAAN,MAAM,uBAAsB,OAAO;AAAA,EACzC,QAAe,yBAAyB,EAAwB,SAA8B;AAC7F,cAAU,OAAO,IAAI,4BAA4B,QAAQ,IAAI;AAAA,EAC9D;AAAA,EAEA,cAAqB,QAAQ,IAAuC;AACnE,UAAM,UAAU,KAAK,KAAK;AAAA,EAC3B;AAAA,EAEA,QAAe,SAAS,IAA8B;AACrD,QAAI,KAAK,QAAQ,MAAM,KAAK,SAAS;AACpC,gBAAU,OAAO,KAAK,gEAAgE;AACtF,YAAM,MAAM,MAAM,UAAU,KAAK,oBAAoB,KAAK,QAAQ,KAAK,IAAI,OAAO;AAElF,iBAAW,SAAS,CAAC,UAAU,QAAQ;AAAG,YAAI,GAAG,OAAO,MAAM,UAAU,KAAK,gBAAgB,CAAC;AAAA,IAC/F;AAAA,EACD;AACD;AAjB0C;AAAnC,IAAM,gBAAN;AAmBP,eAAe,QAAQ,+BAA+B,cAAc,yBAAyB,GAAG,mCAAmC;AACnI,eAAe,QAAQ,qBAAqB,cAAc,QAAQ,GAAG,kBAAkB;AACvF,eAAe,QAAQ,sBAAsB,cAAc,SAAS,GAAG,mBAAmB","sourcesContent":["import { 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,45 +1,58 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sapphire/plugin-i18next",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.0-next.1f2cccc.0",
|
|
4
4
|
"description": "Plugin for @sapphire/framework to support i18next.",
|
|
5
5
|
"author": "@sapphire",
|
|
6
6
|
"license": "MIT",
|
|
7
|
-
"main": "dist/index.
|
|
8
|
-
"module": "dist/index.mjs",
|
|
9
|
-
"types": "dist/index.d.ts",
|
|
7
|
+
"main": "dist/cjs/index.cjs",
|
|
8
|
+
"module": "dist/esm/index.mjs",
|
|
9
|
+
"types": "dist/cjs/index.d.ts",
|
|
10
10
|
"exports": {
|
|
11
11
|
".": {
|
|
12
|
-
"
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
"import": {
|
|
13
|
+
"types": "./dist/esm/index.d.mts",
|
|
14
|
+
"default": "./dist/esm/index.mjs"
|
|
15
|
+
},
|
|
16
|
+
"require": {
|
|
17
|
+
"types": "./dist/cjs/index.d.ts",
|
|
18
|
+
"default": "./dist/cjs/index.cjs"
|
|
19
|
+
}
|
|
15
20
|
},
|
|
16
21
|
"./register": {
|
|
17
|
-
"
|
|
18
|
-
|
|
19
|
-
|
|
22
|
+
"import": {
|
|
23
|
+
"types": "./dist/esm/register.d.mts",
|
|
24
|
+
"default": "./dist/esm/register.mjs"
|
|
25
|
+
},
|
|
26
|
+
"require": {
|
|
27
|
+
"types": "./dist/cjs/register.d.ts",
|
|
28
|
+
"default": "./dist/cjs/register.cjs"
|
|
29
|
+
}
|
|
20
30
|
}
|
|
21
31
|
},
|
|
22
32
|
"sideEffects": [
|
|
23
|
-
"./dist/register.
|
|
24
|
-
"./dist/register.mjs"
|
|
33
|
+
"./dist/cjs/register.cjs",
|
|
34
|
+
"./dist/esm/register.mjs"
|
|
25
35
|
],
|
|
26
36
|
"homepage": "https://github.com/sapphiredev/plugins/tree/main/packages/i18next",
|
|
27
37
|
"scripts": {
|
|
28
38
|
"test": "vitest run",
|
|
29
39
|
"lint": "eslint src tests --ext ts --fix",
|
|
30
|
-
"build": "
|
|
31
|
-
"
|
|
32
|
-
"
|
|
40
|
+
"build": "tsup && yarn build:types",
|
|
41
|
+
"build:types": "concurrently \"yarn:build:types:*\"",
|
|
42
|
+
"build:types:cjs": "rollup-type-bundler -d dist/cjs",
|
|
43
|
+
"build:types:esm": "rollup-type-bundler -d dist/esm -t .mts",
|
|
44
|
+
"build:types:cleanup": "tsx ../../scripts/clean-register-imports.mts",
|
|
45
|
+
"typecheck": "tsc -b src",
|
|
33
46
|
"docs": "typedoc-json-parser",
|
|
34
47
|
"prepack": "yarn build",
|
|
35
48
|
"bump": "cliff-jumper",
|
|
36
49
|
"check-update": "cliff-jumper --dry-run"
|
|
37
50
|
},
|
|
38
51
|
"dependencies": {
|
|
39
|
-
"@sapphire/utilities": "^3.
|
|
52
|
+
"@sapphire/utilities": "^3.14.0",
|
|
40
53
|
"@skyra/i18next-backend": "^2.0.4",
|
|
41
54
|
"chokidar": "^3.5.3",
|
|
42
|
-
"i18next": "^23.7.
|
|
55
|
+
"i18next": "^23.7.7"
|
|
43
56
|
},
|
|
44
57
|
"repository": {
|
|
45
58
|
"type": "git",
|
|
@@ -47,8 +60,7 @@
|
|
|
47
60
|
"directory": "packages/i18next"
|
|
48
61
|
},
|
|
49
62
|
"files": [
|
|
50
|
-
"dist/"
|
|
51
|
-
"!dist/.tsbuildinfo"
|
|
63
|
+
"dist/"
|
|
52
64
|
],
|
|
53
65
|
"engines": {
|
|
54
66
|
"node": ">=v18",
|
|
@@ -74,9 +86,12 @@
|
|
|
74
86
|
},
|
|
75
87
|
"devDependencies": {
|
|
76
88
|
"@favware/cliff-jumper": "^2.2.3",
|
|
77
|
-
"
|
|
78
|
-
"
|
|
89
|
+
"@favware/rollup-type-bundler": "^3.2.1",
|
|
90
|
+
"concurrently": "^8.2.2",
|
|
91
|
+
"tsup": "^8.0.1",
|
|
92
|
+
"tsx": "^4.6.2",
|
|
93
|
+
"typedoc": "^0.25.4",
|
|
79
94
|
"typedoc-json-parser": "^9.0.1",
|
|
80
|
-
"typescript": "^5.
|
|
95
|
+
"typescript": "^5.3.2"
|
|
81
96
|
}
|
|
82
97
|
}
|
package/dist/index.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { InternationalizationHandler } from './lib/InternationalizationHandler';
|
|
2
|
-
import type { InternationalizationClientOptions } from './lib/types';
|
|
3
|
-
export { default as i18next, type TFunction, type TOptions } from 'i18next';
|
|
4
|
-
export * from './lib/InternationalizationHandler';
|
|
5
|
-
export * from './lib/functions';
|
|
6
|
-
export * from './lib/types';
|
|
7
|
-
declare module '@sapphire/pieces' {
|
|
8
|
-
interface Container {
|
|
9
|
-
i18n: InternationalizationHandler;
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
declare module 'discord.js' {
|
|
13
|
-
interface ClientOptions extends InternationalizationClientOptions {
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,mCAAmC,CAAC;AACrF,OAAO,KAAK,EAAE,iCAAiC,EAAE,MAAM,aAAa,CAAC;AAErE,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC5E,cAAc,mCAAmC,CAAC;AAClD,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC;AAE5B,OAAO,QAAQ,kBAAkB,CAAC;IACjC,UAAU,SAAS;QAClB,IAAI,EAAE,2BAA2B,CAAC;KAClC;CACD;AAED,OAAO,QAAQ,YAAY,CAAC;IAC3B,UAAiB,aAAc,SAAQ,iCAAiC;KAAG;CAC3E"}
|
package/dist/index.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
|
-
};
|
|
19
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.i18next = void 0;
|
|
21
|
-
var i18next_1 = require("i18next");
|
|
22
|
-
Object.defineProperty(exports, "i18next", { enumerable: true, get: function () { return __importDefault(i18next_1).default; } });
|
|
23
|
-
__exportStar(require("./lib/InternationalizationHandler"), exports);
|
|
24
|
-
__exportStar(require("./lib/functions"), exports);
|
|
25
|
-
__exportStar(require("./lib/types"), exports);
|
|
26
|
-
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAGA,mCAA4E;AAAnE,mHAAA,OAAO,OAAW;AAC3B,oEAAkD;AAClD,kDAAgC;AAChC,8CAA4B"}
|
package/dist/index.mjs
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import mod from "./index.js";
|
|
2
|
-
|
|
3
|
-
export default mod;
|
|
4
|
-
export const InternationalizationHandler = mod.InternationalizationHandler;
|
|
5
|
-
export const applyDescriptionLocalizedBuilder = mod.applyDescriptionLocalizedBuilder;
|
|
6
|
-
export const applyLocalizedBuilder = mod.applyLocalizedBuilder;
|
|
7
|
-
export const applyNameLocalizedBuilder = mod.applyNameLocalizedBuilder;
|
|
8
|
-
export const createLocalizedChoice = mod.createLocalizedChoice;
|
|
9
|
-
export const fetchLanguage = mod.fetchLanguage;
|
|
10
|
-
export const fetchT = mod.fetchT;
|
|
11
|
-
export const getLocalizedData = mod.getLocalizedData;
|
|
12
|
-
export const i18next = mod.i18next;
|
|
13
|
-
export const resolveKey = mod.resolveKey;
|
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { type Awaitable } from '@sapphire/utilities';
|
|
3
|
-
import { Backend } from '@skyra/i18next-backend';
|
|
4
|
-
import { AppendKeyPrefix, InterpolationMap, Namespace, ParseKeys, TFunctionReturn, TFunctionReturnOptionalDetails, type TFunction, type TOptions } from 'i18next';
|
|
5
|
-
import type { PathLike } from 'node:fs';
|
|
6
|
-
import type { $Dictionary, InternationalizationContext, InternationalizationOptions } from './types';
|
|
7
|
-
/**
|
|
8
|
-
* A generalized class for handling `i18next` JSON files and their discovery.
|
|
9
|
-
* @since 1.0.0
|
|
10
|
-
*/
|
|
11
|
-
export declare class InternationalizationHandler {
|
|
12
|
-
/**
|
|
13
|
-
* Describes whether {@link InternationalizationHandler.init} has been run and languages are loaded in {@link InternationalizationHandler.languages}.
|
|
14
|
-
* @since 1.0.0
|
|
15
|
-
*/
|
|
16
|
-
languagesLoaded: boolean;
|
|
17
|
-
/**
|
|
18
|
-
* A `Set` of initially loaded namespaces.
|
|
19
|
-
* @since 1.2.0
|
|
20
|
-
*/
|
|
21
|
-
namespaces: Set<string>;
|
|
22
|
-
/**
|
|
23
|
-
* A `Map` of `i18next` language functions keyed by their language code.
|
|
24
|
-
* @since 1.0.0
|
|
25
|
-
*/
|
|
26
|
-
readonly languages: Map<string, TFunction<"translation", undefined>>;
|
|
27
|
-
/**
|
|
28
|
-
* The options InternationalizationHandler was initialized with in the client.
|
|
29
|
-
* @since 1.0.0
|
|
30
|
-
*/
|
|
31
|
-
readonly options: InternationalizationOptions;
|
|
32
|
-
/**
|
|
33
|
-
* The director passed to `@skyra/i18next-backend`.
|
|
34
|
-
* Also used in {@link InternationalizationHandler.walkLanguageDirectory}.
|
|
35
|
-
* @since 1.2.0
|
|
36
|
-
*/
|
|
37
|
-
readonly languagesDirectory: string;
|
|
38
|
-
/**
|
|
39
|
-
* The backend options for `@skyra/i18next-backend` used by `i18next`.
|
|
40
|
-
* @since 1.0.0
|
|
41
|
-
*/
|
|
42
|
-
protected readonly backendOptions: Backend.Options;
|
|
43
|
-
/**
|
|
44
|
-
* @param options The options that `i18next`, `@skyra/i18next-backend`, and {@link InternationalizationHandler} should use.
|
|
45
|
-
* @since 1.0.0
|
|
46
|
-
* @constructor
|
|
47
|
-
*/
|
|
48
|
-
constructor(options?: InternationalizationOptions);
|
|
49
|
-
/**
|
|
50
|
-
* The method to be overridden by the developer.
|
|
51
|
-
*
|
|
52
|
-
* @note In the event that fetchLanguage is not defined or returns null / undefined, the defaulting from {@link fetchLanguage} will be used.
|
|
53
|
-
* @since 2.0.0
|
|
54
|
-
* @return A string for the desired language or null for no match.
|
|
55
|
-
* @see {@link fetchLanguage}
|
|
56
|
-
* @example
|
|
57
|
-
* ```typescript
|
|
58
|
-
* // Always use the same language (no per-guild configuration):
|
|
59
|
-
* container.i18n.fetchLanguage = () => 'en-US';
|
|
60
|
-
* ```
|
|
61
|
-
* @example
|
|
62
|
-
* ```typescript
|
|
63
|
-
* // Retrieving the language from an SQL database:
|
|
64
|
-
* container.i18n.fetchLanguage = async (context) => {
|
|
65
|
-
* const guild = await driver.getOne('SELECT language FROM public.guild WHERE id = $1', [context.guild.id]);
|
|
66
|
-
* return guild?.language ?? 'en-US';
|
|
67
|
-
* };
|
|
68
|
-
* ```
|
|
69
|
-
* @example
|
|
70
|
-
* ```typescript
|
|
71
|
-
* // Retrieving the language from an ORM:
|
|
72
|
-
* container.i18n.fetchLanguage = async (context) => {
|
|
73
|
-
* const guild = await driver.getRepository(GuildEntity).findOne({ id: context.guild.id });
|
|
74
|
-
* return guild?.language ?? 'en-US';
|
|
75
|
-
* };
|
|
76
|
-
* ```
|
|
77
|
-
* @example
|
|
78
|
-
* ```typescript
|
|
79
|
-
* // Retrieving the language on a per channel basis, e.g. per user or guild channel (ORM example but same principles apply):
|
|
80
|
-
* container.i18n.fetchLanguage = async (context) => {
|
|
81
|
-
* const channel = await driver.getRepository(ChannelEntity).findOne({ id: context.channel.id });
|
|
82
|
-
* return channel?.language ?? 'en-US';
|
|
83
|
-
* };
|
|
84
|
-
* ```
|
|
85
|
-
*/
|
|
86
|
-
fetchLanguage: (context: InternationalizationContext) => Awaitable<string | null>;
|
|
87
|
-
/**
|
|
88
|
-
* Initializes the handler by loading in the namespaces, passing the data to i18next, and filling in the {@link InternationalizationHandler#languages}.
|
|
89
|
-
* @since 1.0.0
|
|
90
|
-
*/
|
|
91
|
-
init(): Promise<void>;
|
|
92
|
-
/**
|
|
93
|
-
* Retrieve a raw TFunction from the passed locale.
|
|
94
|
-
* @param locale The language to be used.
|
|
95
|
-
* @since 1.0.0
|
|
96
|
-
*/
|
|
97
|
-
getT(locale: string): TFunction<"translation", undefined>;
|
|
98
|
-
/**
|
|
99
|
-
* Localizes a content given one or more keys and i18next options.
|
|
100
|
-
* @since 2.0.0
|
|
101
|
-
* @param locale The language to be used.
|
|
102
|
-
* @param key The key or keys to retrieve the content from.
|
|
103
|
-
* @param options The interpolation options.
|
|
104
|
-
* @see {@link https://www.i18next.com/overview/api#t}
|
|
105
|
-
* @returns The localized content.
|
|
106
|
-
*/
|
|
107
|
-
format<const Key extends ParseKeys<Ns, TOpt, undefined>, const TOpt extends TOptions, Ns extends Namespace, Ret extends TFunctionReturn<Ns, AppendKeyPrefix<Key, undefined>, TOpt>, const ActualOptions extends TOpt & InterpolationMap<Ret> = TOpt & InterpolationMap<Ret>>(locale: string, ...[key, defaultValueOrOptions, optionsOrUndefined]: [key: Key | Key[], options?: ActualOptions] | [key: string | string[], options: TOpt & $Dictionary & {
|
|
108
|
-
defaultValue: string;
|
|
109
|
-
}] | [key: string | string[], defaultValue: string | undefined, options?: TOpt & $Dictionary]): TFunctionReturnOptionalDetails<Ret, TOpt>;
|
|
110
|
-
/**
|
|
111
|
-
* @param directory The directory that should be walked.
|
|
112
|
-
* @since 3.0.0
|
|
113
|
-
*/
|
|
114
|
-
walkRootDirectory(directory: PathLike): Promise<{
|
|
115
|
-
namespaces: string[];
|
|
116
|
-
languages: string[];
|
|
117
|
-
}>;
|
|
118
|
-
reloadResources(): Promise<void>;
|
|
119
|
-
/**
|
|
120
|
-
* @description Skips any files that don't end with `.json`.
|
|
121
|
-
* @param directory The directory that should be walked.
|
|
122
|
-
* @param ns The current namespace.
|
|
123
|
-
* @since 3.0.0
|
|
124
|
-
*/
|
|
125
|
-
private walkLocaleDirectory;
|
|
126
|
-
}
|
|
127
|
-
//# sourceMappingURL=InternationalizationHandler.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"InternationalizationHandler.d.ts","sourceRoot":"","sources":["../../src/lib/InternationalizationHandler.ts"],"names":[],"mappings":";AAEA,OAAO,EAAc,KAAK,SAAS,EAAE,MAAM,qBAAqB,CAAC;AACjE,OAAO,EAAE,OAAO,EAAuB,MAAM,wBAAwB,CAAC;AACtE,OAAgB,EACf,eAAe,EACf,gBAAgB,EAChB,SAAS,EACT,SAAS,EACT,eAAe,EACf,8BAA8B,EAC9B,KAAK,SAAS,EACd,KAAK,QAAQ,EACb,MAAM,SAAS,CAAC;AACjB,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAIxC,OAAO,KAAK,EAAE,WAAW,EAAE,2BAA2B,EAAE,2BAA2B,EAAE,MAAM,SAAS,CAAC;AAErG;;;GAGG;AACH,qBAAa,2BAA2B;IACvC;;;OAGG;IACI,eAAe,UAAS;IAE/B;;;OAGG;IACI,UAAU,cAAqB;IAEtC;;;OAGG;IACH,SAAgB,SAAS,mDAAgC;IAEzD;;;OAGG;IACH,SAAgB,OAAO,EAAE,2BAA2B,CAAC;IAErD;;;;OAIG;IACH,SAAgB,kBAAkB,EAAE,MAAM,CAAC;IAE3C;;;OAGG;IACH,SAAS,CAAC,QAAQ,CAAC,cAAc,EAAE,OAAO,CAAC,OAAO,CAAC;IAEnD;;;;OAIG;gBACgB,OAAO,CAAC,EAAE,2BAA2B;IAyBxD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAoCG;IACI,aAAa,EAAE,CAAC,OAAO,EAAE,2BAA2B,KAAK,SAAS,CAAC,MAAM,GAAG,IAAI,CAAC,CAAc;IAEtG;;;OAGG;IACU,IAAI;IAoCjB;;;;OAIG;IACI,IAAI,CAAC,MAAM,EAAE,MAAM;IAQ1B;;;;;;;;OAQG;IACI,MAAM,CACZ,KAAK,CAAC,GAAG,SAAS,SAAS,CAAC,EAAE,EAAE,IAAI,EAAE,SAAS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