From b07d5a0c2273b6b51b44542b638a768c36d0f184 Mon Sep 17 00:00:00 2001 From: Suneet Tipirneni <77477100+suneettipirneni@users.noreply.github.com> Date: Tue, 18 Jan 2022 17:36:49 -0500 Subject: [PATCH] feat(Locales): add locale string enum (#297) --- deno/payloads/v8/_interactions/base.ts | 5 ++-- deno/payloads/v9/_interactions/base.ts | 5 ++-- deno/rest/common.ts | 35 ++++++++++++++++++++++++++ payloads/v8/_interactions/base.ts | 5 ++-- payloads/v9/_interactions/base.ts | 5 ++-- rest/common.ts | 35 ++++++++++++++++++++++++++ 6 files changed, 82 insertions(+), 8 deletions(-) diff --git a/deno/payloads/v8/_interactions/base.ts b/deno/payloads/v8/_interactions/base.ts index 5b8ea7897..d45a58923 100644 --- a/deno/payloads/v8/_interactions/base.ts +++ b/deno/payloads/v8/_interactions/base.ts @@ -3,6 +3,7 @@ import type { InteractionType } from './responses.ts'; import type { APIMessage } from '../channel.ts'; import type { APIGuildMember } from '../guild.ts'; import type { APIUser } from '../user.ts'; +import type { LocaleString } from '../../../v8.ts'; /** * https://discord.com/developers/docs/interactions/receiving-and-responding#message-interaction-object @@ -89,11 +90,11 @@ export interface APIBaseInteraction { /** * The selected language of the invoking user */ - locale: string; + locale: LocaleString; /** * The guild's preferred locale, if invoked in a guild */ - guild_locale?: string; + guild_locale?: LocaleString; } export type APIDMInteractionWrapper> = Omit< diff --git a/deno/payloads/v9/_interactions/base.ts b/deno/payloads/v9/_interactions/base.ts index 5b8ea7897..563e98460 100644 --- a/deno/payloads/v9/_interactions/base.ts +++ b/deno/payloads/v9/_interactions/base.ts @@ -3,6 +3,7 @@ import type { InteractionType } from './responses.ts'; import type { APIMessage } from '../channel.ts'; import type { APIGuildMember } from '../guild.ts'; import type { APIUser } from '../user.ts'; +import type { LocaleString } from '../../../v9.ts'; /** * https://discord.com/developers/docs/interactions/receiving-and-responding#message-interaction-object @@ -89,11 +90,11 @@ export interface APIBaseInteraction { /** * The selected language of the invoking user */ - locale: string; + locale: LocaleString; /** * The guild's preferred locale, if invoked in a guild */ - guild_locale?: string; + guild_locale?: LocaleString; } export type APIDMInteractionWrapper> = Omit< diff --git a/deno/rest/common.ts b/deno/rest/common.ts index 0af2bf83f..279f76906 100644 --- a/deno/rest/common.ts +++ b/deno/rest/common.ts @@ -208,3 +208,38 @@ export enum RESTJSONErrorCodes { FailedToCreateStageNeededForStageEvent = 180002, } + +export enum Locale { + EnglishUS = 'en-US', + EnglishGB = 'en-GB', + Bulgarian = 'bg', + ChineseCN = 'zh-CN', + ChineseTW = 'zh-TW', + Croatian = 'hr', + Czech = 'cs', + Danish = 'da', + Dutch = 'nl', + Finnish = 'fi', + French = 'fr', + German = 'de', + Greek = 'el', + Hindi = 'hi', + Hungarian = 'hu', + Italian = 'it', + Japanese = 'ja', + Korean = 'ko', + Lithuanian = 'lt', + Norwegian = 'no', + Polish = 'pl', + PortugueseBR = 'pt-BR', + Romanian = 'ro', + Russian = 'ru', + SpanishES = 'es-ES', + Swedish = 'sv-SE', + Thai = 'th', + Turkish = 'tr', + Ukrainian = 'uk', + Vietnamese = 'vi', +} + +export type LocaleString = `${Locale}`; diff --git a/payloads/v8/_interactions/base.ts b/payloads/v8/_interactions/base.ts index 170244055..2fa63f420 100644 --- a/payloads/v8/_interactions/base.ts +++ b/payloads/v8/_interactions/base.ts @@ -3,6 +3,7 @@ import type { InteractionType } from './responses'; import type { APIMessage } from '../channel'; import type { APIGuildMember } from '../guild'; import type { APIUser } from '../user'; +import type { LocaleString } from '../../../v8'; /** * https://discord.com/developers/docs/interactions/receiving-and-responding#message-interaction-object @@ -89,11 +90,11 @@ export interface APIBaseInteraction { /** * The selected language of the invoking user */ - locale: string; + locale: LocaleString; /** * The guild's preferred locale, if invoked in a guild */ - guild_locale?: string; + guild_locale?: LocaleString; } export type APIDMInteractionWrapper> = Omit< diff --git a/payloads/v9/_interactions/base.ts b/payloads/v9/_interactions/base.ts index 170244055..b870f2538 100644 --- a/payloads/v9/_interactions/base.ts +++ b/payloads/v9/_interactions/base.ts @@ -3,6 +3,7 @@ import type { InteractionType } from './responses'; import type { APIMessage } from '../channel'; import type { APIGuildMember } from '../guild'; import type { APIUser } from '../user'; +import type { LocaleString } from '../../../v9'; /** * https://discord.com/developers/docs/interactions/receiving-and-responding#message-interaction-object @@ -89,11 +90,11 @@ export interface APIBaseInteraction { /** * The selected language of the invoking user */ - locale: string; + locale: LocaleString; /** * The guild's preferred locale, if invoked in a guild */ - guild_locale?: string; + guild_locale?: LocaleString; } export type APIDMInteractionWrapper> = Omit< diff --git a/rest/common.ts b/rest/common.ts index c7479c6f3..48b74bcaf 100644 --- a/rest/common.ts +++ b/rest/common.ts @@ -208,3 +208,38 @@ export const enum RESTJSONErrorCodes { FailedToCreateStageNeededForStageEvent = 180002, } + +export const enum Locale { + EnglishUS = 'en-US', + EnglishGB = 'en-GB', + Bulgarian = 'bg', + ChineseCN = 'zh-CN', + ChineseTW = 'zh-TW', + Croatian = 'hr', + Czech = 'cs', + Danish = 'da', + Dutch = 'nl', + Finnish = 'fi', + French = 'fr', + German = 'de', + Greek = 'el', + Hindi = 'hi', + Hungarian = 'hu', + Italian = 'it', + Japanese = 'ja', + Korean = 'ko', + Lithuanian = 'lt', + Norwegian = 'no', + Polish = 'pl', + PortugueseBR = 'pt-BR', + Romanian = 'ro', + Russian = 'ru', + SpanishES = 'es-ES', + Swedish = 'sv-SE', + Thai = 'th', + Turkish = 'tr', + Ukrainian = 'uk', + Vietnamese = 'vi', +} + +export type LocaleString = `${Locale}`;