Skip to content

Commit

Permalink
feat(Locales): add locale string enum (#297)
Browse files Browse the repository at this point in the history
  • Loading branch information
suneettipirneni committed Jan 18, 2022
1 parent 03b8d3f commit b07d5a0
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 8 deletions.
5 changes: 3 additions & 2 deletions deno/payloads/v8/_interactions/base.ts
Expand Up @@ -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
Expand Down Expand Up @@ -89,11 +90,11 @@ export interface APIBaseInteraction<Type extends InteractionType, Data> {
/**
* 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<Original extends APIBaseInteraction<InteractionType, unknown>> = Omit<
Expand Down
5 changes: 3 additions & 2 deletions deno/payloads/v9/_interactions/base.ts
Expand Up @@ -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
Expand Down Expand Up @@ -89,11 +90,11 @@ export interface APIBaseInteraction<Type extends InteractionType, Data> {
/**
* 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<Original extends APIBaseInteraction<InteractionType, unknown>> = Omit<
Expand Down
35 changes: 35 additions & 0 deletions deno/rest/common.ts
Expand Up @@ -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}`;
5 changes: 3 additions & 2 deletions payloads/v8/_interactions/base.ts
Expand Up @@ -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
Expand Down Expand Up @@ -89,11 +90,11 @@ export interface APIBaseInteraction<Type extends InteractionType, Data> {
/**
* 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<Original extends APIBaseInteraction<InteractionType, unknown>> = Omit<
Expand Down
5 changes: 3 additions & 2 deletions payloads/v9/_interactions/base.ts
Expand Up @@ -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
Expand Down Expand Up @@ -89,11 +90,11 @@ export interface APIBaseInteraction<Type extends InteractionType, Data> {
/**
* 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<Original extends APIBaseInteraction<InteractionType, unknown>> = Omit<
Expand Down
35 changes: 35 additions & 0 deletions rest/common.ts
Expand Up @@ -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}`;

0 comments on commit b07d5a0

Please sign in to comment.