mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-12-20 04:12:23 -06:00
Add translate capabilities to QRMessages in CW
This commit is contained in:
36
src/utils/i18n.ts
Normal file
36
src/utils/i18n.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import fs from 'fs';
|
||||
import i18next from 'i18next';
|
||||
import path from 'path';
|
||||
|
||||
import { ConfigService, Language } from '../config/env.config';
|
||||
|
||||
// export class i18n {
|
||||
// constructor(private readonly configService: ConfigService) {
|
||||
const languages = ['en', 'pt-BR'];
|
||||
const translationsPath = path.join(__dirname, 'translations');
|
||||
const configService: ConfigService = new ConfigService();
|
||||
|
||||
const resources: any = {};
|
||||
|
||||
languages.forEach((language) => {
|
||||
const languagePath = path.join(translationsPath, `${language}.json`);
|
||||
if (fs.existsSync(languagePath)) {
|
||||
resources[language] = {
|
||||
translation: require(languagePath),
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
i18next.init({
|
||||
resources,
|
||||
fallbackLng: 'en',
|
||||
lng: configService.get<Language>('LANGUAGE'),
|
||||
debug: false,
|
||||
|
||||
interpolation: {
|
||||
escapeValue: false,
|
||||
},
|
||||
});
|
||||
// }
|
||||
// }
|
||||
export default i18next;
|
||||
5
src/utils/translations/en.json
Normal file
5
src/utils/translations/en.json
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"qrgeneratedsuccesfully": "QRCode successfully generated!",
|
||||
"scanqr": "Scan this QR code within the next 40 seconds.",
|
||||
"qrlimitreached": "QRCode generation limit reached, to generate a new QRCode, send the 'init' message again."
|
||||
}
|
||||
5
src/utils/translations/pt-BR.json
Normal file
5
src/utils/translations/pt-BR.json
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"qrgeneratedsuccesfully": "QRCode gerado com sucesso!",
|
||||
"scanqr": "Escanei o QRCode com o Whatsapp nos próximos 40 segundos.",
|
||||
"qrlimitreached": "Limite de geração de QRCode atingido! Para gerar um novo QRCode, envie o texto 'init' nesta conversa."
|
||||
}
|
||||
Reference in New Issue
Block a user