localization

This commit is contained in:
2025-09-13 15:16:05 +09:00
parent e81725e4d5
commit 1eb7d1c9bc
11 changed files with 660 additions and 11 deletions

View File

@@ -1,6 +1,7 @@
import i18next from 'i18next';
import * as fs from 'fs';
import * as path from 'path';
import { pool } from '../database/connection';
export class LocalizationService {
private static instance: LocalizationService;
@@ -129,6 +130,22 @@ export class LocalizationService {
}
}
// Функция для получения персонализированного перевода пользователя
export const getUserTranslation = async (telegramId: string, key: string, options?: any): Promise<string> => {
try {
// Получаем язык пользователя из базы данных
const result = await pool.query('SELECT language FROM users WHERE telegram_id = $1', [telegramId]);
const userLanguage = result.rows[0]?.language || 'ru';
// Получаем перевод для языка пользователя
return LocalizationService.getInstance().getTranslation(key, userLanguage, options);
} catch (error) {
console.error('Error getting user translation:', error);
// Возвращаем перевод на русском языке по умолчанию
return LocalizationService.getInstance().getTranslation(key, 'ru', options);
}
};
// Функция-хелпер для быстрого доступа к переводам
export const t = (key: string, options?: any): string => {
return LocalizationService.getInstance().t(key, options);