admin管理员组文章数量:1023738
I have been reading about this for days, and nothing seems to be working. I have seen a lot of documentation of this issue, but none of the work arounds are working 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)
config/i18n-js.yml
translations:
- file: "app/assets/javascripts/application/i18n/translations.js"
only: '*.js*'
config/application.rb
config.middleware.use I18n::JS::Middleware
When I add new translations to the corresponding yml file, the i18n/translations.js does not update to include the new .yml translations.
For example, in en.yml:
en:
form_error:
tos_check: "You must agree to Lexody's 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 have tried:
Deleting translations.js and run rake i18n:js:export
rake tmp:cache:clear
rake assets:prepile
Does anyone have another solution I can try? Thanks!!
I have been reading about this for days, and nothing seems to be working. I have seen a lot of documentation of this issue, but none of the work arounds are working 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)
config/i18n-js.yml
translations:
- file: "app/assets/javascripts/application/i18n/translations.js"
only: '*.js*'
config/application.rb
config.middleware.use I18n::JS::Middleware
When I add new translations to the corresponding yml file, the i18n/translations.js does not update to include the new .yml translations.
For example, in en.yml:
en:
form_error:
tos_check: "You must agree to Lexody's 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 have tried:
Deleting translations.js and run rake i18n:js:export
rake tmp:cache:clear
rake assets:prepile
Does anyone have another solution I can try? Thanks!!
Share Improve this question edited Jan 12, 2017 at 23:00 gwalshington asked Jan 4, 2017 at 22:39 gwalshingtongwalshington 1,5052 gold badges32 silver badges65 bronze badges4 Answers
Reset to default 3 +50Update
After looking at the additional configuration files, this config/i18n-js.yml
seems suspect:
translations:
- file: "app/assets/javascripts/application/i18n/translations.js"
only: '*.js*'
According to the export configuration docs, the only
key refers to the translation keys to be exported, not the filenames. So '*.js*'
will match nothing, causing no translations to be exported.
Change this file to read:
translations:
- file: "app/assets/javascripts/application/i18n/translations.js"
only: '*'
(Original answer below)
Working example
Here's a minimal, working example that produces expected behavior with the i18n-js
gem:
#!/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
For me, running the above script outputs "NEW_KEY"
on the last line, as expected (demonstrating that NEW_KEY
is correctly added to public/javascripts/translations.js
after running i18n:js:export
in a fresh Rails installation), which means something else is going on in your local project.
Further investigation
In order to know what else exactly is going on, you'll have to further investigate exactly what configuration you've changed locally when pared to a fresh Rails installation.
(Note that the easiest way to do this is to provide a Minimal, Complete and Verifiable example, such as a link to a GitHub repo that produces your issue exactly.)
- you say "the i18n/translations.js does not update to include the new .yml translations.", but the default path that gets updated is
public/javascripts/translations.js
. If you're using a non-standard path for yourtranslations.js
file, do you have additional configuration for this inconfig/i18n-js.yml
? (If so, please share the entire contents of this file). - Have you confirmed that the new translation doesn't show up in
translations.js
at all (e.g., using agrep
mand like the one above)? Or is it possible that the issue is related to the asset pipeline configuration instead?
Not sure if you mean dev
or prod
env. I had a similar problem in my dev
env and I solved it by adding config.middleware.use(I18n::JS::Middleware)
to config/application.rb
. You can check it here. Hope it helps.
In the .yml
file, check for a colon after the language code.
Your example reads:
en
form_error:
cancel_reason: "Please provide a reason for cancelling."
Try:
en:
form_error:
cancel_reason: "Please provide a reason for cancelling."
I haven't tried exercising an example with this. However, the .yml
files in the projects I have copies of all have colon after the language name. And it's just the sort of infuriating typo that might be invisible to someone close to it. Grr!
It seems that you have the English translation but is trying to access french locale instead.
I have been reading about this for days, and nothing seems to be working. I have seen a lot of documentation of this issue, but none of the work arounds are working 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)
config/i18n-js.yml
translations:
- file: "app/assets/javascripts/application/i18n/translations.js"
only: '*.js*'
config/application.rb
config.middleware.use I18n::JS::Middleware
When I add new translations to the corresponding yml file, the i18n/translations.js does not update to include the new .yml translations.
For example, in en.yml:
en:
form_error:
tos_check: "You must agree to Lexody's 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 have tried:
Deleting translations.js and run rake i18n:js:export
rake tmp:cache:clear
rake assets:prepile
Does anyone have another solution I can try? Thanks!!
I have been reading about this for days, and nothing seems to be working. I have seen a lot of documentation of this issue, but none of the work arounds are working 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)
config/i18n-js.yml
translations:
- file: "app/assets/javascripts/application/i18n/translations.js"
only: '*.js*'
config/application.rb
config.middleware.use I18n::JS::Middleware
When I add new translations to the corresponding yml file, the i18n/translations.js does not update to include the new .yml translations.
For example, in en.yml:
en:
form_error:
tos_check: "You must agree to Lexody's 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 have tried:
Deleting translations.js and run rake i18n:js:export
rake tmp:cache:clear
rake assets:prepile
Does anyone have another solution I can try? Thanks!!
Share Improve this question edited Jan 12, 2017 at 23:00 gwalshington asked Jan 4, 2017 at 22:39 gwalshingtongwalshington 1,5052 gold badges32 silver badges65 bronze badges4 Answers
Reset to default 3 +50Update
After looking at the additional configuration files, this config/i18n-js.yml
seems suspect:
translations:
- file: "app/assets/javascripts/application/i18n/translations.js"
only: '*.js*'
According to the export configuration docs, the only
key refers to the translation keys to be exported, not the filenames. So '*.js*'
will match nothing, causing no translations to be exported.
Change this file to read:
translations:
- file: "app/assets/javascripts/application/i18n/translations.js"
only: '*'
(Original answer below)
Working example
Here's a minimal, working example that produces expected behavior with the i18n-js
gem:
#!/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
For me, running the above script outputs "NEW_KEY"
on the last line, as expected (demonstrating that NEW_KEY
is correctly added to public/javascripts/translations.js
after running i18n:js:export
in a fresh Rails installation), which means something else is going on in your local project.
Further investigation
In order to know what else exactly is going on, you'll have to further investigate exactly what configuration you've changed locally when pared to a fresh Rails installation.
(Note that the easiest way to do this is to provide a Minimal, Complete and Verifiable example, such as a link to a GitHub repo that produces your issue exactly.)
- you say "the i18n/translations.js does not update to include the new .yml translations.", but the default path that gets updated is
public/javascripts/translations.js
. If you're using a non-standard path for yourtranslations.js
file, do you have additional configuration for this inconfig/i18n-js.yml
? (If so, please share the entire contents of this file). - Have you confirmed that the new translation doesn't show up in
translations.js
at all (e.g., using agrep
mand like the one above)? Or is it possible that the issue is related to the asset pipeline configuration instead?
Not sure if you mean dev
or prod
env. I had a similar problem in my dev
env and I solved it by adding config.middleware.use(I18n::JS::Middleware)
to config/application.rb
. You can check it here. Hope it helps.
In the .yml
file, check for a colon after the language code.
Your example reads:
en
form_error:
cancel_reason: "Please provide a reason for cancelling."
Try:
en:
form_error:
cancel_reason: "Please provide a reason for cancelling."
I haven't tried exercising an example with this. However, the .yml
files in the projects I have copies of all have colon after the language name. And it's just the sort of infuriating typo that might be invisible to someone close to it. Grr!
It seems that you have the English translation but is trying to access french locale instead.
本文标签: javascripti18njs translations not updating with additional translations in ymlStack Overflow
版权声明:本文标题:javascript - i18n-js translations not updating with additional translations in .yml - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745596573a2158207.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论