Enhance moderation commands with locale support and permission checks
- Updated moderation commands to utilize locale for user-facing messages, improving internationalization. - Refactored permission checks to include locale as a parameter, ensuring accurate responses based on the server's language settings. - Added new translation keys for bot permissions and command restrictions in both German and English.
This commit is contained in:
@@ -34,13 +34,41 @@ export type ModerationAction = z.infer<typeof ModerationActionSchema>;
|
||||
type Dictionary = Record<string, string>;
|
||||
const de: Dictionary = {
|
||||
'generic.noPermission': 'Du hast keine Berechtigung für diese Aktion.',
|
||||
'generic.guildOnly': 'Dieser Command kann nur auf einem Server verwendet werden.',
|
||||
'generic.botMissingPermission': 'Dem Bot fehlt die erforderliche Berechtigung ({permission}).',
|
||||
'generic.invalidRegex': 'Ungültiges Regex-Muster.',
|
||||
'moderation.success': 'Aktion erfolgreich ausgeführt.',
|
||||
'moderation.reason.none': 'Kein Grund angegeben'
|
||||
'moderation.reason.none': 'Kein Grund angegeben',
|
||||
'moderation.warning.created': 'Verwarnung erstellt: {warningId}',
|
||||
'moderation.warning.none': 'Keine Verwarnungen vorhanden.',
|
||||
'moderation.warning.defaultReason': 'Kein Grund',
|
||||
'moderation.note.none': 'Keine Notizen vorhanden.',
|
||||
'moderation.case.notFound': 'Fall nicht gefunden.',
|
||||
'moderation.escalation.durationRequired':
|
||||
'Für TIMEOUT-Eskalation ist eine Dauer erforderlich.',
|
||||
'moderation.escalation.noneConfigured': 'Keine Eskalationsregeln konfiguriert.',
|
||||
'moderation.escalation.saved':
|
||||
'Eskalationsregel gespeichert: {warnCount} Verwarnungen => {action}{duration}.',
|
||||
'moderation.escalation.removed':
|
||||
'Eskalationsregel für {warnCount} Verwarnungen entfernt.'
|
||||
};
|
||||
const en: Dictionary = {
|
||||
'generic.noPermission': 'You do not have permission for this action.',
|
||||
'generic.guildOnly': 'This command can only be used in a server.',
|
||||
'generic.botMissingPermission': 'Bot lacks required permission ({permission}).',
|
||||
'generic.invalidRegex': 'Invalid regex pattern.',
|
||||
'moderation.success': 'Action executed successfully.',
|
||||
'moderation.reason.none': 'No reason provided'
|
||||
'moderation.reason.none': 'No reason provided',
|
||||
'moderation.warning.created': 'Warning created: {warningId}',
|
||||
'moderation.warning.none': 'No warnings.',
|
||||
'moderation.warning.defaultReason': 'No reason',
|
||||
'moderation.note.none': 'No notes.',
|
||||
'moderation.case.notFound': 'Case not found.',
|
||||
'moderation.escalation.durationRequired': 'Duration is required for TIMEOUT escalation.',
|
||||
'moderation.escalation.noneConfigured': 'No escalation rules configured.',
|
||||
'moderation.escalation.saved':
|
||||
'Escalation rule saved: {warnCount} warnings => {action}{duration}.',
|
||||
'moderation.escalation.removed': 'Escalation rule removed for {warnCount} warnings.'
|
||||
};
|
||||
|
||||
const locales: Record<Locale, Dictionary> = { de, en };
|
||||
@@ -48,3 +76,11 @@ const locales: Record<Locale, Dictionary> = { de, en };
|
||||
export function t(locale: Locale, key: string): string {
|
||||
return locales[locale][key] ?? key;
|
||||
}
|
||||
|
||||
export function tf(locale: Locale, key: string, vars: Record<string, string | number>): string {
|
||||
const base = t(locale, key);
|
||||
return Object.entries(vars).reduce(
|
||||
(acc, [name, value]) => acc.replaceAll(`{${name}}`, String(value)),
|
||||
base
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user