Skip to content

Commit

Permalink
add force english toggle
Browse files Browse the repository at this point in the history
  • Loading branch information
3vorp committed Oct 9, 2023
1 parent 1dc514e commit a199027
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 11 deletions.
8 changes: 4 additions & 4 deletions src/client/interaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,23 @@ export type PermissionType = "manager" | "dev" | "moderator" | "council";
declare module "discord.js" {
interface ChatInputCommandInteraction {
client: ExtendedClient; // so you don't have to cast it every time
strings(): AllStrings;
strings(forceEnglish?: boolean): AllStrings;
hasPermission(type: PermissionType): boolean;
}

interface ButtonInteraction {
client: ExtendedClient;
strings(): AllStrings;
strings(forceEnglish?: boolean): AllStrings;
}

interface StringSelectMenuInteraction {
client: ExtendedClient;
strings(): AllStrings;
strings(forceEnglish?: boolean): AllStrings;
}

interface ModalSubmitInteraction {
client: ExtendedClient;
strings(): AllStrings;
strings(forceEnglish?: boolean): AllStrings;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/client/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ declare module "discord.js" {
client: ExtendedClient; // so you don't have to cast it every time
/** @param hasAuthorID whether to search for an author id in the footer or the interaction owner */
deleteButton(hasAuthorID?: boolean): Promise<Message>;
strings(): AllStrings;
strings(forceEnglish?: boolean): AllStrings;
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/helpers/images/palette.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,10 @@ export async function paletteTooBig(
| StringSelectMenuInteraction
| Message,
) {
// force english if it's a message
return warnUser(
interaction,
interaction.strings().command.images.too_big.replace("%ACTION%", "take the palette of"),
interaction.strings().command.images.max_size,
interaction.strings(interaction instanceof Message).command.images.too_big.replace("%ACTION%", "take the palette of"),
interaction.strings(interaction instanceof Message).command.images.max_size,
);
}
5 changes: 3 additions & 2 deletions src/helpers/images/tile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,10 @@ export async function tileTooBig(
| StringSelectMenuInteraction
| Message,
) {
// force english if it's a message
return warnUser(
interaction,
interaction.strings().command.images.too_big.replace("%ACTION%", "be tiled"),
interaction.strings().command.images.max_size,
interaction.strings(interaction instanceof Message).command.images.too_big.replace("%ACTION%", "be tiled"),
interaction.strings(interaction instanceof Message).command.images.max_size,
);
}
4 changes: 2 additions & 2 deletions src/helpers/strings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export type AllStrings = typeof baseTranslations;
* @author Evorp
* @returns string output in correct language
*/
export function strings(): AllStrings {
export function strings(forceEnglish = false): AllStrings {
const countryCode = this.locale;
let lang: AllStrings;
// load all english strings into one lang object
Expand All @@ -20,7 +20,7 @@ export function strings(): AllStrings {
...require(`@/lang/en-US/${json}.json`), // fallback
};

if (countryCode == "en-GB" || countryCode == "en-US") return lang;
if (countryCode == "en-GB" || countryCode == "en-US" || forceEnglish) return lang;

// because the fallback is already IN ENGLISH
for (const json of JSONFiles)
Expand Down

0 comments on commit a199027

Please sign in to comment.