I just switched to Rails 6 (6.0.0.rc1) which uses the Webpacker gem. I want to use i18n-js in some of my modules for translation purpose. How can configured i18n in my application with webpacker ?
Sorry for the late answering but I have already resolved this issue as below :-
yarn add i18n-js
After this I have changed in below files
## javascript/packs/application.js
require("@rails/ujs").start()
require("@rails/activestorage").start()
require("channels")
window.jQuery = window.$ = require('jquery')
var Turbolinks = require("turbolinks");
Turbolinks.start();
import I18n from 'i18n-js'
window.I18n = I18n
And then to load all translations :-
## application.html.erb
<script>
var language = "<%= I18n.locale %>";
I18n.translations = <%== I18n::JS.filtered_translations.to_json %>;
</script>
Now translations are ready to use in js files:-
I18n.t('a.hello')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With