refactor(commands): Use Locale over LocaleString (#10624)

* refactor: use `Locale`

* test: update `LocaleString` tests
This commit is contained in:
Jiralite
2024-11-28 17:33:40 +00:00
committed by GitHub
parent 2b0944a92f
commit 9d62ff57d6
4 changed files with 49 additions and 35 deletions

View File

@@ -1,4 +1,4 @@
import type { LocaleString, RESTPostAPIApplicationCommandsJSONBody } from 'discord-api-types/v10';
import type { Locale, RESTPostAPIApplicationCommandsJSONBody } from 'discord-api-types/v10';
export interface SharedNameData
extends Partial<Pick<RESTPostAPIApplicationCommandsJSONBody, 'name_localizations' | 'name'>> {}
@@ -25,7 +25,7 @@ export class SharedName {
* @param locale - The locale to set
* @param localizedName - The localized name for the given `locale`
*/
public setNameLocalization(locale: LocaleString, localizedName: string) {
public setNameLocalization(locale: Locale, localizedName: string) {
this.data.name_localizations ??= {};
this.data.name_localizations[locale] = localizedName;
@@ -37,7 +37,7 @@ export class SharedName {
*
* @param locale - The locale to clear
*/
public clearNameLocalization(locale: LocaleString) {
public clearNameLocalization(locale: Locale) {
this.data.name_localizations ??= {};
this.data.name_localizations[locale] = undefined;
@@ -49,7 +49,7 @@ export class SharedName {
*
* @param localizedNames - The object of localized names to set
*/
public setNameLocalizations(localizedNames: Partial<Record<LocaleString, string>>) {
public setNameLocalizations(localizedNames: Partial<Record<Locale, string>>) {
this.data.name_localizations = structuredClone(localizedNames);
return this;
}

View File

@@ -1,4 +1,4 @@
import type { APIApplicationCommand, LocaleString } from 'discord-api-types/v10';
import type { APIApplicationCommand, Locale } from 'discord-api-types/v10';
import type { SharedNameData } from './SharedName.js';
import { SharedName } from './SharedName.js';
@@ -28,7 +28,7 @@ export class SharedNameAndDescription extends SharedName {
* @param locale - The locale to set
* @param localizedDescription - The localized description for the given `locale`
*/
public setDescriptionLocalization(locale: LocaleString, localizedDescription: string) {
public setDescriptionLocalization(locale: Locale, localizedDescription: string) {
this.data.description_localizations ??= {};
this.data.description_localizations[locale] = localizedDescription;
@@ -40,7 +40,7 @@ export class SharedNameAndDescription extends SharedName {
*
* @param locale - The locale to clear
*/
public clearDescriptionLocalization(locale: LocaleString) {
public clearDescriptionLocalization(locale: Locale) {
this.data.description_localizations ??= {};
this.data.description_localizations[locale] = undefined;
@@ -52,7 +52,7 @@ export class SharedNameAndDescription extends SharedName {
*
* @param localizedDescriptions - The object of localized descriptions to set
*/
public setDescriptionLocalizations(localizedDescriptions: Partial<Record<LocaleString, string>>) {
public setDescriptionLocalizations(localizedDescriptions: Partial<Record<Locale, string>>) {
this.data.description_localizations = structuredClone(localizedDescriptions);
return this;
}