feat: partially translated /about

This commit is contained in:
TrèsAbhi committed 2024-03-05 09:59:46 -06:00
1 parent 8e35e0d6d9
commit db7c865c76
5 files changed
+104 -43

No files matched your search

@@ -0,0 +1,48 @@
import { Locale, SlashCommandBuilder } from 'discord.js';
import { translator } from '../localization/translator';
import { localizationObject } from './localizationObject';
interface CreateLocalizedCommandSubcommand {
subcommand: string;
}
export async function createLocalizedCommand(
command: string,
subcommands?: CreateLocalizedCommandSubcommand[],
) {
const { translate } = await translator(Locale.EnglishUS);
const slashCommand = new SlashCommandBuilder()
.setName(command)
.setNameLocalizations(await localizationObject(`bot.commands.${command}`))
.setDescription(translate(`bot.commands.${command}.description`))
.setDescriptionLocalizations(
await localizationObject(`bot.commands.${command}.description`),
);
if (subcommands) {
await Promise.all(
subcommands.map(async ({ subcommand }) => {
const subcommandNameLocalizations = await localizationObject(
`bot.commands.${command}.subcommands.${subcommand}`,
);
const subcommandDescriptionLocalizations = await localizationObject(
`bot.commands.${command}.subcommands.${subcommand}.description`,
);
slashCommand.addSubcommand((option) =>
option
.setName(subcommand)
.setNameLocalizations(subcommandNameLocalizations)
.setDescription(
translate(
`bot.commands.${command}.subcommands.${subcommand}.description`,
),
)
.setDescriptionLocalizations(subcommandDescriptionLocalizations),
);
}),
);
}
return slashCommand;
}