I18n-js translations are not updated with additional translations in .yml

I read about it for several days and nothing works. I saw a lot of documentation on this issue, but not a single work around works for me. I have:

  Rails 5.0.1
  * sprockets (3.7.1)
  * sprockets-rails (3.2.0)
  * i18n (0.7.0)
  * i18n-js (3.0.0.rc15)

configurations / i18n-js.yml

translations:
- file: "app/assets/javascripts/application/i18n/translations.js"
  only: '*.js*'

configurations / application.rb

    config.middleware.use I18n::JS::Middleware

When I add new translations to the corresponding yml file, i18n / translations.js is not updated to include new .yml translations.

For example, in en.yml:

en:
 form_error:
    tos_check: "You must agree to Lexody Terms of Use to continue."
    choose_city: "Please select a city from the menu."
    cancel_reason: "Please provide a reason for cancelling."

$('.prompt').html('<p style="color:#e57373">' + I18n.t('form_error.cancel_reason') +'</p>');

returns: [missing "en.form_error.cancel_reason" translation]

I tried:

Removing translations.js and launching rake i18n:js:export

rake tmp:cache:clear

rake assets:precompile

Does anyone have any other solution that I can try? Thank!!

+4
source share
4 answers

Update

config/i18n-js.yml :

translations:
- file: "app/assets/javascripts/application/i18n/translations.js"
  only: '*.js*'

export configuration docs only , . , '*.js*' , .

:

translations:
- file: "app/assets/javascripts/application/i18n/translations.js"
  only: '*'

( )

, i18n-js:

#!/bin/bash
rails _5.0.1_ new .
echo "gem 'i18n-js', '3.0.0.rc15'" >> Gemfile
echo "  NEW_KEY: NEW_VALUE" >> config/locales/en.yml
bundle install
bundle exec rake i18n:js:export
grep -o '"NEW_KEY"' public/javascripts/translations.js

script "NEW_KEY" , (, NEW_KEY public/javascripts/translations.js i18n:js:export Rails), - .

, , , , Rails.

( , - , , GitHub, .)

  • : "i18n/translations.js , .yml.", , , public/javascripts/translations.js. translations.js, config/i18n-js.yml? ( , ).
  • , translations.js (, grep, )? , ?
+2

, dev prod env. dev env, , config.middleware.use(I18n::JS::Middleware) config/application.rb. . , .

0

.yml .

:

en
 form_error:
    cancel_reason: "Please provide a reason for cancelling."

Try:

en:
 form_error:
    cancel_reason: "Please provide a reason for cancelling."

. , .yml , , . , - . Grr!

0
source

It seems that you have an English translation, but it is trying to access the French language.

-1
source

Source: https://habr.com/ru/post/1665797/


All Articles