@sapphire/plugin-i18next 3.0.2-next.f0bab02.0 → 3.1.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/CHANGELOG.md CHANGED
@@ -2,6 +2,16 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file.
4
4
 
5
+ # [@sapphire/plugin-i18next@3.1.0](https://github.com/sapphiredev/plugins/compare/@sapphire/plugin-i18next@3.0.1...@sapphire/plugin-i18next@3.1.0) - (2022-10-16)
6
+
7
+ ## 🐛 Bug Fixes
8
+
9
+ - **i18next:** Update dependencies ([98e3313](https://github.com/sapphiredev/plugins/commit/98e3313c6bdf279d8301a4d6705a4b40f6767929))
10
+
11
+ ## 🚀 Features
12
+
13
+ - **plugin-i18next:** Add `applyLocalizedBuilder` and `createSelectMenuChoiceName` to help registering localized commands (#372) ([6deee87](https://github.com/sapphiredev/plugins/commit/6deee87c6dee3af2d5f7c02d39d9aa03b480d65f))
14
+
5
15
  # [@sapphire/plugin-i18next@3.0.1](https://github.com/sapphiredev/plugins/compare/@sapphire/plugin-i18next@3.0.0...@sapphire/plugin-i18next@3.0.1) - (2022-10-02)
6
16
 
7
17
  ## 🐛 Bug Fixes
package/dist/index.mjs CHANGED
@@ -2,6 +2,11 @@ import mod from "./index.js";
2
2
 
3
3
  export default mod;
4
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;
5
9
  export const fetchLanguage = mod.fetchLanguage;
6
10
  export const fetchT = mod.fetchT;
11
+ export const getLocalizedData = mod.getLocalizedData;
7
12
  export const resolveKey = mod.resolveKey;
@@ -1,6 +1,7 @@
1
- import type { NonNullObject } from '@sapphire/utilities';
1
+ import { type NonNullObject } from '@sapphire/utilities';
2
+ import { APIApplicationCommandOptionChoice } from 'discord-api-types/v10';
2
3
  import type { StringMap, TFunctionKeys, TFunctionResult, TOptions } from 'i18next';
3
- import type { Target } from './types';
4
+ import type { BuilderWithDescription, BuilderWithName, BuilderWithNameAndDescription, LocalizedData, Target } from './types';
4
5
  /**
5
6
  * Retrieves the language name for a specific target, using {@link InternationalizationHandler.fetchLanguage}.
6
7
  * If {@link InternationalizationHandler.fetchLanguage} is not defined or this function returns a nullish value,
@@ -30,4 +31,106 @@ export declare function fetchT(target: Target): Promise<import("i18next").TFunct
30
31
  * @returns The data that `key` held, processed by i18next.
31
32
  */
32
33
  export declare function resolveKey<TResult extends TFunctionResult = string, TKeys extends TFunctionKeys = string, TInterpolationMap extends NonNullObject = StringMap>(target: Target, key: TKeys | TKeys[], options?: TOptions<TInterpolationMap>): Promise<TResult>;
34
+ /**
35
+ * Gets the value and the localizations from a language key.
36
+ * @param key The key to get the localizations from.
37
+ * @returns The retrieved data.
38
+ * @remarks This should be called **strictly** after loading the locales.
39
+ */
40
+ export declare function getLocalizedData(key: TFunctionKeys): LocalizedData;
41
+ /**
42
+ * Applies the localized names on the builder, calling `setName` and `setNameLocalizations`.
43
+ * @param builder The builder to apply the localizations to.
44
+ * @param key The key to get the localizations from.
45
+ * @returns The updated builder.
46
+ */
47
+ export declare function applyNameLocalizedBuilder<T extends BuilderWithName>(builder: T, key: TFunctionKeys): T;
48
+ /**
49
+ * Applies the localized descriptions on the builder, calling `setDescription` and `setDescriptionLocalizations`.
50
+ * @param builder The builder to apply the localizations to.
51
+ * @param key The key to get the localizations from.
52
+ * @returns The updated builder.
53
+ */
54
+ export declare function applyDescriptionLocalizedBuilder<T extends BuilderWithDescription>(builder: T, key: TFunctionKeys): T;
55
+ /**
56
+ * Applies the localized names and descriptions on the builder, calling {@link applyNameLocalizedBuilder} and
57
+ * {@link applyDescriptionLocalizedBuilder}.
58
+ *
59
+ * @param builder The builder to apply the localizations to.
60
+ *
61
+ * @param params The root key or the key for the name and description keys.
62
+ * This needs to be either 1 or 2 parameters.
63
+ * See examples below for more information.
64
+ *
65
+ * @returns The updated builder. You can chain subsequent builder methods on this.
66
+ *
67
+ * @remarks If only 2 parameters were passed, then this function will automatically append `Name` and `Description`
68
+ * to the root-key (wherein `root-key` is second parameter in the function, after `builder`)
69
+ * passed through the second parameter.
70
+ *
71
+ * For example given `applyLocalizedBuilder(builder, 'userinfo')` the localized options will use the i18next keys
72
+ * `userinfoName` and `userinfoDescription`.
73
+ *
74
+ * In the following example we provide all parameters and add a User Option
75
+ * `applyLocalizedBuilder` needs either
76
+ * @example
77
+ * ```typescript
78
+ * class UserInfoCommand extends Command {
79
+ * public registerApplicationCommands(registry: ChatInputCommand.Registry) {
80
+ * registry.registerChatInputCommand(
81
+ * (builder) =>
82
+ * applyLocalizedBuilder(builder, 'commands/names:userinfo', 'commands/descriptions:userinfo')
83
+ * .addUserOption(
84
+ * (input) => applyLocalizedBuilder(input, 'commands/options:userinfo-name', 'commands/options:userinfo-description').setRequired(true)
85
+ * )
86
+ * );
87
+ * }
88
+ * }
89
+ * ```
90
+ *
91
+ * In the following example we provide single root keys which means `Name` and `Description` get appended as mentioned above.
92
+ * @example
93
+ * ```typescript
94
+ * class UserInfoCommand extends Command {
95
+ * public registerApplicationCommands(registry: ChatInputCommand.Registry) {
96
+ * registry.registerChatInputCommand(
97
+ * (builder) =>
98
+ * applyLocalizedBuilder(builder, 'commands:userinfo')
99
+ * .addUserOption(
100
+ * (input) => applyLocalizedBuilder(input, 'options:userinfo').setRequired(true)
101
+ * )
102
+ * );
103
+ * }
104
+ * }
105
+ * ```
106
+ */
107
+ export declare function applyLocalizedBuilder<T extends BuilderWithNameAndDescription>(builder: T, ...params: [root: string] | [name: TFunctionKeys, description: TFunctionKeys]): T;
108
+ /**
109
+ * Constructs an object that can be passed into `setChoices` for String or Number option with localized names.
110
+ *
111
+ * @param key The i18next key for the name of the select option name.
112
+ * @param options The additional Select Menu options. This should _at least_ include the `value` key.
113
+ * @returns An object with anything provided through {@link createLocalizedChoice.options} with `name` and `name_localizations` added.
114
+ *
115
+ * @example
116
+ * ```typescript
117
+ * export class TypeCommand extends Command {
118
+ * public override registerApplicationCommands(registry: ChatInputCommand.Registry) {
119
+ * registry.registerChatInputCommand((builder) =>
120
+ * applyLocalizedBuilder(builder, 'commands/names:type').addStringOption((option) =>
121
+ * applyLocalizedBuilder(option, 'commands/options:type')
122
+ * .setRequired(true)
123
+ * .setChoices(
124
+ * createLocalizedChoice('selects/pokemon:type-grass', { value: 'grass' }),
125
+ * createLocalizedChoice('selects/pokemon:type-water', { value: 'water' }),
126
+ * createLocalizedChoice('selects/pokemon:type-fire', { value: 'fire' }),
127
+ * createLocalizedChoice('selects/pokemon:type-electric', { value: 'electric' })
128
+ * )
129
+ * )
130
+ * );
131
+ * }
132
+ * }
133
+ * ```
134
+ */
135
+ export declare function createLocalizedChoice<ValueType = string | number>(key: TFunctionKeys, options: Omit<APIApplicationCommandOptionChoice<ValueType>, 'name' | 'name_localizations'>): APIApplicationCommandOptionChoice<ValueType>;
33
136
  //# sourceMappingURL=functions.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"functions.d.ts","sourceRoot":"","sources":["../../src/lib/functions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEzD,OAAO,KAAK,EAAE,SAAS,EAAE,aAAa,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnF,OAAO,KAAK,EAA+B,MAAM,EAAE,MAAM,SAAS,CAAC;AAEnE;;;;;;;;;;;GAWG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CA6B7D;AAED;;;;;GAKG;AACH,wBAAsB,MAAM,CAAC,MAAM,EAAE,MAAM,wCAE1C;AAED;;;;;;;GAOG;AACH,wBAAsB,UAAU,CAC/B,OAAO,SAAS,eAAe,GAAG,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S,eAAe,EAAE,OAAO,EAAE,CAAC,EAAE,GAAG,EAAE,aAAa,KAGlG;AAED;;;;;GAKG;AACH,wBAAgB,gCAAgC,CAAC,CAAC,SAAS,sBAAsB,EAAE,OAAO,EAAE,CAAC,EAAE,GAAG,EAAE,aAAa,KAGhH;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmDG;AACH,wBAAgB,qBAAqB,CAAC,CAAC,SAAS,6BAA6B,EAC5E,OAAO,EAAE,CAAC,EACV,GAAG,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,aAAa,EAAE,WAAW,EAAE,aAAa,CAAC,GAC3E,CAAC,CAQH;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,qBAAqB,CAAC,SAAS,GAAG,MAAM,GAAG,MAAM,EAChE,GAAG,EAAE,aAAa,EAClB,OAAO,EAAE,IAAI,CAAC,iCAAiC,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,oBAAoB,CAAC,GACxF,iCAAiC,CAAC,SAAS,CAAC,CAQ9C"}
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.resolveKey = exports.fetchT = exports.fetchLanguage = void 0;
3
+ exports.createLocalizedChoice = exports.applyLocalizedBuilder = exports.applyDescriptionLocalizedBuilder = exports.applyNameLocalizedBuilder = exports.getLocalizedData = exports.resolveKey = exports.fetchT = exports.fetchLanguage = void 0;
4
4
  const pieces_1 = require("@sapphire/pieces");
5
+ const utilities_1 = require("@sapphire/utilities");
6
+ const v10_1 = require("discord-api-types/v10");
5
7
  const discord_js_1 = require("discord.js");
6
8
  /**
7
9
  * Retrieves the language name for a specific target, using {@link InternationalizationHandler.fetchLanguage}.
@@ -71,4 +73,165 @@ async function resolveLanguage(context) {
71
73
  const lang = await pieces_1.container.i18n.fetchLanguage(context);
72
74
  return lang ?? context.guild?.preferredLocale ?? pieces_1.container.i18n.options.defaultName ?? 'en-US';
73
75
  }
76
+ const supportedLanguages = new Set(Object.values(v10_1.Locale));
77
+ function isSupportedDiscordLocale(language) {
78
+ return supportedLanguages.has(language);
79
+ }
80
+ const getLocales = (0, utilities_1.lazy)(() => {
81
+ const locales = new Map(pieces_1.container.i18n.languages);
82
+ for (const [locale] of locales) {
83
+ if (!isSupportedDiscordLocale(locale)) {
84
+ process.emitWarning('Unsupported Discord locale', {
85
+ code: 'UNSUPPORTED_LOCALE',
86
+ detail: `'${locale}' needs to be one of: ${[...locales.keys()]}`
87
+ });
88
+ locales.delete(locale);
89
+ }
90
+ continue;
91
+ }
92
+ return locales;
93
+ });
94
+ const getDefaultT = (0, utilities_1.lazy)(() => {
95
+ const defaultLocale = pieces_1.container.i18n.options.defaultName ?? 'en-US';
96
+ if (!isSupportedDiscordLocale(defaultLocale)) {
97
+ throw new TypeError(`Unsupported Discord locale found:\n'${defaultLocale}' is not within the list of ${[...supportedLanguages]}`);
98
+ }
99
+ const defaultT = getLocales().get(defaultLocale);
100
+ if (defaultT) {
101
+ return defaultT;
102
+ }
103
+ throw new TypeError(`Could not find ${defaultLocale}`);
104
+ });
105
+ /**
106
+ * Gets the value and the localizations from a language key.
107
+ * @param key The key to get the localizations from.
108
+ * @returns The retrieved data.
109
+ * @remarks This should be called **strictly** after loading the locales.
110
+ */
111
+ function getLocalizedData(key) {
112
+ const locales = getLocales();
113
+ const defaultT = getDefaultT();
114
+ return {
115
+ value: defaultT(key),
116
+ localizations: Object.fromEntries(Array.from(locales, ([locale, t]) => [locale, t(key)]))
117
+ };
118
+ }
119
+ exports.getLocalizedData = getLocalizedData;
120
+ /**
121
+ * Applies the localized names on the builder, calling `setName` and `setNameLocalizations`.
122
+ * @param builder The builder to apply the localizations to.
123
+ * @param key The key to get the localizations from.
124
+ * @returns The updated builder.
125
+ */
126
+ function applyNameLocalizedBuilder(builder, key) {
127
+ const result = getLocalizedData(key);
128
+ return builder.setName(result.value).setNameLocalizations(result.localizations);
129
+ }
130
+ exports.applyNameLocalizedBuilder = applyNameLocalizedBuilder;
131
+ /**
132
+ * Applies the localized descriptions on the builder, calling `setDescription` and `setDescriptionLocalizations`.
133
+ * @param builder The builder to apply the localizations to.
134
+ * @param key The key to get the localizations from.
135
+ * @returns The updated builder.
136
+ */
137
+ function applyDescriptionLocalizedBuilder(builder, key) {
138
+ const result = getLocalizedData(key);
139
+ return builder.setDescription(result.value).setDescriptionLocalizations(result.localizations);
140
+ }
141
+ exports.applyDescriptionLocalizedBuilder = applyDescriptionLocalizedBuilder;
142
+ /**
143
+ * Applies the localized names and descriptions on the builder, calling {@link applyNameLocalizedBuilder} and
144
+ * {@link applyDescriptionLocalizedBuilder}.
145
+ *
146
+ * @param builder The builder to apply the localizations to.
147
+ *
148
+ * @param params The root key or the key for the name and description keys.
149
+ * This needs to be either 1 or 2 parameters.
150
+ * See examples below for more information.
151
+ *
152
+ * @returns The updated builder. You can chain subsequent builder methods on this.
153
+ *
154
+ * @remarks If only 2 parameters were passed, then this function will automatically append `Name` and `Description`
155
+ * to the root-key (wherein `root-key` is second parameter in the function, after `builder`)
156
+ * passed through the second parameter.
157
+ *
158
+ * For example given `applyLocalizedBuilder(builder, 'userinfo')` the localized options will use the i18next keys
159
+ * `userinfoName` and `userinfoDescription`.
160
+ *
161
+ * In the following example we provide all parameters and add a User Option
162
+ * `applyLocalizedBuilder` needs either
163
+ * @example
164
+ * ```typescript
165
+ * class UserInfoCommand extends Command {
166
+ * public registerApplicationCommands(registry: ChatInputCommand.Registry) {
167
+ * registry.registerChatInputCommand(
168
+ * (builder) =>
169
+ * applyLocalizedBuilder(builder, 'commands/names:userinfo', 'commands/descriptions:userinfo')
170
+ * .addUserOption(
171
+ * (input) => applyLocalizedBuilder(input, 'commands/options:userinfo-name', 'commands/options:userinfo-description').setRequired(true)
172
+ * )
173
+ * );
174
+ * }
175
+ * }
176
+ * ```
177
+ *
178
+ * In the following example we provide single root keys which means `Name` and `Description` get appended as mentioned above.
179
+ * @example
180
+ * ```typescript
181
+ * class UserInfoCommand extends Command {
182
+ * public registerApplicationCommands(registry: ChatInputCommand.Registry) {
183
+ * registry.registerChatInputCommand(
184
+ * (builder) =>
185
+ * applyLocalizedBuilder(builder, 'commands:userinfo')
186
+ * .addUserOption(
187
+ * (input) => applyLocalizedBuilder(input, 'options:userinfo').setRequired(true)
188
+ * )
189
+ * );
190
+ * }
191
+ * }
192
+ * ```
193
+ */
194
+ function applyLocalizedBuilder(builder, ...params) {
195
+ const [localeName, localeDescription] = params.length === 1 ? [`${params[0]}Name`, `${params[0]}Description`] : params;
196
+ applyNameLocalizedBuilder(builder, localeName);
197
+ applyDescriptionLocalizedBuilder(builder, localeDescription);
198
+ return builder;
199
+ }
200
+ exports.applyLocalizedBuilder = applyLocalizedBuilder;
201
+ /**
202
+ * Constructs an object that can be passed into `setChoices` for String or Number option with localized names.
203
+ *
204
+ * @param key The i18next key for the name of the select option name.
205
+ * @param options The additional Select Menu options. This should _at least_ include the `value` key.
206
+ * @returns An object with anything provided through {@link createLocalizedChoice.options} with `name` and `name_localizations` added.
207
+ *
208
+ * @example
209
+ * ```typescript
210
+ * export class TypeCommand extends Command {
211
+ * public override registerApplicationCommands(registry: ChatInputCommand.Registry) {
212
+ * registry.registerChatInputCommand((builder) =>
213
+ * applyLocalizedBuilder(builder, 'commands/names:type').addStringOption((option) =>
214
+ * applyLocalizedBuilder(option, 'commands/options:type')
215
+ * .setRequired(true)
216
+ * .setChoices(
217
+ * createLocalizedChoice('selects/pokemon:type-grass', { value: 'grass' }),
218
+ * createLocalizedChoice('selects/pokemon:type-water', { value: 'water' }),
219
+ * createLocalizedChoice('selects/pokemon:type-fire', { value: 'fire' }),
220
+ * createLocalizedChoice('selects/pokemon:type-electric', { value: 'electric' })
221
+ * )
222
+ * )
223
+ * );
224
+ * }
225
+ * }
226
+ * ```
227
+ */
228
+ function createLocalizedChoice(key, options) {
229
+ const result = getLocalizedData(key);
230
+ return {
231
+ ...options,
232
+ name: result.value,
233
+ name_localizations: result.localizations
234
+ };
235
+ }
236
+ exports.createLocalizedChoice = createLocalizedChoice;
74
237
  //# sourceMappingURL=functions.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"functions.js","sourceRoot":"","sources":["../../src/lib/functions.ts"],"names":[],"mappings":";;;AAAA,6CAA6C;AAE7C,2CAAiG;AAIjG;;;;;;;;;;;GAWG;AACH,SAAgB,aAAa,CAAC,MAAc;IAC3C,uBAAuB;IACvB,IAAI,MAAM,YAAY,mCAAsB,IAAI,MAAM,YAAY,wCAA2B,EAAE;QAC9F,OAAO,eAAe,CAAC;YACtB,IAAI,EAAE,MAAM,CAAC,IAAI;YACjB,OAAO,EAAE,MAAM,CAAC,OAAO;YACvB,KAAK,EAAE,MAAM,CAAC,KAAK;YACnB,sBAAsB,EAAE,MAAM,CAAC,WAAW;YAC1C,iBAAiB,EAAE,MAAM,CAAC,MAAM;SAChC,CAAC,CAAC;KACH;IAED,kBAAkB;IAClB,IAAI,MAAM,YAAY,oBAAO,EAAE;QAC9B,OAAO,eAAe,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,OAAO,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC;KAC9F;IAED,gBAAgB;IAChB,IAAI,MAAM,YAAY,kBAAK,EAAE;QAC5B,OAAO,eAAe,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC;KACrE;IAED,oBAAoB;IACpB,IAAI,MAAM,CAAC,IAAI,KAAK,IAAI,EAAE;QACzB,OAAO,eAAe,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;KACrE;IAED,4BAA4B;IAC5B,OAAO,eAAe,CAAC,EAAE,IAAI,EAAE,IAAI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AAM,CAAC,KAAK,CAAC,CAAC,2BAA2B,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC;AAC/F,CAAC;AAHD,4EAGC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmDG;AACH,SAAgB,qBAAqB,CACpC,OAAU,EACV,GAAG,MAA0E;IAE7E,MAAM,CAAC,UAAU,EAAE,iBAAiB,CAAC,GACpC,MAAM,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,MAAuB,EAAE,GAAG,MAAM,CAAC,CAAC,CAAC,aAA8B,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;IAElH,yBAAyB,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;IAC/C,gCAAgC,CAAC,OAAO,EAAE,iBAAiB,CAAC,CAAC;IAE7D,OAAO,OAAO,CAAC;AAChB,CAAC;AAXD,sDAWC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,SAAgB,qBAAqB,CACpC,GAAkB,EAClB,OAA0F;IAE1F,MAAM,MAAM,GAAG,gBAAgB,CAAC,GAAG,CAAC,CAAC;IAErC,OAAO;QACN,GAAG,OAAO;QACV,IAAI,EAAE,MAAM,CAAC,KAAK;QAClB,kBAAkB,EAAE,MAAM,CAAC,aAAa;KACxC,CAAC;AACH,CAAC;AAXD,sDAWC"}
@@ -1,6 +1,7 @@
1
1
  import type { Awaitable } from '@sapphire/utilities';
2
2
  import type { Backend } from '@skyra/i18next-backend';
3
3
  import type { WatchOptions } from 'chokidar';
4
+ import type { LocalizationMap } from 'discord-api-types/v10';
4
5
  import type { BaseCommandInteraction, Guild, Interaction, Message, MessageComponentInteraction, StageChannel, StoreChannel, User, VoiceChannel } from 'discord.js';
5
6
  import type { InitOptions } from 'i18next';
6
7
  /**
@@ -121,6 +122,19 @@ export interface I18nextFormatters {
121
122
  name: string;
122
123
  format(value: any, lng: string | undefined, options: any): string;
123
124
  }
125
+ export interface LocalizedData {
126
+ value: string;
127
+ localizations: LocalizationMap;
128
+ }
129
+ export interface BuilderWithName {
130
+ setName(name: string): this;
131
+ setNameLocalizations(localizedNames: LocalizationMap | null): this;
132
+ }
133
+ export interface BuilderWithDescription {
134
+ setDescription(description: string): this;
135
+ setDescriptionLocalizations(localizedDescriptions: LocalizationMap | null): this;
136
+ }
137
+ export declare type BuilderWithNameAndDescription = BuilderWithName & BuilderWithDescription;
124
138
  export declare type ChannelTarget = Message | DiscordChannel;
125
139
  export declare type Target = BaseCommandInteraction | ChannelTarget | Guild | MessageComponentInteraction;
126
140
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/lib/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,KAAK,EACX,sBAAsB,EACtB,KAAK,EACL,WAAW,EACX,OAAO,EACP,2BAA2B,EAC3B,YAAY,EACZ,YAAY,EACZ,IAAI,EACJ,YAAY,EACZ,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAE3C;;;GAGG;AACH,MAAM,WAAW,UAAU;IAC1B;;;OAGG;IACH,OAAO,EAAE,OAAO,CAAC;IAEjB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAE9B;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAE/B;;OAEG;IACH,OAAO,CAAC,EAAE,YAAY,CAAC;CACvB;AAED;;;;GAIG;AACH,oBAAY,cAAc,CAAC,CAAC,SAAS,WAAW,IAAI,CAAC,UAAU,EAAE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AAE,GAAG,EAAE,GAAG,EAAE,MAAM,GAAG,SAAS,EAAE,OAAO,EAAE,GAAG,GAAG,MAAM,CAAC;CAClE;AAED,MAAM,WAAW,aAAa;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,aAAa,EAAE,eAAe,CAAC;CAC/B;AAED,MAAM,WAAW,eAAe;IAC/B,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,oBAAoB,CAAC,cAAc,EAAE,eAAe,GAAG,IAAI,GAAG,IAAI,CAAC;CACnE;AAED,MAAM,WAAW,sBAAsB;IACtC,cAAc,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1C,2BAA2B,CAAC,qBAAqB,EAAE,eAAe,GAAG,IAAI,GAAG,IAAI,CAAC;CACjF;AAED,oBAAY,6BAA6B,GAAG,eAAe,GAAG,sBAAsB,CAAC;AACrF,oBAAY,aAAa,GAAG,OAAO,GAAG,cAAc,CAAC;AACrD,oBAAY,MAAM,GAAG,sBAAsB,GAAG,aAAa,GAAG,KAAK,GAAG,2BAA2B,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sapphire/plugin-i18next",
3
- "version": "3.0.2-next.f0bab02.0",
3
+ "version": "3.1.0",
4
4
  "description": "Plugin for @sapphire/framework to support i18next.",
5
5
  "author": "@sapphire",
6
6
  "license": "MIT",
@@ -80,7 +80,7 @@
80
80
  "devDependencies": {
81
81
  "@favware/cliff-jumper": "^1.8.8",
82
82
  "gen-esm-wrapper": "^1.1.3",
83
- "typedoc": "^0.23.15",
83
+ "typedoc": "^0.23.16",
84
84
  "typedoc-json-parser": "^6.0.0",
85
85
  "typescript": "^4.8.4"
86
86
  }