Skip to content

Commit 6dcf0bd

Browse files
authoredApr 21, 2022
docs: fix and improve localization docs (v13 backport) (#7807)
1 parent 816936e commit 6dcf0bd

File tree

4 files changed

+58
-23
lines changed

4 files changed

+58
-23
lines changed
 

‎src/structures/ApplicationCommand.js

+19-15
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class ApplicationCommand extends Base {
6565
if ('name_localizations' in data) {
6666
/**
6767
* The name localizations for this command
68-
* @type {?Object<string, string>}
68+
* @type {?Object<Locale, string>}
6969
*/
7070
this.nameLocalizations = data.name_localizations;
7171
} else {
@@ -75,7 +75,7 @@ class ApplicationCommand extends Base {
7575
if ('name_localized' in data) {
7676
/**
7777
* The localized name for this command
78-
* @type {?Object<string, string>}
78+
* @type {?string}
7979
*/
8080
this.nameLocalized = data.name_localized;
8181
} else {
@@ -93,7 +93,7 @@ class ApplicationCommand extends Base {
9393
if ('description_localizations' in data) {
9494
/**
9595
* The description localizations for this command
96-
* @type {?string}
96+
* @type {?Object<Locale, string>}
9797
*/
9898
this.descriptionLocalizations = data.description_localizations;
9999
} else {
@@ -168,9 +168,9 @@ class ApplicationCommand extends Base {
168168
* Data for creating or editing an application command.
169169
* @typedef {Object} ApplicationCommandData
170170
* @property {string} name The name of the command
171-
* @property {Object<string, string>} [nameLocalizations] The localizations for the command name
171+
* @property {Object<Locale, string>} [nameLocalizations] The localizations for the command name
172172
* @property {string} description The description of the command
173-
* @property {Object<string, string>} [descriptionLocalizations] The localizations for the command description
173+
* @property {Object<Locale, string>} [descriptionLocalizations] The localizations for the command description
174174
* @property {ApplicationCommandType} [type] The type of the command
175175
* @property {ApplicationCommandOptionData[]} [options] Options for the command
176176
* @property {boolean} [defaultPermission] Whether the command is enabled by default when the app is added to a guild
@@ -185,9 +185,9 @@ class ApplicationCommand extends Base {
185185
* @typedef {Object} ApplicationCommandOptionData
186186
* @property {ApplicationCommandOptionType|number} type The type of the option
187187
* @property {string} name The name of the option
188-
* @property {Object<string, string>} [nameLocalizations] The name localizations for the option
188+
* @property {Object<Locale, string>} [nameLocalizations] The name localizations for the option
189189
* @property {string} description The description of the option
190-
* @property {Object<string, string>} [descriptionLocalizations] The description localizations for the option
190+
* @property {Object<Locale, string>} [descriptionLocalizations] The description localizations for the option
191191
* @property {boolean} [autocomplete] Whether the option is an autocomplete option
192192
* @property {boolean} [required] Whether the option is required
193193
* @property {ApplicationCommandOptionChoiceData[]} [choices] The choices of the option for the user to pick from
@@ -201,15 +201,10 @@ class ApplicationCommand extends Base {
201201
/**
202202
* @typedef {Object} ApplicationCommandOptionChoiceData
203203
* @property {string} name The name of the choice
204-
* @property {Object<string, string>} [nameLocalizations] The localized names for this choice
204+
* @property {Object<Locale, string>} [nameLocalizations] The localized names for this choice
205205
* @property {string|number} value The value of the choice
206206
*/
207207

208-
/**
209-
* @typedef {ApplicationCommandOptionChoiceData} ApplicationCommandOptionChoice
210-
* @property {string} [nameLocalized] The localized name for this choice
211-
*/
212-
213208
/**
214209
* Edits this application command.
215210
* @param {ApplicationCommandData} data The data to update the command with
@@ -237,7 +232,7 @@ class ApplicationCommand extends Base {
237232

238233
/**
239234
* Edits the localized names of this ApplicationCommand
240-
* @param {Object<string, string>} nameLocalizations The new localized names for the command
235+
* @param {Object<Locale, string>} nameLocalizations The new localized names for the command
241236
* @returns {Promise<ApplicationCommand>}
242237
* @example
243238
* // Edit the name localizations of this command
@@ -263,7 +258,7 @@ class ApplicationCommand extends Base {
263258

264259
/**
265260
* Edits the localized descriptions of this ApplicationCommand
266-
* @param {Object<string, string>} descriptionLocalizations The new localized descriptions for the command
261+
* @param {Object<Locale, string>} descriptionLocalizations The new localized descriptions for the command
267262
* @returns {Promise<ApplicationCommand>}
268263
* @example
269264
* // Edit the description localizations of this command
@@ -449,6 +444,15 @@ class ApplicationCommand extends Base {
449444
* @property {number} [maxValue] The maximum value for an `INTEGER` or `NUMBER` option
450445
*/
451446

447+
/**
448+
* A choice for an application command option.
449+
* @typedef {Object} ApplicationCommandOptionChoice
450+
* @property {string} name The name of the choice
451+
* @property {?string} nameLocalized The localized name of the choice in the provided locale, if any
452+
* @property {?Object<string, string>} [nameLocalizations] The localized names for this choice
453+
* @property {string|number} value The value of the choice
454+
*/
455+
452456
/**
453457
* Transforms an {@link ApplicationCommandOptionData} object into something that can be used with the API.
454458
* @param {ApplicationCommandOptionData|ApplicationCommandOption} option The option to transform

‎src/structures/Guild.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ class Guild extends AnonymousGuild {
411411
if ('preferred_locale' in data) {
412412
/**
413413
* The preferred locale of the guild, defaults to `en-US`
414-
* @type {string}
414+
* @type {Locale}
415415
* @see {@link https://discord.com/developers/docs/reference#locales}
416416
*/
417417
this.preferredLocale = data.preferred_locale;

‎src/structures/Interaction.js

+38-3
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,50 @@ class Interaction extends Base {
7676
this.memberPermissions = data.member?.permissions ? new Permissions(data.member.permissions).freeze() : null;
7777

7878
/**
79-
* The locale of the user who invoked this interaction
80-
* @type {string}
79+
* A Discord locale string, possible values are:
80+
* * en-US (English, US)
81+
* * en-GB (English, UK)
82+
* * bg (Bulgarian)
83+
* * zh-CN (Chinese, China)
84+
* * zh-TW (Chinese, Taiwan)
85+
* * hr (Croatian)
86+
* * cs (Czech)
87+
* * da (Danish)
88+
* * nl (Dutch)
89+
* * fi (Finnish)
90+
* * fr (French)
91+
* * de (German)
92+
* * el (Greek)
93+
* * hi (Hindi)
94+
* * hu (Hungarian)
95+
* * it (Italian)
96+
* * ja (Japanese)
97+
* * ko (Korean)
98+
* * lt (Lithuanian)
99+
* * no (Norwegian)
100+
* * pl (Polish)
101+
* * pt-BR (Portuguese, Brazilian)
102+
* * ro (Romanian, Romania)
103+
* * ru (Russian)
104+
* * es-ES (Spanish)
105+
* * sv-SE (Swedish)
106+
* * th (Thai)
107+
* * tr (Turkish)
108+
* * uk (Ukrainian)
109+
* * vi (Vietnamese)
81110
* @see {@link https://discord.com/developers/docs/reference#locales}
111+
* @typedef {string} Locale
112+
*/
113+
114+
/**
115+
* The locale of the user who invoked this interaction
116+
* @type {Locale}
82117
*/
83118
this.locale = data.locale;
84119

85120
/**
86121
* The preferred locale from the guild this interaction was sent in
87-
* @type {?string}
122+
* @type {?Locale}
88123
*/
89124
this.guildLocale = data.guild_locale ?? null;
90125
}

‎typings/index.d.ts

-4
Original file line numberDiff line numberDiff line change
@@ -3923,10 +3923,6 @@ export interface ApplicationCommandOptionChoiceData {
39233923
value: string | number;
39243924
}
39253925

3926-
export interface ApplicationCommandOptionChoice extends ApplicationCommandOptionChoiceData {
3927-
nameLocalized?: string;
3928-
}
3929-
39303926
export type ApplicationCommandType = keyof typeof ApplicationCommandTypes;
39313927

39323928
export type ApplicationCommandOptionType = keyof typeof ApplicationCommandOptionTypes;

0 commit comments

Comments
 (0)
Please sign in to comment.