Update README and moderation commands for localization and migration support
- Revised README to include database migration steps and a new section for database management. - Enhanced moderation command responses to utilize localized messages for unknown commands. - Refactored moderation commands to use centralized command data definitions, improving maintainability and consistency. - Added localization support for command descriptions and options in both German and English. - Versioned Prisma migrations for better tracking of database changes.
This commit is contained in:
48
packages/shared/src/discord-localization.ts
Normal file
48
packages/shared/src/discord-localization.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import { commandLocales, type CommandLocaleKey } from './command-locales.js';
|
||||
|
||||
export function commandLocale(key: CommandLocaleKey): {
|
||||
description: string;
|
||||
descriptionLocalizations: Record<string, string>;
|
||||
} {
|
||||
const entry = commandLocales[key];
|
||||
return {
|
||||
description: entry.en,
|
||||
descriptionLocalizations: {
|
||||
de: entry.de,
|
||||
'en-US': entry.en
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export function localizedChoice(key: CommandLocaleKey, value: string) {
|
||||
const entry = commandLocales[key];
|
||||
return {
|
||||
name: entry.en,
|
||||
name_localizations: {
|
||||
de: entry.de,
|
||||
'en-US': entry.en
|
||||
},
|
||||
value
|
||||
};
|
||||
}
|
||||
|
||||
export function applyCommandDescription<
|
||||
T extends {
|
||||
setDescription: (description: string) => T;
|
||||
setDescriptionLocalizations: (localizations: Record<string, string>) => T;
|
||||
}
|
||||
>(builder: T, key: CommandLocaleKey): T {
|
||||
const locale = commandLocale(key);
|
||||
return builder
|
||||
.setDescription(locale.description)
|
||||
.setDescriptionLocalizations(locale.descriptionLocalizations);
|
||||
}
|
||||
|
||||
export function applyOptionDescription<
|
||||
T extends {
|
||||
setDescription: (description: string) => T;
|
||||
setDescriptionLocalizations: (localizations: Record<string, string>) => T;
|
||||
}
|
||||
>(option: T, key: CommandLocaleKey): T {
|
||||
return applyCommandDescription(option, key);
|
||||
}
|
||||
Reference in New Issue
Block a user