mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-22 19:19:52 +02:00
feat: some period translations
This commit is contained in:
1 parent
267f23cad8
commit
adad668157
24 files changed
+1309
-1216
No files matched your search
@@ -1,14 +1,27 @@
|
||||
import { Locale, SlashCommandBuilder } from 'discord.js';
|
||||
import {
|
||||
Locale,
|
||||
SlashCommandBuilder,
|
||||
SlashCommandSubcommandBuilder,
|
||||
SlashCommandSubcommandGroupBuilder,
|
||||
} from 'discord.js';
|
||||
import { translator } from '../localization/translator';
|
||||
import { localizationObject } from './localizationObject';
|
||||
|
||||
interface CreateLocalizedCommandSubcommand {
|
||||
subcommand: string;
|
||||
modify?: (option: SlashCommandSubcommandBuilder) => void;
|
||||
}
|
||||
|
||||
interface CreateLocalizedCommandSubcommandGroup {
|
||||
group: string;
|
||||
modify?: (option: SlashCommandSubcommandGroupBuilder) => void;
|
||||
}
|
||||
|
||||
export function createLocalizedCommand(
|
||||
command: string,
|
||||
subcommands?: CreateLocalizedCommandSubcommand[],
|
||||
sub?:
|
||||
| CreateLocalizedCommandSubcommand[]
|
||||
| CreateLocalizedCommandSubcommandGroup[],
|
||||
) {
|
||||
const { translate } = translator(Locale.EnglishUS);
|
||||
const slashCommand = new SlashCommandBuilder()
|
||||
@@ -19,26 +32,51 @@ export function createLocalizedCommand(
|
||||
localizationObject(`bot.commands.${command}.description`),
|
||||
);
|
||||
|
||||
if (subcommands) {
|
||||
subcommands.map(({ subcommand }) => {
|
||||
const subcommandNameLocalizations = localizationObject(
|
||||
`bot.commands.${command}.subcommands.${subcommand}`,
|
||||
);
|
||||
const subcommandDescriptionLocalizations = localizationObject(
|
||||
`bot.commands.${command}.subcommands.${subcommand}.description`,
|
||||
);
|
||||
if (sub) {
|
||||
sub.map((subItem) => {
|
||||
if ('subcommand' in subItem) {
|
||||
const subcommandNameLocalizations = localizationObject(
|
||||
`bot.commands.${command}.subcommands.${subItem.subcommand}`,
|
||||
);
|
||||
const subcommandDescriptionLocalizations = localizationObject(
|
||||
`bot.commands.${command}.subcommands.${subItem.subcommand}.description`,
|
||||
);
|
||||
|
||||
slashCommand.addSubcommand((option) =>
|
||||
option
|
||||
.setName(subcommand)
|
||||
.setNameLocalizations(subcommandNameLocalizations)
|
||||
.setDescription(
|
||||
translate(
|
||||
`bot.commands.${command}.subcommands.${subcommand}.description`,
|
||||
),
|
||||
)
|
||||
.setDescriptionLocalizations(subcommandDescriptionLocalizations),
|
||||
);
|
||||
slashCommand.addSubcommand((option) => {
|
||||
if (subItem.modify) subItem.modify(option);
|
||||
|
||||
return option
|
||||
.setName(subItem.subcommand)
|
||||
.setNameLocalizations(subcommandNameLocalizations)
|
||||
.setDescription(
|
||||
translate(
|
||||
`bot.commands.${command}.subcommands.${subItem.subcommand}.description`,
|
||||
),
|
||||
)
|
||||
.setDescriptionLocalizations(subcommandDescriptionLocalizations);
|
||||
});
|
||||
} else {
|
||||
const subcommandNameLocalizations = localizationObject(
|
||||
`bot.commands.${command}.groups.${subItem.group}`,
|
||||
);
|
||||
const subcommandDescriptionLocalizations = localizationObject(
|
||||
`bot.commands.${command}.groups.${subItem.group}.description`,
|
||||
);
|
||||
|
||||
slashCommand.addSubcommandGroup((option) => {
|
||||
if (subItem.modify) subItem.modify(option);
|
||||
|
||||
return option
|
||||
.setName(subItem.group)
|
||||
.setNameLocalizations(subcommandNameLocalizations)
|
||||
.setDescription(
|
||||
translate(
|
||||
`bot.commands.${command}.groups.${subItem.group}.description`,
|
||||
),
|
||||
)
|
||||
.setDescriptionLocalizations(subcommandDescriptionLocalizations);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user