@wolfstar/plugin-i18next 2.1.2 → 2.2.0-next-20261004192124

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 CHANGED
@@ -31,6 +31,38 @@ pnpm add @wolfstar/http-framework @wolfstar/plugin-i18next
31
31
 
32
32
  ## Usage
33
33
 
34
+ ### Stars module
35
+
36
+ On framework 6.1 and later, list the module in `modules` in `stars.config` (needs the optional
37
+ `@wolfstar/kit` peer):
38
+
39
+ ```ts
40
+ // stars.config.ts
41
+ export default defineConfig({
42
+ modules: [["@wolfstar/plugin-i18next/module", { defaultLanguageDirectory: "./languages" }]],
43
+ });
44
+ ```
45
+
46
+ The options are written into the built entry, so they must be JSON-serialisable. `fetchLanguage` and
47
+ the functions in `hmr.options` are not: set `fetchLanguage` through `ClientOptions.i18n`, which is
48
+ merged (shallowly) over the module options. Because the merge is shallow, `hmr: { options }` set
49
+ through `ClientOptions.i18n` replaces the module's whole `hmr` object: when you need functions in it,
50
+ set the entire `hmr` object, including `enabled: true`, through `ClientOptions.i18n`.
51
+
52
+ Never combine the module (or the `@wolfstar/plugin-i18next/plugin` factory below) with
53
+ `import "@wolfstar/plugin-i18next/register"`: both paths install the same hooks, so combining them
54
+ installs them twice.
55
+
56
+ Without Stars, pass the `definePlugin` factory to `plugins` instead:
57
+
58
+ ```ts
59
+ import i18nPlugin from "@wolfstar/plugin-i18next/plugin";
60
+
61
+ const client = new Client({ plugins: [i18nPlugin({ defaultName: "en-US" })] });
62
+ ```
63
+
64
+ ### `register` entrypoint (framework v3/v5/v6)
65
+
34
66
  Import the register entrypoint **before** creating the client:
35
67
 
36
68
  ```typescript
@@ -240,6 +272,21 @@ import { I18nextPlugin } from "@wolfstar/plugin-i18next/register";
240
272
  await I18nextPlugin.watcher?.close();
241
273
  ```
242
274
 
275
+ The `./plugin` factory exposes the same watcher as `watcher` on the plugin it returns (`null` until
276
+ `postListen` has run, and when HMR is not enabled):
277
+
278
+ ```typescript
279
+ import i18nPlugin from "@wolfstar/plugin-i18next/plugin";
280
+
281
+ const plugin = i18nPlugin({ hmr: { enabled: true } });
282
+ const client = new Client({ plugins: [plugin] });
283
+
284
+ await plugin.watcher?.close();
285
+ ```
286
+
287
+ A module activated through `stars.config` is built by the CLI, so there is no plugin instance to read
288
+ the watcher from.
289
+
243
290
  ## Options
244
291
 
245
292
  | Option | Type | Description |
@@ -0,0 +1,50 @@
1
+ import { InternationalizationHandler } from "./index.js";
2
+ import { container } from "@wolfstar/http-framework";
3
+ import { watch } from "chokidar";
4
+
5
+ //#region src/hooks.ts
6
+ /**
7
+ * The chokidar events that make the languages directory's contents change.
8
+ */
9
+ const HmrEvents = [
10
+ "add",
11
+ "addDir",
12
+ "change",
13
+ "unlink",
14
+ "unlinkDir"
15
+ ];
16
+ /**
17
+ * Creates the {@link InternationalizationHandler} and assigns it to `container.i18n`. Shared by the `./register`
18
+ * class plugin and the `./plugin` `definePlugin` factory.
19
+ *
20
+ * @param options The client options, read for `i18n`.
21
+ */
22
+ function installI18n(options) {
23
+ container.i18n = new InternationalizationHandler(options.i18n);
24
+ }
25
+ /**
26
+ * Loads the languages, so command builders can be localized when the stores load.
27
+ */
28
+ async function initI18n() {
29
+ await container.i18n.init();
30
+ }
31
+ /**
32
+ * Watches the languages directory and reloads the resources when it changes, if `i18n.hmr.enabled` is set.
33
+ *
34
+ * @param options The client options, read for `i18n.hmr`.
35
+ * @returns The chokidar watcher, or `null` when HMR is not enabled.
36
+ */
37
+ function watchLanguages(options) {
38
+ if (!options.i18n?.hmr?.enabled) return null;
39
+ console.info("[plugin-i18next] HMR enabled. Watching for language changes.");
40
+ const watcher = watch(container.i18n.languagesDirectory, {
41
+ ignoreInitial: true,
42
+ ...options.i18n.hmr.options
43
+ });
44
+ for (const event of HmrEvents) watcher.on(event, () => void container.i18n.reloadResources());
45
+ return watcher;
46
+ }
47
+
48
+ //#endregion
49
+ export { installI18n as n, watchLanguages as r, initI18n as t };
50
+ //# sourceMappingURL=hooks-Bwy47aXr.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hooks-Bwy47aXr.js","names":[],"sources":["../../src/hooks.ts"],"sourcesContent":["import { container, type ClientOptions } from \"@wolfstar/http-framework\";\nimport { watch, type FSWatcher } from \"chokidar\";\nimport { InternationalizationHandler } from \"./lib/InternationalizationHandler\";\n\n/**\n * The chokidar events that make the languages directory's contents change.\n */\nconst HmrEvents = [\"add\", \"addDir\", \"change\", \"unlink\", \"unlinkDir\"] as const;\n\n/**\n * Creates the {@link InternationalizationHandler} and assigns it to `container.i18n`. Shared by the `./register`\n * class plugin and the `./plugin` `definePlugin` factory.\n *\n * @param options The client options, read for `i18n`.\n */\nexport function installI18n(options: ClientOptions): void {\n container.i18n = new InternationalizationHandler(options.i18n);\n}\n\n/**\n * Loads the languages, so command builders can be localized when the stores load.\n */\nexport async function initI18n(): Promise<void> {\n await container.i18n.init();\n}\n\n/**\n * Watches the languages directory and reloads the resources when it changes, if `i18n.hmr.enabled` is set.\n *\n * @param options The client options, read for `i18n.hmr`.\n * @returns The chokidar watcher, or `null` when HMR is not enabled.\n */\nexport function watchLanguages(options: ClientOptions): FSWatcher | null {\n if (!options.i18n?.hmr?.enabled) return null;\n\n console.info(\"[plugin-i18next] HMR enabled. Watching for language changes.\");\n\n // `ignoreInitial` defaults to `true` here: chokidar otherwise replays an `add` for every file\n // already on disk, which would trigger a reload per translation file on startup.\n const watcher = watch(container.i18n.languagesDirectory, {\n ignoreInitial: true,\n ...options.i18n.hmr.options,\n });\n\n // Adding a locale directory or a namespace file emits `addDir` / `add`, not `change`, so all of\n // them have to be watched for new languages and namespaces to be picked up.\n for (const event of HmrEvents) {\n watcher.on(event, () => void container.i18n.reloadResources());\n }\n\n return watcher;\n}\n"],"mappings":";;;;;;;;AAOA,MAAM,YAAY;CAAC;CAAO;CAAU;CAAU;CAAU;AAAW;;;;;;;AAQnE,SAAgB,YAAY,SAA8B;CACxD,UAAU,OAAO,IAAI,4BAA4B,QAAQ,IAAI;AAC/D;;;;AAKA,eAAsB,WAA0B;CAC9C,MAAM,UAAU,KAAK,KAAK;AAC5B;;;;;;;AAQA,SAAgB,eAAe,SAA0C;CACvE,IAAI,CAAC,QAAQ,MAAM,KAAK,SAAS,OAAO;CAExC,QAAQ,KAAK,8DAA8D;CAI3E,MAAM,UAAU,MAAM,UAAU,KAAK,oBAAoB;EACvD,eAAe;EACf,GAAG,QAAQ,KAAK,IAAI;CACtB,CAAC;CAID,KAAK,MAAM,SAAS,WAClB,QAAQ,GAAG,aAAa,KAAK,UAAU,KAAK,gBAAgB,CAAC;CAG/D,OAAO;AACT"}
@@ -1,272 +1,9 @@
1
- import i18next, { AppendKeyPrefix, DefaultNamespace, FlatNamespace, InitOptions, InitOptions as InitOptions$1, InterpolationMap, Namespace, ParseKeys, TFunction, TFunction as TFunction$1, TFunctionReturn, TFunctionReturnOptionalDetails, TOptions, TOptions as TOptions$1, TOptionsBase, TOptionsBase as TOptionsBase$1, TypeOptions } from "i18next";
2
- import { APIApplicationCommandOptionChoice, APIInteraction, APIPingInteraction, APIUser, ChannelType, LocaleString, LocalizationMap } from "discord-api-types/v10";
1
+ import { C as Target, S as MessageTarget, _ as InternationalizationContext, a as BuilderWithDescription, b as LocaleSeparator, c as ChannelTarget, d as HMROptions, f as I18nextFormatter, g as InternationalizationClientOptions, h as Interaction, i as AnyNamespace, l as DynamicOptions, m as I18nextNamedFormatter, n as $NoInfer, o as BuilderWithName, p as I18nextNamedCachedFormatter, r as $SpecialObject, s as BuilderWithNameAndDescription, t as $Dictionary, u as GuildTarget, v as InternationalizationOptions, x as LocalizedData, y as LocalePrefixKey } from "./types-BhhqHOJk.js";
2
+ import i18next, { AppendKeyPrefix, DefaultNamespace, InitOptions, InterpolationMap, Namespace, ParseKeys, TFunction, TFunction as TFunction$1, TFunctionReturn, TFunctionReturnOptionalDetails, TOptions, TOptions as TOptions$1, TOptionsBase, TOptionsBase as TOptionsBase$1 } from "i18next";
3
+ import { APIApplicationCommandOptionChoice, LocaleString, LocalizationMap } from "discord-api-types/v10";
3
4
  import { Awaitable, NonNullObject } from "@sapphire/utilities";
4
5
  import { Backend } from "@wolfstar/i18next-backend";
5
- import { ChokidarOptions } from "chokidar";
6
6
  import { PathLike } from "node:fs";
7
- //#region src/lib/types.d.ts
8
- /**
9
- * This is a re-exported type from i18next.
10
- *
11
- * We could use the `NoInfer` TypeScript built-in utility, however this package still supports
12
- * TypeScript < 5.4.
13
- *
14
- * @see https://github.com/millsp/ts-toolbelt/blob/master/sources/Function/NoInfer.ts
15
- */
16
- type $NoInfer<A> = [A][A extends any ? 0 : never];
17
- /**
18
- * This is a re-exported type from i18next. It is essentially an object of key-value pairs, where
19
- * the key is a string and the value is any.
20
- */
21
- interface $Dictionary {
22
- [key: string]: any;
23
- }
24
- /**
25
- * This is a re-exported type from i18next. It is the returned type from the translation helpers
26
- * when `returnObjects` is `true` in the options.
27
- */
28
- type $SpecialObject = $Dictionary | Array<string | $Dictionary>;
29
- /**
30
- * The namespace separator i18next is configured with, `':'` unless `CustomTypeOptions` overrides it.
31
- */
32
- type LocaleSeparator = TypeOptions["nsSeparator"];
33
- /**
34
- * A `<namespace><separator><key>` shaped key, used as the root key overload of
35
- * {@link applyLocalizedBuilder}.
36
- */
37
- type LocalePrefixKey = `${string}${LocaleSeparator}${string}`;
38
- /**
39
- * Every namespace known through the `CustomTypeOptions.resources` augmentation generated by
40
- * [`@wolfstar/i18next-type-generator`](https://www.npmjs.com/package/@wolfstar/i18next-type-generator).
41
- *
42
- * @remarks
43
- * Used as the default `Ns` generic of every helper that takes a fully-qualified
44
- * `<namespace><separator><key>` key, since i18next only parses those out of `ParseKeys` when `Ns`
45
- * is the array of every namespace the key could belong to — a single namespace (i18next's own
46
- * `DefaultNamespace`) only parses keys of that one namespace, unprefixed.
47
- */
48
- type AnyNamespace = readonly FlatNamespace[];
49
- /**
50
- * The subset of an interaction payload the localization helpers need in order to resolve a language.
51
- *
52
- * @remarks
53
- * `@wolfstar/http-framework` receives raw Discord interaction payloads over HTTP, so the helpers
54
- * operate on `discord-api-types` structures rather than on `discord.js` class instances.
55
- */
56
- type Interaction = Pick<Exclude<APIInteraction, APIPingInteraction>, "locale" | "guild_locale" | "guild_id"> & Partial<Pick<Exclude<APIInteraction, APIPingInteraction>, "channel_id" | "user" | "member">>;
57
- /**
58
- * The subset of a guild payload the localization helpers need.
59
- *
60
- * @remarks
61
- * `APIGuild` satisfies it, as does any partial guild that carries an id. Only a full guild payload
62
- * carries `preferred_locale`; without it the guild's id is still handed to
63
- * {@link InternationalizationHandler.fetchLanguage}, so a custom hook can resolve the language.
64
- */
65
- interface GuildTarget {
66
- id: string;
67
- /**
68
- * The guild's preferred locale. Typed as `string` rather than `LocaleString` because
69
- * `APIGuild` types it as the `Locale` enum; it is validated at runtime.
70
- */
71
- preferred_locale?: string;
72
- }
73
- /**
74
- * The subset of a channel payload the localization helpers need. Every `APIChannel` member
75
- * satisfies it.
76
- *
77
- * @remarks
78
- * A channel payload carries no locale of its own, so the language is resolved from
79
- * {@link InternationalizationHandler.fetchLanguage} and then from the configured default.
80
- */
81
- interface ChannelTarget {
82
- id: string;
83
- type: ChannelType;
84
- guild_id?: string;
85
- }
86
- /**
87
- * The subset of a message payload the localization helpers need. `APIMessage` satisfies it, and
88
- * gateway message payloads additionally carry `guild_id`.
89
- *
90
- * @remarks
91
- * Like {@link ChannelTarget}, a message carries no locale of its own.
92
- */
93
- interface MessageTarget {
94
- id: string;
95
- channel_id: string;
96
- guild_id?: string;
97
- author?: Pick<APIUser, "id">;
98
- }
99
- /**
100
- * Any value the localization helpers accept as the source of a language.
101
- *
102
- * @remarks
103
- * The four members are told apart structurally, in this order: an {@link Interaction} has `locale`,
104
- * a {@link MessageTarget} has `channel_id`, a {@link ChannelTarget} has `type`, and anything else is
105
- * a {@link GuildTarget}.
106
- */
107
- type Target = Interaction | MessageTarget | ChannelTarget | GuildTarget;
108
- /**
109
- * Configure whether to use Hot-Module-Replacement (HMR) for your i18next resources using these
110
- * options. The minimum config to enable HMR is to set `enabled` to true. Any other properties are
111
- * optional.
112
- */
113
- interface HMROptions {
114
- /**
115
- * HMR status for the i18next plugin.
116
- * @default false
117
- */
118
- enabled: boolean;
119
- /**
120
- * Languages that will be reloaded when updating the languages directory.
121
- *
122
- * @remarks
123
- * Pinning both this and {@link HMROptions.namespaces} skips the directory walk, so languages and
124
- * namespaces added while the process is running are not registered on i18next.
125
- * @default All languages that are automatically resolved from your folder setup
126
- */
127
- languages?: string | string[];
128
- /**
129
- * Namespaces that will be reloaded when updating the languages directory.
130
- *
131
- * @remarks
132
- * Pinning both this and {@link HMROptions.languages} skips the directory walk, so languages and
133
- * namespaces added while the process is running are not registered on i18next.
134
- * @default All namespaces that are automatically resolved from your languages folder setup
135
- */
136
- namespaces?: string | string[];
137
- /**
138
- * The options passed to `chokidar`'s `watch`.
139
- *
140
- * @remarks
141
- * `ignoreInitial` defaults to `true`, since chokidar would otherwise replay an `add` event for
142
- * every translation file already on disk and trigger a reload for each of them on startup.
143
- */
144
- options?: ChokidarOptions;
145
- }
146
- /**
147
- * Used to dynamically add options based on the languages found in {@link InternationalizationHandler.init}.
148
- */
149
- type DynamicOptions<T extends InitOptions$1> = (namespaces: string[], languages: string[]) => T;
150
- /**
151
- * The options used in {@link InternationalizationHandler}.
152
- */
153
- interface InternationalizationOptions {
154
- /**
155
- * Used as the default 2nd to last fallback locale if no other is found. It's only followed by
156
- * `'en-US'`.
157
- */
158
- defaultName?: string;
159
- /**
160
- * The options passed to `backend` in `i18next.init`.
161
- */
162
- backend?: Backend.Options;
163
- /**
164
- * The options passed to `i18next.init`.
165
- */
166
- i18next?: InitOptions$1 | DynamicOptions<InitOptions$1>;
167
- /**
168
- * The directory in which `@wolfstar/i18next-backend` should search for files.
169
- * @default `rootDirectory/languages`
170
- */
171
- defaultLanguageDirectory?: string;
172
- /**
173
- * The default value to be used if a specific language key isn't found. Defaults to
174
- * `'default:default'`.
175
- */
176
- defaultMissingKey?: string;
177
- /**
178
- * The default namespace that is prefixed to all keys that don't specify it. Defaults to
179
- * `'default'`.
180
- */
181
- defaultNS?: string;
182
- /**
183
- * Array of formatters to add to i18next.
184
- * @default []
185
- */
186
- formatters?: I18nextFormatter[];
187
- /**
188
- * Reload languages and namespaces when updating the languages directory.
189
- */
190
- hmr?: HMROptions;
191
- /**
192
- * A function that is to be used to retrieve the language for the current context.
193
- *
194
- * If this is not set, then the language will always be resolved from the interaction's locales.
195
- *
196
- * This will be inserted for {@link InternationalizationHandler.fetchLanguage}.
197
- * @default () => null
198
- */
199
- fetchLanguage?: (context: InternationalizationContext) => Awaitable<string | null>;
200
- }
201
- /**
202
- * Context for {@link InternationalizationHandler.fetchLanguage} functions. This context enables
203
- * implementation of per-guild, per-channel, and per-user localization.
204
- */
205
- interface InternationalizationContext {
206
- /** The ID of the guild the interaction was sent from, or `null` when sent from a DM. */
207
- guildId: string | null;
208
- /** The ID of the channel the interaction was sent from, or `null` when it was not provided. */
209
- channelId: string | null;
210
- /** The ID of the user that sent the interaction, or `null` when it was not provided. */
211
- userId: string | null;
212
- /** The locale the guild the interaction was sent from is configured with. */
213
- interactionGuildLocale?: LocaleString;
214
- /** The locale the user that sent the interaction is configured with. */
215
- interactionLocale?: LocaleString;
216
- /**
217
- * The preferred locale of the guild the target belongs to.
218
- *
219
- * @remarks
220
- * Filled in from `guild_locale` for an {@link Interaction} and from `preferred_locale` for a
221
- * {@link GuildTarget}; a {@link ChannelTarget} and a {@link MessageTarget} carry no locale, so it
222
- * is left undefined for them.
223
- */
224
- preferredLocale?: string;
225
- }
226
- interface InternationalizationClientOptions {
227
- i18n?: InternationalizationOptions;
228
- }
229
- /**
230
- * Represents a formatter that is added to i18next with `i18next.services.formatter.add` or
231
- * `i18next.services.formatter.addCached`, depending on the `cached` property.
232
- *
233
- * @see {@link https://www.i18next.com/translation-function/formatting#adding-custom-format-function}
234
- */
235
- type I18nextFormatter = I18nextNamedFormatter | I18nextNamedCachedFormatter;
236
- /**
237
- * Represents a formatter that is added to i18next with `i18next.services.formatter.add`.
238
- *
239
- * @see {@link https://www.i18next.com/translation-function/formatting#adding-custom-format-function}
240
- */
241
- interface I18nextNamedFormatter {
242
- cached?: false;
243
- name: string;
244
- format(value: any, lng: string | undefined, options: any): string;
245
- }
246
- /**
247
- * Represents a cached formatter that is added to i18next with `i18next.services.formatter.addCached`.
248
- *
249
- * @see {@link https://www.i18next.com/translation-function/formatting#adding-custom-format-function}
250
- */
251
- interface I18nextNamedCachedFormatter {
252
- cached: true;
253
- name: string;
254
- format(lng: string | undefined, options: any): (value: any) => string;
255
- }
256
- interface LocalizedData {
257
- value: string;
258
- localizations: LocalizationMap;
259
- }
260
- interface BuilderWithName {
261
- setName(name: string): this;
262
- setNameLocalizations(localizedNames: LocalizationMap | null): this;
263
- }
264
- interface BuilderWithDescription {
265
- setDescription(description: string): this;
266
- setDescriptionLocalizations(localizedDescriptions: LocalizationMap | null): this;
267
- }
268
- type BuilderWithNameAndDescription = BuilderWithName & BuilderWithDescription;
269
- //#endregion
270
7
  //#region src/lib/InternationalizationHandler.d.ts
271
8
  /**
272
9
  * A generalized class for handling `i18next` JSON files and their discovery.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../../src/lib/types.ts","../../src/lib/InternationalizationHandler.ts","../../src/lib/compat.ts","../../src/lib/functions.ts","../../src/index.ts"],"mappings":";;;;;;;;;;;;;;;KAqBY,SAAS,MAAM,GAAG;;;;;UAMb;GACd;;;;;;KAOS,iBAAiB,cAAc,eAAe;;;;KAK9C,kBAAkB;;;;;KAMlB,8BAA8B;;;;;;;;;;;KAY9B,wBAAwB;;;;;;;;KASxB,cAAc,KACxB,QAAQ,gBAAgB,+DAGxB,QAAQ,KAAK,QAAQ,gBAAgB;;;;;;;;;UAUtB;EACf;;;;;EAKA;;;;;;;;;;UAWe;EACf;EACA,MAAM;EACN;;;;;;;;;UAUe;EACf;EACA;EACA;EACA,SAAS,KAAK;;;;;;;;;;KAWJ,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kC,6CAC/C,kCAAkC;;;;;;wBAerB,2BACd,UAAU,qBACJ,aAAa,aAAW,YAC9B,WAAW,YAAY,cACvB,qBACA,KAAK,UAAU,IAAI,MAAM,UAAU,QAAQ,IAAI,2BAA2B,OAAO;yBASlE;OACH,OAAO,KAAK;IACtB;IACA,oBAAoB;;;;;;;;;;;;;;;YCpnBZ,UAAU,WAAW,YAAY,kBAAkB;;;;IAI3D;;;;;IAMA;;;;IAKA,KAAK;;;;IAKL,YAAY;;;;YAKJ;;;;IAIR,MAAM;;;;YAKE;;;;;IAKR,OAAO"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../../src/lib/InternationalizationHandler.ts","../../src/lib/compat.ts","../../src/lib/functions.ts","../../src/index.ts"],"mappings":";;;;;;;;;;qBA8Ba;;;;;EAKJ;;;;EAKA,YAAU;;;;WAKD,WAAS,YAAA;;;;WAKT,SAAS;;;;;WAMT;;;;qBAKG,gBAAgB,QAAQ;;;;UAKnC;;;;;EAMR,YAAmB,UAAU;;;;;;;;;;;;;;;;;;;;;;;EA0CtB,gBAAgB,SAAS,gCAAgC;;;;;EAOnD,QAAI;;;;;;;;;;;EAiDV,WAAW,WAAW,YAAY,kBACvC,gBACA,YAAY,KACX,YAAU;;;;;;;;;EAyBN,aACC,YAAY,UAAU,IAAI,wBAC1B,aAAa,aAAW,YAC9B,WAAW,YAAY,cACvB,YAAY,gBAAgB,IAAI,gBAAgB,iBAAiB,QAAQ,gBACvE,IACA,gBAAgB,iBAChB,aAEI,sBAAsB,OAAO,iBAAiB,OAAO,OAAO,iBAAiB,MAEnF,gBACA,KAAK,MAAM,OACX,UAAU,gBACT,+BAA+B,KAAK;;;;;;;;;;EAWhC,aACC,YAAY,UAAU,IAAI,wBAC1B,aAAa,aAAW,YAC9B,WAAW,YAAY,cACvB,YAAY,gBAAgB,IAAI,gBAAgB,iBAAiB,QAAQ,gBACvE,IACA,gBAAgB,iBAChB,OAGF,gBACA,wBACA,SAAS,OAAO;IAAgB;MA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;YCpnBZ,UAAU,WAAW,YAAY,kBAAkB;;;;IAI3D;;;;;IAMA;;;;IAKA,KAAK;;;;IAKL,YAAY;;;;YAKJ;;;;IAIR,MAAM;;;;YAKE;;;;;IAKR,OAAO"}
@@ -0,0 +1,22 @@
1
+ import { v as InternationalizationOptions } from "./types-BhhqHOJk.js";
2
+ //#region src/module.d.ts
3
+ /**
4
+ * The Stars module: listing `@wolfstar/plugin-i18next/module` in `modules` in `stars.config` registers the i18next
5
+ * plugin with the options written there.
6
+ *
7
+ * @remarks
8
+ * The options are written into the built entry, so they have to be JSON-serialisable. `fetchLanguage` and the
9
+ * `hmr.options` functions are not: set `fetchLanguage` through `ClientOptions.i18n`.
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * // stars.config.ts
14
+ * export default defineConfig({
15
+ * modules: [['@wolfstar/plugin-i18next/module', { defaultLanguageDirectory: './languages' }]],
16
+ * });
17
+ * ```
18
+ */
19
+ declare const _default: import("@wolfstar/kit").StarsModule<InternationalizationOptions>;
20
+ //#endregion
21
+ export { _default as default };
22
+ //# sourceMappingURL=module.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module.d.ts","names":[],"sources":["../../src/module.ts"],"mappings":""}
@@ -0,0 +1,35 @@
1
+ import { defineModule } from "@wolfstar/kit";
2
+
3
+ //#region src/module.ts
4
+ /**
5
+ * The Stars module: listing `@wolfstar/plugin-i18next/module` in `modules` in `stars.config` registers the i18next
6
+ * plugin with the options written there.
7
+ *
8
+ * @remarks
9
+ * The options are written into the built entry, so they have to be JSON-serialisable. `fetchLanguage` and the
10
+ * `hmr.options` functions are not: set `fetchLanguage` through `ClientOptions.i18n`.
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * // stars.config.ts
15
+ * export default defineConfig({
16
+ * modules: [['@wolfstar/plugin-i18next/module', { defaultLanguageDirectory: './languages' }]],
17
+ * });
18
+ * ```
19
+ */
20
+ var module_default = defineModule({
21
+ meta: {
22
+ name: "@wolfstar/plugin-i18next",
23
+ compatibility: { framework: ">=6.1.0" }
24
+ },
25
+ setup(options, ctx) {
26
+ ctx.addPlugin({
27
+ from: "@wolfstar/plugin-i18next/plugin",
28
+ options
29
+ });
30
+ }
31
+ });
32
+
33
+ //#endregion
34
+ export { module_default as default };
35
+ //# sourceMappingURL=module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module.js","names":[],"sources":["../../src/module.ts"],"sourcesContent":["import { defineModule } from \"@wolfstar/kit\";\nimport type { InternationalizationOptions } from \"./lib/types\";\n\n/**\n * The Stars module: listing `@wolfstar/plugin-i18next/module` in `modules` in `stars.config` registers the i18next\n * plugin with the options written there.\n *\n * @remarks\n * The options are written into the built entry, so they have to be JSON-serialisable. `fetchLanguage` and the\n * `hmr.options` functions are not: set `fetchLanguage` through `ClientOptions.i18n`.\n *\n * @example\n * ```ts\n * // stars.config.ts\n * export default defineConfig({\n * modules: [['@wolfstar/plugin-i18next/module', { defaultLanguageDirectory: './languages' }]],\n * });\n * ```\n */\nexport default defineModule<InternationalizationOptions>({\n meta: {\n name: \"@wolfstar/plugin-i18next\",\n compatibility: { framework: \">=6.1.0\" },\n },\n setup(options, ctx) {\n ctx.addPlugin({ from: \"@wolfstar/plugin-i18next/plugin\", options });\n },\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAmBA,qBAAe,aAA0C;CACvD,MAAM;EACJ,MAAM;EACN,eAAe,EAAE,WAAW,UAAU;CACxC;CACA,MAAM,SAAS,KAAK;EAClB,IAAI,UAAU;GAAE,MAAM;GAAmC;EAAQ,CAAC;CACpE;AACF,CAAC"}
@@ -0,0 +1,31 @@
1
+ import { v as InternationalizationOptions } from "./types-BhhqHOJk.js";
2
+ import "./index.js";
3
+ import { ClientOptions } from "@wolfstar/http-framework";
4
+ import { FSWatcher } from "chokidar";
5
+ //#region src/plugin.d.ts
6
+ /**
7
+ * The i18next plugin: installs the `InternationalizationHandler` on `container.i18n`, loads the languages before the
8
+ * stores, and watches the languages directory when HMR is enabled.
9
+ *
10
+ * The plugin exposes the chokidar watcher started by `postListen` as `watcher` (`null` until then, and when HMR is not
11
+ * enabled), so it can be closed on shutdown, like `I18nextPlugin.watcher` of `./register`.
12
+ *
13
+ * @param pluginOptions The handler options. `ClientOptions.i18n` is merged over them.
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * import i18nPlugin from '@wolfstar/plugin-i18next/plugin';
18
+ *
19
+ * const client = new Client({ plugins: [i18nPlugin({ defaultName: 'en-US' })] });
20
+ * ```
21
+ */
22
+ declare const _default: (pluginOptions?: InternationalizationOptions | undefined) => {
23
+ name: string;
24
+ readonly watcher: FSWatcher | null;
25
+ preGenericsInitialization(_client: import("@wolfstar/http-framework").Client, options: ClientOptions): void;
26
+ preLoad: () => Promise<void>;
27
+ postListen(_client: import("@wolfstar/http-framework").Client, options: ClientOptions): void;
28
+ };
29
+ //#endregion
30
+ export { _default as default };
31
+ //# sourceMappingURL=plugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.d.ts","names":[],"sources":["../../src/plugin.ts"],"mappings":""}
@@ -0,0 +1,50 @@
1
+ import "./index.js";
2
+ import { n as installI18n, r as watchLanguages, t as initI18n } from "./hooks-Bwy47aXr.js";
3
+ import { definePlugin } from "@wolfstar/http-framework";
4
+
5
+ //#region src/plugin.ts
6
+ /**
7
+ * The i18next plugin: installs the `InternationalizationHandler` on `container.i18n`, loads the languages before the
8
+ * stores, and watches the languages directory when HMR is enabled.
9
+ *
10
+ * The plugin exposes the chokidar watcher started by `postListen` as `watcher` (`null` until then, and when HMR is not
11
+ * enabled), so it can be closed on shutdown, like `I18nextPlugin.watcher` of `./register`.
12
+ *
13
+ * @param pluginOptions The handler options. `ClientOptions.i18n` is merged over them.
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * import i18nPlugin from '@wolfstar/plugin-i18next/plugin';
18
+ *
19
+ * const client = new Client({ plugins: [i18nPlugin({ defaultName: 'en-US' })] });
20
+ * ```
21
+ */
22
+ var plugin_default = definePlugin((pluginOptions) => {
23
+ const isEmpty = (value) => !value || Object.keys(value).length === 0;
24
+ const merged = (options) => ({
25
+ ...options,
26
+ i18n: isEmpty(pluginOptions) && isEmpty(options.i18n) ? void 0 : {
27
+ ...pluginOptions,
28
+ ...options.i18n
29
+ }
30
+ });
31
+ let watcher = null;
32
+ return {
33
+ name: "@wolfstar/plugin-i18next",
34
+ get watcher() {
35
+ return watcher;
36
+ },
37
+ preGenericsInitialization(_client, options) {
38
+ options.i18n = merged(options).i18n;
39
+ installI18n(options);
40
+ },
41
+ preLoad: () => initI18n(),
42
+ postListen(_client, options) {
43
+ watcher = watchLanguages(merged(options)) ?? watcher;
44
+ }
45
+ };
46
+ });
47
+
48
+ //#endregion
49
+ export { plugin_default as default };
50
+ //# sourceMappingURL=plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.js","names":[],"sources":["../../src/plugin.ts"],"sourcesContent":["import { definePlugin, type ClientOptions } from \"@wolfstar/http-framework\";\nimport type { FSWatcher } from \"chokidar\";\nimport \"./index\";\nimport { initI18n, installI18n, watchLanguages } from \"./hooks\";\nimport type { InternationalizationOptions } from \"./lib/types\";\n\n/**\n * The i18next plugin: installs the `InternationalizationHandler` on `container.i18n`, loads the languages before the\n * stores, and watches the languages directory when HMR is enabled.\n *\n * The plugin exposes the chokidar watcher started by `postListen` as `watcher` (`null` until then, and when HMR is not\n * enabled), so it can be closed on shutdown, like `I18nextPlugin.watcher` of `./register`.\n *\n * @param pluginOptions The handler options. `ClientOptions.i18n` is merged over them.\n *\n * @example\n * ```ts\n * import i18nPlugin from '@wolfstar/plugin-i18next/plugin';\n *\n * const client = new Client({ plugins: [i18nPlugin({ defaultName: 'en-US' })] });\n * ```\n */\nexport default definePlugin((pluginOptions?: InternationalizationOptions) => {\n // Without any options the handler falls back to its own defaults, so only build an object when there is one. Kit's\n // `defineModule` calls `setup` with `{}` rather than `undefined` when no options are given, so an empty object\n // counts as \"no options\" too.\n const isEmpty = (value: InternationalizationOptions | undefined) =>\n !value || Object.keys(value).length === 0;\n const merged = (options: ClientOptions): ClientOptions => ({\n ...options,\n i18n:\n isEmpty(pluginOptions) && isEmpty(options.i18n)\n ? undefined\n : { ...pluginOptions, ...options.i18n },\n });\n\n let watcher: FSWatcher | null = null;\n\n return {\n name: \"@wolfstar/plugin-i18next\",\n get watcher() {\n return watcher;\n },\n preGenericsInitialization(_client, options) {\n options.i18n = merged(options).i18n;\n installI18n(options);\n },\n preLoad: () => initI18n(),\n postListen(_client, options) {\n watcher = watchLanguages(merged(options)) ?? watcher;\n },\n };\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAsBA,qBAAe,cAAc,kBAAgD;CAI3E,MAAM,WAAW,UACf,CAAC,SAAS,OAAO,KAAK,KAAK,CAAC,CAAC,WAAW;CAC1C,MAAM,UAAU,aAA2C;EACzD,GAAG;EACH,MACE,QAAQ,aAAa,KAAK,QAAQ,QAAQ,IAAI,IAC1C,SACA;GAAE,GAAG;GAAe,GAAG,QAAQ;EAAK;CAC5C;CAEA,IAAI,UAA4B;CAEhC,OAAO;EACL,MAAM;EACN,IAAI,UAAU;GACZ,OAAO;EACT;EACA,0BAA0B,SAAS,SAAS;GAC1C,QAAQ,OAAO,OAAO,OAAO,CAAC,CAAC;GAC/B,YAAY,OAAO;EACrB;EACA,eAAe,SAAS;EACxB,WAAW,SAAS,SAAS;GAC3B,UAAU,eAAe,OAAO,OAAO,CAAC,KAAK;EAC/C;CACF;AACF,CAAC"}
@@ -3,7 +3,7 @@ import { Client, ClientOptions, Plugin, postListen, preGenericsInitialization, p
3
3
  import { FSWatcher } from "chokidar";
4
4
  //#region src/register.d.ts
5
5
  /**
6
- * Registers the i18next-powered {@link InternationalizationHandler} on `container.i18n`, loading the
6
+ * Registers the i18next-powered `InternationalizationHandler` on `container.i18n`, loading the
7
7
  * languages before the stores are loaded so command builders can be localized at registration time.
8
8
  *
9
9
  * Activate by importing the side-effecting entrypoint before creating the client:
@@ -1 +1 @@
1
- {"version":3,"file":"register.d.ts","names":[],"sources":["../../src/register.ts"],"mappings":";;;;;;;;;;;;;;qBA4Ba,sBAAsB;;;;;SAKnB,SAAS;UAER,2BAA2B,MAAM,QAAQ,SAAS;UAI5C,SAAS,MAAM,SAAS;UAI9B,YAAY,MAAM,QAAQ,SAAS"}
1
+ {"version":3,"file":"register.d.ts","names":[],"sources":["../../src/register.ts"],"mappings":";;;;;;;;;;;;;;qBAsBa,sBAAsB;;;;;SAKnB,SAAS;UAER,2BAA2B,MAAM,QAAQ,SAAS;UAI5C,SAAS,MAAM,SAAS;UAI9B,YAAY,MAAM,QAAQ,SAAS"}
@@ -1,20 +1,10 @@
1
- import { InternationalizationHandler } from "./index.js";
2
- import { Client, Plugin, container, postListen, preGenericsInitialization, preLoad } from "@wolfstar/http-framework";
3
- import { watch } from "chokidar";
1
+ import "./index.js";
2
+ import { n as installI18n, r as watchLanguages, t as initI18n } from "./hooks-Bwy47aXr.js";
3
+ import { Client, Plugin, postListen, preGenericsInitialization, preLoad } from "@wolfstar/http-framework";
4
4
 
5
5
  //#region src/register.ts
6
6
  /**
7
- * The chokidar events that make the languages directory's contents change.
8
- */
9
- const HmrEvents = [
10
- "add",
11
- "addDir",
12
- "change",
13
- "unlink",
14
- "unlinkDir"
15
- ];
16
- /**
17
- * Registers the i18next-powered {@link InternationalizationHandler} on `container.i18n`, loading the
7
+ * Registers the i18next-powered `InternationalizationHandler` on `container.i18n`, loading the
18
8
  * languages before the stores are loaded so command builders can be localized at registration time.
19
9
  *
20
10
  * Activate by importing the side-effecting entrypoint before creating the client:
@@ -30,20 +20,13 @@ var I18nextPlugin = class I18nextPlugin extends Plugin {
30
20
  */
31
21
  static watcher = null;
32
22
  static [preGenericsInitialization](options) {
33
- container.i18n = new InternationalizationHandler(options.i18n);
23
+ installI18n(options);
34
24
  }
35
25
  static async [preLoad]() {
36
- await container.i18n.init();
26
+ await initI18n();
37
27
  }
38
28
  static [postListen](options) {
39
- if (!options.i18n?.hmr?.enabled) return;
40
- console.info("[plugin-i18next] HMR enabled. Watching for language changes.");
41
- const watcher = watch(container.i18n.languagesDirectory, {
42
- ignoreInitial: true,
43
- ...options.i18n.hmr.options
44
- });
45
- for (const event of HmrEvents) watcher.on(event, () => void container.i18n.reloadResources());
46
- I18nextPlugin.watcher = watcher;
29
+ I18nextPlugin.watcher = watchLanguages(options) ?? I18nextPlugin.watcher;
47
30
  }
48
31
  };
49
32
  Client.plugins.registerPreGenericsInitializationHook(I18nextPlugin[preGenericsInitialization], "WolfStar-I18next-PreGenericsInitialization");
@@ -1 +1 @@
1
- {"version":3,"file":"register.js","names":[],"sources":["../../src/register.ts"],"sourcesContent":["import {\n Client,\n container,\n Plugin,\n postListen,\n preGenericsInitialization,\n preLoad,\n type ClientOptions,\n} from \"@wolfstar/http-framework\";\nimport { watch, type FSWatcher } from \"chokidar\";\nimport \"./index\";\nimport { InternationalizationHandler } from \"./lib/InternationalizationHandler\";\n\n/**\n * The chokidar events that make the languages directory's contents change.\n */\nconst HmrEvents = [\"add\", \"addDir\", \"change\", \"unlink\", \"unlinkDir\"] as const;\n\n/**\n * Registers the i18next-powered {@link InternationalizationHandler} on `container.i18n`, loading the\n * languages before the stores are loaded so command builders can be localized at registration time.\n *\n * Activate by importing the side-effecting entrypoint before creating the client:\n *\n * ```ts\n * import '@wolfstar/plugin-i18next/register';\n * ```\n */\nexport class I18nextPlugin extends Plugin {\n /**\n * The chokidar watcher started by the `postListen` hook when HMR is enabled, or `null` when it is\n * not. Exposed so it can be closed on shutdown.\n */\n public static watcher: FSWatcher | null = null;\n\n public static [preGenericsInitialization](this: Client, options: ClientOptions): void {\n container.i18n = new InternationalizationHandler(options.i18n);\n }\n\n public static async [preLoad](this: Client): Promise<void> {\n await container.i18n.init();\n }\n\n public static [postListen](this: Client, options: ClientOptions): void {\n if (!options.i18n?.hmr?.enabled) return;\n\n console.info(\"[plugin-i18next] HMR enabled. Watching for language changes.\");\n\n // `ignoreInitial` defaults to `true` here: chokidar otherwise replays an `add` for every file\n // already on disk, which would trigger a reload per translation file on startup.\n const watcher = watch(container.i18n.languagesDirectory, {\n ignoreInitial: true,\n ...options.i18n.hmr.options,\n });\n\n // Adding a locale directory or a namespace file emits `addDir` / `add`, not `change`, so all of\n // them have to be watched for new languages and namespaces to be picked up.\n for (const event of HmrEvents) {\n watcher.on(event, () => void container.i18n.reloadResources());\n }\n\n I18nextPlugin.watcher = watcher;\n }\n}\n\nClient.plugins.registerPreGenericsInitializationHook(\n I18nextPlugin[preGenericsInitialization],\n \"WolfStar-I18next-PreGenericsInitialization\",\n);\nClient.plugins.registerPreLoadHook(I18nextPlugin[preLoad], \"WolfStar-I18next-PreLoad\");\nClient.plugins.registerPostListenHook(I18nextPlugin[postListen], \"WolfStar-I18next-PostListen\");\n"],"mappings":";;;;;;;;AAgBA,MAAM,YAAY;CAAC;CAAO;CAAU;CAAU;CAAU;AAAW;;;;;;;;;;;AAYnE,IAAa,gBAAb,MAAa,sBAAsB,OAAO;;;;;CAKxC,OAAc,UAA4B;CAE1C,QAAe,2BAAyC,SAA8B;EACpF,UAAU,OAAO,IAAI,4BAA4B,QAAQ,IAAI;CAC/D;CAEA,cAAqB,WAAsC;EACzD,MAAM,UAAU,KAAK,KAAK;CAC5B;CAEA,QAAe,YAA0B,SAA8B;EACrE,IAAI,CAAC,QAAQ,MAAM,KAAK,SAAS;EAEjC,QAAQ,KAAK,8DAA8D;EAI3E,MAAM,UAAU,MAAM,UAAU,KAAK,oBAAoB;GACvD,eAAe;GACf,GAAG,QAAQ,KAAK,IAAI;EACtB,CAAC;EAID,KAAK,MAAM,SAAS,WAClB,QAAQ,GAAG,aAAa,KAAK,UAAU,KAAK,gBAAgB,CAAC;EAG/D,cAAc,UAAU;CAC1B;AACF;AAEA,OAAO,QAAQ,sCACb,cAAc,4BACd,4CACF;AACA,OAAO,QAAQ,oBAAoB,cAAc,UAAU,0BAA0B;AACrF,OAAO,QAAQ,uBAAuB,cAAc,aAAa,6BAA6B"}
1
+ {"version":3,"file":"register.js","names":[],"sources":["../../src/register.ts"],"sourcesContent":["import {\n Client,\n Plugin,\n postListen,\n preGenericsInitialization,\n preLoad,\n type ClientOptions,\n} from \"@wolfstar/http-framework\";\nimport type { FSWatcher } from \"chokidar\";\nimport \"./index\";\nimport { initI18n, installI18n, watchLanguages } from \"./hooks\";\n\n/**\n * Registers the i18next-powered `InternationalizationHandler` on `container.i18n`, loading the\n * languages before the stores are loaded so command builders can be localized at registration time.\n *\n * Activate by importing the side-effecting entrypoint before creating the client:\n *\n * ```ts\n * import '@wolfstar/plugin-i18next/register';\n * ```\n */\nexport class I18nextPlugin extends Plugin {\n /**\n * The chokidar watcher started by the `postListen` hook when HMR is enabled, or `null` when it is\n * not. Exposed so it can be closed on shutdown.\n */\n public static watcher: FSWatcher | null = null;\n\n public static [preGenericsInitialization](this: Client, options: ClientOptions): void {\n installI18n(options);\n }\n\n public static async [preLoad](this: Client): Promise<void> {\n await initI18n();\n }\n\n public static [postListen](this: Client, options: ClientOptions): void {\n I18nextPlugin.watcher = watchLanguages(options) ?? I18nextPlugin.watcher;\n }\n}\n\nClient.plugins.registerPreGenericsInitializationHook(\n I18nextPlugin[preGenericsInitialization],\n \"WolfStar-I18next-PreGenericsInitialization\",\n);\nClient.plugins.registerPreLoadHook(I18nextPlugin[preLoad], \"WolfStar-I18next-PreLoad\");\nClient.plugins.registerPostListenHook(I18nextPlugin[postListen], \"WolfStar-I18next-PostListen\");\n"],"mappings":";;;;;;;;;;;;;;;AAsBA,IAAa,gBAAb,MAAa,sBAAsB,OAAO;;;;;CAKxC,OAAc,UAA4B;CAE1C,QAAe,2BAAyC,SAA8B;EACpF,YAAY,OAAO;CACrB;CAEA,cAAqB,WAAsC;EACzD,MAAM,SAAS;CACjB;CAEA,QAAe,YAA0B,SAA8B;EACrE,cAAc,UAAU,eAAe,OAAO,KAAK,cAAc;CACnE;AACF;AAEA,OAAO,QAAQ,sCACb,cAAc,4BACd,4CACF;AACA,OAAO,QAAQ,oBAAoB,cAAc,UAAU,0BAA0B;AACrF,OAAO,QAAQ,uBAAuB,cAAc,aAAa,6BAA6B"}
@@ -0,0 +1,270 @@
1
+ import { FlatNamespace, InitOptions, TypeOptions } from "i18next";
2
+ import { APIInteraction, APIPingInteraction, APIUser, ChannelType, LocaleString, LocalizationMap } from "discord-api-types/v10";
3
+ import { Awaitable } from "@sapphire/utilities";
4
+ import { Backend } from "@wolfstar/i18next-backend";
5
+ import { ChokidarOptions } from "chokidar";
6
+ //#region src/lib/types.d.ts
7
+ /**
8
+ * This is a re-exported type from i18next.
9
+ *
10
+ * We could use the `NoInfer` TypeScript built-in utility, however this package still supports
11
+ * TypeScript < 5.4.
12
+ *
13
+ * @see https://github.com/millsp/ts-toolbelt/blob/master/sources/Function/NoInfer.ts
14
+ */
15
+ type $NoInfer<A> = [A][A extends any ? 0 : never];
16
+ /**
17
+ * This is a re-exported type from i18next. It is essentially an object of key-value pairs, where
18
+ * the key is a string and the value is any.
19
+ */
20
+ interface $Dictionary {
21
+ [key: string]: any;
22
+ }
23
+ /**
24
+ * This is a re-exported type from i18next. It is the returned type from the translation helpers
25
+ * when `returnObjects` is `true` in the options.
26
+ */
27
+ type $SpecialObject = $Dictionary | Array<string | $Dictionary>;
28
+ /**
29
+ * The namespace separator i18next is configured with, `':'` unless `CustomTypeOptions` overrides it.
30
+ */
31
+ type LocaleSeparator = TypeOptions["nsSeparator"];
32
+ /**
33
+ * A `<namespace><separator><key>` shaped key, used as the root key overload of
34
+ * {@link applyLocalizedBuilder}.
35
+ */
36
+ type LocalePrefixKey = `${string}${LocaleSeparator}${string}`;
37
+ /**
38
+ * Every namespace known through the `CustomTypeOptions.resources` augmentation generated by
39
+ * [`@wolfstar/i18next-type-generator`](https://www.npmjs.com/package/@wolfstar/i18next-type-generator).
40
+ *
41
+ * @remarks
42
+ * Used as the default `Ns` generic of every helper that takes a fully-qualified
43
+ * `<namespace><separator><key>` key, since i18next only parses those out of `ParseKeys` when `Ns`
44
+ * is the array of every namespace the key could belong to — a single namespace (i18next's own
45
+ * `DefaultNamespace`) only parses keys of that one namespace, unprefixed.
46
+ */
47
+ type AnyNamespace = readonly FlatNamespace[];
48
+ /**
49
+ * The subset of an interaction payload the localization helpers need in order to resolve a language.
50
+ *
51
+ * @remarks
52
+ * `@wolfstar/http-framework` receives raw Discord interaction payloads over HTTP, so the helpers
53
+ * operate on `discord-api-types` structures rather than on `discord.js` class instances.
54
+ */
55
+ type Interaction = Pick<Exclude<APIInteraction, APIPingInteraction>, "locale" | "guild_locale" | "guild_id"> & Partial<Pick<Exclude<APIInteraction, APIPingInteraction>, "channel_id" | "user" | "member">>;
56
+ /**
57
+ * The subset of a guild payload the localization helpers need.
58
+ *
59
+ * @remarks
60
+ * `APIGuild` satisfies it, as does any partial guild that carries an id. Only a full guild payload
61
+ * carries `preferred_locale`; without it the guild's id is still handed to
62
+ * {@link InternationalizationHandler.fetchLanguage}, so a custom hook can resolve the language.
63
+ */
64
+ interface GuildTarget {
65
+ id: string;
66
+ /**
67
+ * The guild's preferred locale. Typed as `string` rather than `LocaleString` because
68
+ * `APIGuild` types it as the `Locale` enum; it is validated at runtime.
69
+ */
70
+ preferred_locale?: string;
71
+ }
72
+ /**
73
+ * The subset of a channel payload the localization helpers need. Every `APIChannel` member
74
+ * satisfies it.
75
+ *
76
+ * @remarks
77
+ * A channel payload carries no locale of its own, so the language is resolved from
78
+ * {@link InternationalizationHandler.fetchLanguage} and then from the configured default.
79
+ */
80
+ interface ChannelTarget {
81
+ id: string;
82
+ type: ChannelType;
83
+ guild_id?: string;
84
+ }
85
+ /**
86
+ * The subset of a message payload the localization helpers need. `APIMessage` satisfies it, and
87
+ * gateway message payloads additionally carry `guild_id`.
88
+ *
89
+ * @remarks
90
+ * Like {@link ChannelTarget}, a message carries no locale of its own.
91
+ */
92
+ interface MessageTarget {
93
+ id: string;
94
+ channel_id: string;
95
+ guild_id?: string;
96
+ author?: Pick<APIUser, "id">;
97
+ }
98
+ /**
99
+ * Any value the localization helpers accept as the source of a language.
100
+ *
101
+ * @remarks
102
+ * The four members are told apart structurally, in this order: an {@link Interaction} has `locale`,
103
+ * a {@link MessageTarget} has `channel_id`, a {@link ChannelTarget} has `type`, and anything else is
104
+ * a {@link GuildTarget}.
105
+ */
106
+ type Target = Interaction | MessageTarget | ChannelTarget | GuildTarget;
107
+ /**
108
+ * Configure whether to use Hot-Module-Replacement (HMR) for your i18next resources using these
109
+ * options. The minimum config to enable HMR is to set `enabled` to true. Any other properties are
110
+ * optional.
111
+ */
112
+ interface HMROptions {
113
+ /**
114
+ * HMR status for the i18next plugin.
115
+ * @default false
116
+ */
117
+ enabled: boolean;
118
+ /**
119
+ * Languages that will be reloaded when updating the languages directory.
120
+ *
121
+ * @remarks
122
+ * Pinning both this and {@link HMROptions.namespaces} skips the directory walk, so languages and
123
+ * namespaces added while the process is running are not registered on i18next.
124
+ * @default All languages that are automatically resolved from your folder setup
125
+ */
126
+ languages?: string | string[];
127
+ /**
128
+ * Namespaces that will be reloaded when updating the languages directory.
129
+ *
130
+ * @remarks
131
+ * Pinning both this and {@link HMROptions.languages} skips the directory walk, so languages and
132
+ * namespaces added while the process is running are not registered on i18next.
133
+ * @default All namespaces that are automatically resolved from your languages folder setup
134
+ */
135
+ namespaces?: string | string[];
136
+ /**
137
+ * The options passed to `chokidar`'s `watch`.
138
+ *
139
+ * @remarks
140
+ * `ignoreInitial` defaults to `true`, since chokidar would otherwise replay an `add` event for
141
+ * every translation file already on disk and trigger a reload for each of them on startup.
142
+ */
143
+ options?: ChokidarOptions;
144
+ }
145
+ /**
146
+ * Used to dynamically add options based on the languages found in {@link InternationalizationHandler.init}.
147
+ */
148
+ type DynamicOptions<T extends InitOptions> = (namespaces: string[], languages: string[]) => T;
149
+ /**
150
+ * The options used in {@link InternationalizationHandler}.
151
+ */
152
+ interface InternationalizationOptions {
153
+ /**
154
+ * Used as the default 2nd to last fallback locale if no other is found. It's only followed by
155
+ * `'en-US'`.
156
+ */
157
+ defaultName?: string;
158
+ /**
159
+ * The options passed to `backend` in `i18next.init`.
160
+ */
161
+ backend?: Backend.Options;
162
+ /**
163
+ * The options passed to `i18next.init`.
164
+ */
165
+ i18next?: InitOptions | DynamicOptions<InitOptions>;
166
+ /**
167
+ * The directory in which `@wolfstar/i18next-backend` should search for files.
168
+ * @default `rootDirectory/languages`
169
+ */
170
+ defaultLanguageDirectory?: string;
171
+ /**
172
+ * The default value to be used if a specific language key isn't found. Defaults to
173
+ * `'default:default'`.
174
+ */
175
+ defaultMissingKey?: string;
176
+ /**
177
+ * The default namespace that is prefixed to all keys that don't specify it. Defaults to
178
+ * `'default'`.
179
+ */
180
+ defaultNS?: string;
181
+ /**
182
+ * Array of formatters to add to i18next.
183
+ * @default []
184
+ */
185
+ formatters?: I18nextFormatter[];
186
+ /**
187
+ * Reload languages and namespaces when updating the languages directory.
188
+ */
189
+ hmr?: HMROptions;
190
+ /**
191
+ * A function that is to be used to retrieve the language for the current context.
192
+ *
193
+ * If this is not set, then the language will always be resolved from the interaction's locales.
194
+ *
195
+ * This will be inserted for {@link InternationalizationHandler.fetchLanguage}.
196
+ * @default () => null
197
+ */
198
+ fetchLanguage?: (context: InternationalizationContext) => Awaitable<string | null>;
199
+ }
200
+ /**
201
+ * Context for {@link InternationalizationHandler.fetchLanguage} functions. This context enables
202
+ * implementation of per-guild, per-channel, and per-user localization.
203
+ */
204
+ interface InternationalizationContext {
205
+ /** The ID of the guild the interaction was sent from, or `null` when sent from a DM. */
206
+ guildId: string | null;
207
+ /** The ID of the channel the interaction was sent from, or `null` when it was not provided. */
208
+ channelId: string | null;
209
+ /** The ID of the user that sent the interaction, or `null` when it was not provided. */
210
+ userId: string | null;
211
+ /** The locale the guild the interaction was sent from is configured with. */
212
+ interactionGuildLocale?: LocaleString;
213
+ /** The locale the user that sent the interaction is configured with. */
214
+ interactionLocale?: LocaleString;
215
+ /**
216
+ * The preferred locale of the guild the target belongs to.
217
+ *
218
+ * @remarks
219
+ * Filled in from `guild_locale` for an {@link Interaction} and from `preferred_locale` for a
220
+ * {@link GuildTarget}; a {@link ChannelTarget} and a {@link MessageTarget} carry no locale, so it
221
+ * is left undefined for them.
222
+ */
223
+ preferredLocale?: string;
224
+ }
225
+ interface InternationalizationClientOptions {
226
+ i18n?: InternationalizationOptions;
227
+ }
228
+ /**
229
+ * Represents a formatter that is added to i18next with `i18next.services.formatter.add` or
230
+ * `i18next.services.formatter.addCached`, depending on the `cached` property.
231
+ *
232
+ * @see {@link https://www.i18next.com/translation-function/formatting#adding-custom-format-function}
233
+ */
234
+ type I18nextFormatter = I18nextNamedFormatter | I18nextNamedCachedFormatter;
235
+ /**
236
+ * Represents a formatter that is added to i18next with `i18next.services.formatter.add`.
237
+ *
238
+ * @see {@link https://www.i18next.com/translation-function/formatting#adding-custom-format-function}
239
+ */
240
+ interface I18nextNamedFormatter {
241
+ cached?: false;
242
+ name: string;
243
+ format(value: any, lng: string | undefined, options: any): string;
244
+ }
245
+ /**
246
+ * Represents a cached formatter that is added to i18next with `i18next.services.formatter.addCached`.
247
+ *
248
+ * @see {@link https://www.i18next.com/translation-function/formatting#adding-custom-format-function}
249
+ */
250
+ interface I18nextNamedCachedFormatter {
251
+ cached: true;
252
+ name: string;
253
+ format(lng: string | undefined, options: any): (value: any) => string;
254
+ }
255
+ interface LocalizedData {
256
+ value: string;
257
+ localizations: LocalizationMap;
258
+ }
259
+ interface BuilderWithName {
260
+ setName(name: string): this;
261
+ setNameLocalizations(localizedNames: LocalizationMap | null): this;
262
+ }
263
+ interface BuilderWithDescription {
264
+ setDescription(description: string): this;
265
+ setDescriptionLocalizations(localizedDescriptions: LocalizationMap | null): this;
266
+ }
267
+ type BuilderWithNameAndDescription = BuilderWithName & BuilderWithDescription;
268
+ //#endregion
269
+ export { Target as C, MessageTarget as S, InternationalizationContext as _, BuilderWithDescription as a, LocaleSeparator as b, ChannelTarget as c, HMROptions as d, I18nextFormatter as f, InternationalizationClientOptions as g, Interaction as h, AnyNamespace as i, DynamicOptions as l, I18nextNamedFormatter as m, $NoInfer as n, BuilderWithName as o, I18nextNamedCachedFormatter as p, $SpecialObject as r, BuilderWithNameAndDescription as s, $Dictionary as t, GuildTarget as u, InternationalizationOptions as v, LocalizedData as x, LocalePrefixKey as y };
270
+ //# sourceMappingURL=types-BhhqHOJk.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types-BhhqHOJk.d.ts","names":[],"sources":["../../src/lib/types.ts"],"mappings":";;;;;;;;;;;;;;KAqBY,SAAS,MAAM,GAAG;;;;;UAMb;GACd;;;;;;KAOS,iBAAiB,cAAc,eAAe;;;;KAK9C,kBAAkB;;;;;KAMlB,8BAA8B;;;;;;;;;;;KAY9B,wBAAwB;;;;;;;;KASxB,cAAc,KACxB,QAAQ,gBAAgB,+DAGxB,QAAQ,KAAK,QAAQ,gBAAgB;;;;;;;;;UAUtB;EACf;;;;;EAKA;;;;;;;;;;UAWe;EACf;EACA,MAAM;EACN;;;;;;;;;UAUe;EACf;EACA;EACA;EACA,SAAS,KAAK;;;;;;;;;;KAWJ,SAAS,cAAc,gBAAgB,gBAAgB;;;;;;UAOlD;;;;;EAKf;;;;;;;;;EAUA;;;;;;;;;EAUA;;;;;;;;EASA,UAAU;;;;;KAMA,eAAe,UAAU,gBACnC,sBACA,wBACG;;;;UAKY;;;;;EAKf;;;;EAKA,UAAU,QAAQ;;;;EAKlB,UAAU,cAAc,eAAe;;;;;EAMvC;;;;;EAMA;;;;;EAMA;;;;;EAMA,aAAa;;;;EAKb,MAAM;;;;;;;;;EAUN,iBAAiB,SAAS,gCAAgC;;;;;;UAO3C;;EAEf;;EAEA;;EAEA;;EAEA,yBAAyB;;EAEzB,oBAAoB;;;;;;;;;EASpB;;UAGe;EACf,OAAO;;;;;;;;KASG,mBAAmB,wBAAwB;;;;;;UAOtC;EACf;EACA;EACA,OAAO,YAAY,yBAAyB;;;;;;;UAQ7B;EACf;EACA;EACA,OAAO,yBAAyB,gBAAgB;;UAGjC;EACf;EACA,eAAe;;UAGA;EACf,QAAQ;EACR,qBAAqB,gBAAgB;;UAGtB;EACf,eAAe;EACf,4BAA4B,uBAAuB;;KAGzC,gCAAgC,kBAAkB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wolfstar/plugin-i18next",
3
- "version": "2.1.2",
3
+ "version": "2.2.0-next-20261004192124",
4
4
  "description": "Plugin for @wolfstar/http-framework adding i18next-powered internationalization for HTTP interactions",
5
5
  "keywords": [
6
6
  "discord",
@@ -42,6 +42,18 @@
42
42
  "types": "./dist/esm/register.d.ts",
43
43
  "default": "./dist/esm/register.js"
44
44
  }
45
+ },
46
+ "./plugin": {
47
+ "import": {
48
+ "types": "./dist/esm/plugin.d.ts",
49
+ "default": "./dist/esm/plugin.js"
50
+ }
51
+ },
52
+ "./module": {
53
+ "import": {
54
+ "types": "./dist/esm/module.d.ts",
55
+ "default": "./dist/esm/module.js"
56
+ }
45
57
  }
46
58
  },
47
59
  "publishConfig": {
@@ -60,15 +72,20 @@
60
72
  },
61
73
  "devDependencies": {
62
74
  "@wolfstar/http-framework": "^6.1.0",
63
- "@wolfstar/i18next-type-generator": "3.1.5"
75
+ "@wolfstar/i18next-type-generator": "3.1.5",
76
+ "@wolfstar/kit": "^0.1.0"
64
77
  },
65
78
  "peerDependencies": {
66
79
  "@wolfstar/http-framework": "^3.1.0 || ^5.0.0 || ^6.0.0",
67
- "@wolfstar/i18next-type-generator": "^3.0.0"
80
+ "@wolfstar/i18next-type-generator": "^3.0.0",
81
+ "@wolfstar/kit": "^0.1.0"
68
82
  },
69
83
  "peerDependenciesMeta": {
70
84
  "@wolfstar/i18next-type-generator": {
71
85
  "optional": true
86
+ },
87
+ "@wolfstar/kit": {
88
+ "optional": true
72
89
  }
73
90
  },
74
91
  "engines": {