Skip to content

Conversation

@RaFaeL-Cunha
Copy link

@RaFaeL-Cunha RaFaeL-Cunha commented Oct 3, 2025

📋 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 __dirname no 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

  • 🐛 Bug fix (alteração sem quebra que corrige um problema)
  • ✨ New feature (alteração sem quebra que adiciona funcionalidade)
  • 💥 Breaking change (correção ou recurso que faria com que a funcionalidade existente não funcionasse como esperado)
  • 📚 Documentation update
  • 🔧 Refactoring (sem alterações funcionais)
  • ⚡ Performance improvement
  • 🧹 Code cleanup
  • 🔒 Security fix

🧪 Testing

  • Manual testing completed (Teste manual concluído)
  • Functionality verified in development environment (Funcionalidade verificada em ambiente de desenvolvimento)
  • No breaking changes introduced (Nenhuma alteração de quebra introduzida)
  • Tested with different connection types (if applicable)

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.numbernotinwhatsapp foi substituído corretamente pelo texto traduzido, confirmando que os arquivos JSON estão sendo lidos.

📸 Screenshots (if applicable)

image

✅ Checklist

  • My code follows the project's style guidelines
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have manually tested my changes thoroughly
  • I have verified the changes work with different scenarios
  • Any dependent changes have been merged and published

📝 Additional Notes

N/A

Summary by Sourcery

Bug Fixes:

  • Ensure JSON translation files are correctly located and loaded in Docker by using __dirname for absolute path resolution in i18n initialization.

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Oct 3, 2025

Reviewer's Guide

Replace 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 initialization

classDiagram
    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]
Loading

Flow diagram for translation file loading with __dirname

flowchart 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
Loading

File-Level Changes

Change Details Files
Switch to __dirname for translation path resolution
  • Remove path.resolve(process.cwd(), ...) usage and stub __dirname declaration
  • Introduce currentDir using native __dirname
  • Update translationsPath to use currentDir
  • Add explanatory comment for translations directory resolution
src/utils/i18n.ts

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a 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 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.
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.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@Vitordotpy
Copy link
Contributor

@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 ?

@RaFaeL-Cunha
Copy link
Author

Vitordotpy

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.

@Vitordotpy
Copy link
Contributor

Vitordotpy

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

@RaFaeL-Cunha
Copy link
Author

Vitordotpy

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants