Add translate capabilities to QRMessages in CW

This commit is contained in:
Douglas Rauber at Nitro
2024-01-25 16:19:08 -03:00
parent 7f74de07ed
commit 0edc8a9284
9 changed files with 68 additions and 6 deletions

36
src/utils/i18n.ts Normal file
View 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;

View 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."
}

View 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."
}