From 26d94bed0ca24bf181ed2d97779b5258f9b1a0af Mon Sep 17 00:00:00 2001 From: Slincnik Date: Tue, 4 Mar 2025 18:02:39 +0300 Subject: [PATCH] feat: moved translate command to i18n service --- src/services/languages/index.ts | 13 ++++++------- src/structures/client.ts | 10 ---------- 2 files changed, 6 insertions(+), 17 deletions(-) diff --git a/src/services/languages/index.ts b/src/services/languages/index.ts index d8a920c1..06b1f045 100644 --- a/src/services/languages/index.ts +++ b/src/services/languages/index.ts @@ -26,7 +26,7 @@ export default class InternationalizationService { this.client = client; this.options = { localesPath: resolve(this.client.configService.get("paths.locales")), - defaultLanguage: options.defaultLanguage || "en-US", + defaultLanguage: options.defaultLanguage || this.client.configService.get("defaultLang"), }; this.init(); } @@ -54,6 +54,11 @@ export default class InternationalizationService { return { namespaces: [...new Set(namespaces)], languages }; } + public translate(key: string, options: TOptionsBase = {}) { + const lng = options.lng || this.options.defaultLanguage; + return i18next.t(key, { lng, ...options }); + } + private async init() { const { namespaces, languages } = await this.walkDirectory(this.options.localesPath); @@ -71,12 +76,6 @@ export default class InternationalizationService { initImmediate: false, }); - // Типизированная функция translate - this.client.translate = (key: string, options: TOptionsBase = {}): string => { - const lng = options.lng || this.options.defaultLanguage; - return i18next.t(key, { lng, ...options }); - }; - logger.log("Internationalization initialized"); return i18nInstance; diff --git a/src/structures/client.ts b/src/structures/client.ts index f44b3add..dca3650e 100644 --- a/src/structures/client.ts +++ b/src/structures/client.ts @@ -1,6 +1,5 @@ import { Client, ClientOptions } from "discord.js"; import { GiveawaysManager } from "discord-giveaways"; -import { TOptionsBase } from "i18next"; import { Handlers } from "@/handlers/index.js"; import MongooseAdapter from "@/adapters/database/MongooseAdapter.js"; import logger from "@/helpers/logger.js"; @@ -16,15 +15,6 @@ export class ExtendedClient extends Client { cacheReminds = new Map(); i18n = new InternationalizationService(this); - translate!: ( - _key: string, - _options?: - | TOptionsBase - | { - [key: string]: string; - }, - ) => string; - // @ts-ignore - because ExtendedClient != Client from discord.js giveaways = new GiveawaysManager(this, { storage: "./giveaways.json",