mirror of
https://github.com/darksaid98/cadence-discord-bot.git
synced 2026-12-03 14:38:49 +00:00
Merge pull request #326 from tacheometry/main
Use existing i18n instance
This commit is contained in:
2 files changed
+2
-28
No files matched your search
@@ -11,7 +11,7 @@ import i18n from 'i18next';
|
||||
import i18nextFsBackend, { FsBackendOptions } from 'i18next-fs-backend';
|
||||
import { join } from 'path';
|
||||
|
||||
const translatorInstance = i18n.createInstance();
|
||||
export const translatorInstance = i18n.createInstance();
|
||||
const localeDir = join(__dirname, '..', '..', 'locales');
|
||||
translatorInstance.use(i18nextFsBackend).init<FsBackendOptions>({
|
||||
initImmediate: false,
|
||||
|
||||
@@ -14,12 +14,8 @@ import {
|
||||
} from 'discord.js';
|
||||
import { BaseSlashCommandInteraction } from '../../../classes/interactions';
|
||||
import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes';
|
||||
import { CommandMetadata, localizeCommand, useServerTranslator } from '../../../common/localeUtil';
|
||||
import { CommandMetadata, localizeCommand, translatorInstance, useServerTranslator } from '../../../common/localeUtil';
|
||||
import { ExtendedClient } from '../../../types/clientTypes';
|
||||
import i18n from 'i18next';
|
||||
import i18nextFsBackend, { FsBackendOptions } from 'i18next-fs-backend';
|
||||
import { join } from 'path';
|
||||
import { lstatSync, readdirSync } from 'fs';
|
||||
|
||||
class HelpCommand extends BaseSlashCommandInteraction {
|
||||
constructor() {
|
||||
@@ -104,30 +100,8 @@ class HelpCommand extends BaseSlashCommandInteraction {
|
||||
}
|
||||
|
||||
private getCommandString(command: BaseSlashCommandInteraction, interaction: ChatInputCommandInteraction): string {
|
||||
// TODO: Clean up this mess and create a common factory for translator instances.
|
||||
const commandName = command.data.name;
|
||||
const metadataKey = `commands.${commandName}.metadata`;
|
||||
const translatorInstance = i18n.createInstance();
|
||||
const localeDir = join(__dirname, '..', '..', '..', '..', 'locales');
|
||||
translatorInstance.use(i18nextFsBackend).init<FsBackendOptions>({
|
||||
initImmediate: false,
|
||||
fallbackLng: 'en',
|
||||
preload: readdirSync(localeDir).filter((fileName) => {
|
||||
const joinedPath = join(localeDir, fileName);
|
||||
const isDirectory = lstatSync(joinedPath).isDirectory();
|
||||
return isDirectory;
|
||||
}),
|
||||
ns: 'bot',
|
||||
defaultNS: 'bot',
|
||||
backend: {
|
||||
loadPath: join(localeDir, '{{lng}}', '{{ns}}.json'),
|
||||
addPath: join(localeDir, '{{lng}}', '{{ns}}.missing.json')
|
||||
},
|
||||
interpolation: {
|
||||
escapeValue: false
|
||||
}
|
||||
});
|
||||
|
||||
const locale = interaction.guildLocale ?? 'en';
|
||||
let translatedData: CommandMetadata | undefined = undefined;
|
||||
translatedData = translatorInstance.getResource(locale, 'bot', metadataKey) as CommandMetadata | undefined;
|
||||
|
||||
Reference in new issue
Block a user