fnando / i18n-js

It's a small library to provide the I18n translations on the Javascript. It comes with Rails support.
MIT License
3.75k stars 519 forks source link

Bug: Translation files Don't Update #660

Closed anthony0030 closed 1 year ago

anthony0030 commented 1 year ago

Description

The output translation files don't update with new content

How to reproduce

Make an edit to a translation YML file

What do you expect

The JSON file receives updated content

What happened instead

The initial translations are written to the file

Software:

Full backtrace

NA

fnando commented 1 year ago

Can you please provide some extra info? How are you exporting translations? Are you using guard, listen, watchman?

anthony0030 commented 1 year ago

I was trying to use the guard. But I might switch to watchman to get it resolved faster.

I see this in the terminal:

16:11:15 - INFO - [guard-i18n-js] Changes detected: config/locales/view_components/en.yml

On initial load, the translation files get created with their initial content, but what gets written to them is still the initial contents.

/Users/anthonyveaudry/.rvm/gems/ruby-3.1.2/gems/i18n-js-4.0.0/lib/i18n-js.rb lines from 65

  def self.translations
    ::I18n.backend.instance_eval do
      has_been_initialized_before = respond_to?(:initialized?, true) && initialized?
      init_translations unless has_been_initialized_before
      binding.remote_pry
      translations
    end
  end

If I run init_translations the translations get updated. The content of translations is always the initial translations from when it boots.

Guardfile

  guard(:"i18n-js",
        run_on_start: true,
        config_file: './config/i18n.yml',
        require_file: './config/environment.rb') do
    watch(%r{^(app|config)/locales/.+\.(yml|po)$})
    watch(%r{^config/i18n.yml$})
    watch('config/jumpstart/Gemfile')
  end

i18n.yml

---
  translations:
    - file: app/assets/locales/view_components/:locale.json
      patterns:
        - "*.view_components.*"
anthony0030 commented 1 year ago

I am facing a similar problem that is described here #616

anthony0030 commented 1 year ago

I installed the gem like this:

  gem "i18n-js", github: "fnando/i18n-js", branch: "shell-out-listen-export"

The code on the branch you are working on seems to keep the language files updated on my setup.

fnando commented 1 year ago

Thanks for testing. I'm going to merge it and make a new release soon.

anthony0030 commented 1 year ago

Hi @fnando, Thank you for getting this fixed in version 4.0.1!