Browse files

assert that i18n-js can correctly precompile assets given the current…

… application configuration - complain loudly if not
  • Loading branch information...
1 parent db724fc commit 9f7a09481c8845bd90f0ddbade9882fec60de406 @mjtko mjtko committed Oct 3, 2011
Showing with 15 additions and 3 deletions.
  1. +9 −0 lib/i18n-js.rb
  2. +6 −3 vendor/assets/javascripts/i18n/translations.js.erb
View
9 lib/i18n-js.rb
@@ -11,6 +11,15 @@ module I18n
# deep_merge by Stefan Rusterholz, see http://www.ruby-forum.com/topic/142809
MERGER = proc { |key, v1, v2| Hash === v1 && Hash === v2 ? v1.merge(v2, &MERGER) : v2 }
+ # Under rails 3.1.1 and higher, perform a check to ensure that the
+ # full environment will be available during asset compilation.
+ # This is required to ensure I18n is loaded.
+ def assert_usable_configuration!
+ @usable_configuration ||= Rails.version >= "3.1.1" &&
+ Rails.application.config.assets.initialize_on_precompile ||
+ raise("Cannot precompile i18n-js translations unless environment is initialized. Please set config.assets.initialize_on_precompile to true.")
+ end
+
def config_file
Rails.root.join("config/i18n-js.yml")
end
View
9 vendor/assets/javascripts/i18n/translations.js.erb
@@ -1,4 +1,7 @@
+<% SimplesIdeias::I18n.assert_usable_configuration! %>
var I18n = I18n || {};
-I18n.translations = <%= SimplesIdeias::I18n.translation_segments.each_with_object({}) do |(name, segment),translations|
- translations.merge!(segment)
-end.to_json %>;
+I18n.translations = <%=
+ SimplesIdeias::I18n.translation_segments.each_with_object({}) do |(name, segment),translations|
+ translations.merge!(segment)
+ end.to_json
+%>;

0 comments on commit 9f7a094

Please sign in to comment.