-
Couldn't load subscription status.
- Fork 4.6k
FIX(i18n): Garante o carregamento dos arquivos de tradução no Docker usando __dirname #2046
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Reviewer's GuideReplace cwd-based path resolution with native __dirname to reliably load translation JSON files in Docker environments, updating the i18n initialization accordingly. Class diagram for updated i18n initializationclassDiagram
class ConfigService {
+get<Language>(key: string): Language
}
class i18next {
+init(options)
}
class "i18n setup" {
+currentDir: string
+translationsPath: string
+resources: any
+languages: string[]
}
"i18n setup" --> ConfigService : uses
"i18n setup" --> i18next : initializes
"i18n setup" : +forEach(language)
"i18n setup" : +fs.readFileSync(languagePath)
"i18n setup" : +JSON.parse(translationContent)
"i18n setup" : +resources[language]
Flow diagram for translation file loading with __dirnameflowchart TD
A["Start i18n setup"] --> B["Set currentDir to __dirname"]
B --> C["Set translationsPath = currentDir + '/translations'"]
C --> D["For each language in ['en', 'pt-BR', 'es']"]
D --> E["Check if translation file exists"]
E -->|Exists| F["Read and parse translation JSON"]
F --> G["Add to resources"]
E -->|Does not exist| H["Skip language"]
G --> I["Initialize i18next with resources"]
H --> I
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey there - I've reviewed your changes - here's some feedback:
- The
currentDirvariable is redundant since you can use__dirnamedirectly inpath.join—consider removing it and simplifying the code. - There’s a decorative separator comment (
// ------------------------------------------------------------------------------------------------) that adds noise; removing it will keep the file cleaner and more focused. - Wrap the JSON.parse call in a try/catch so that a malformed translation file doesn’t crash the entire initialization and you can log a clear error message.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The `currentDir` variable is redundant since you can use `__dirname` directly in `path.join`—consider removing it and simplifying the code.
- There’s a decorative separator comment (`// ------------------------------------------------------------------------------------------------`) that adds noise; removing it will keep the file cleaner and more focused.
- Wrap the JSON.parse call in a try/catch so that a malformed translation file doesn’t crash the entire initialization and you can log a clear error message.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
|
@RaFaeL-Cunha um fix desse problema já foi implementado e está em homolog, testou a imagem de homolog para ver se resolveu antes de desenvolver esse fix ? |
Sim, testei homolog continua bugado trazendo cw.message por isso mandei essa pr para ajudar. pq na minha imagem resolvi assim e ta funcionando normal. |
então joia |
Nessa de 4 dias atrás não tinha olhado eu tava rodando imagem de 7 dias testei essa ultima de 4 dias e realmente ta funcionando. se ja foi implementado vou removar o pull |
📋 Description
Este PR corrige um problema crítico onde as chaves de tradução (ex:
cw.message.numbernotinwhatsapp) apareciam na interface em vez do texto traduzido.O bug ocorria porque o carregamento dos arquivos JSON de tradução (
pt-BR.json,en.json, etc.) falhava em ambientes de deployment, como o Docker.Solução: Substituído o uso de
path.resolve(process.cwd(), ...)(que é inconsistente) pela variável nativa__dirnameno arquivo de inicialização de i18n. Isso garante um caminho absoluto e funcional para os arquivos, independentemente do Diretório de Trabalho (CWD) do processo.🔗 Related Issue
N/A
🧪 Type of Change
🧪 Testing
Descrição Adicional do Teste:
A correção foi testada em um ambiente Docker, onde o problema era replicável. Após a alteração, o texto de erro
cw.message.numbernotinwhatsappfoi substituído corretamente pelo texto traduzido, confirmando que os arquivos JSON estão sendo lidos.📸 Screenshots (if applicable)
✅ Checklist
📝 Additional Notes
N/A
Summary by Sourcery
Bug Fixes: