$ rails new my-i8n --webpack
Gemfile
gem 'i18n-js'
$ bundle --binstubs
$ yarn add i18n-js
$ bin/rails webpacker:install:erb
app/javascript/i18n-js/index.js.erb
import I18n from "i18n-js"
I18n.translations = <%= I18n::JS.filtered_translations.to_json %>;
export default I18n
app/javascript/packs/application.js
import I18n from 'i18n-js/index.js.erb'
console.log(I18n.t('hello'))
$ bin/rails g controller welcome index
config/routes.rb
root 'welcome#index'
app/views/layouts/application.html.erb
<%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>
$ bin/rails s
Hi @bazzel,
In my case all is good, but if I change default locale to something else rather than "en", it still defaults to EN. Any idea what can be wrong?
i have added
application_controller.rb
config/application.rb
routes.rb
and also created fr & de yml files.
The result i have always hello world in english in application.js though if i add in the view
and switch locale it shows the correct one.