Skip to content

Commit 55d0d5b

Browse files
committed
Backend: add gem i18n-js & set configuration
1 parent 159fc3a commit 55d0d5b

File tree

6 files changed

+966
-1
lines changed

6 files changed

+966
-1
lines changed

Gemfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ gem "autoprefixer-rails"
5151

5252
gem "awesome_print"
5353

54+
gem "i18n-js", ">= 3.0.0.rc11"
55+
5456
# jquery as the JavaScript library has been moved under /client and managed by npm.
5557
# It is critical to not include any of the jquery gems when following this pattern or
5658
# else you might have multiple jQuery versions.

Gemfile.lock

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ GEM
109109
globalid (0.3.7)
110110
activesupport (>= 4.1.0)
111111
i18n (0.7.0)
112+
i18n-js (3.0.0.rc14)
113+
i18n (~> 0.6, >= 0.6.6)
112114
interception (0.5)
113115
io-like (0.3.0)
114116
jbuilder (2.6.0)
@@ -319,6 +321,7 @@ DEPENDENCIES
319321
factory_girl_rails
320322
foreman
321323
generator_spec
324+
i18n-js (>= 3.0.0.rc11)
322325
jbuilder
323326
launchy
324327
listen

config/application.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,8 @@ class Application < Rails::Application
1111
# Settings in config/environments/* take precedence over those specified here.
1212
# Application configuration should go into files in config/initializers
1313
# -- all .rb files in that directory are automatically loaded.
14+
15+
# i18n-js
16+
config.middleware.use I18n::JS::Middleware
1417
end
1518
end

config/initializers/assets.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,5 @@
1616
"application_#{type}.js",
1717
"application_#{type}.css"
1818
]
19+
20+
Rails.application.config.assets.precompile += %w(i18n.js)

config/initializers/react_on_rails.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
module RenderingExtension
2+
def self.custom_context(_view_context)
3+
{ translations: I18n.backend.send(:translations) }
4+
end
5+
end
16
# Shown below are the defaults for configuration
27
ReactOnRails.configure do |config|
38
# Directory where your generated assets go. All generated assets must go to the same directory.
@@ -74,7 +79,7 @@
7479

7580
# This allows you to add additional values to the Rails Context. Implement one static method
7681
# called `custom_context(view_context)` and return a Hash.
77-
config.rendering_extension = nil
82+
config.rendering_extension = RenderingExtension
7883

7984
# The server render method - either ExecJS or NodeJS
8085
config.server_render_method = "ExecJS"

0 commit comments

Comments
 (0)