diff options
| -rw-r--r-- | app/controllers/application_controller.rb | 6 | ||||
| -rw-r--r-- | config/initializers/inflections.rb | 14 |
2 files changed, 7 insertions, 13 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 45b7f55f6..29c2443f0 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -9,6 +9,7 @@ class ApplicationController < ActionController::Base protect_from_forgery unless: -> { request.get? && (request.format.json? || request.format.js?) } before_action :authenticate_user! before_action :set_locale + after_action :reset_locale # Load helpers in rails engine @@ -19,6 +20,11 @@ class ApplicationController < ActionController::Base # For testing different locales w/o restarting the server I18n.locale = (params['lang'] || session[:language] || I18n.default_locale).to_sym logger.info "locale set to #{I18n.locale.inspect}" + String.send :alias_method, :pluralize, :pluralize_with_i18n + end + + def reset_locale + String.send :alias_method, :pluralize, :pluralize_without_i18n end def pundit_user diff --git a/config/initializers/inflections.rb b/config/initializers/inflections.rb index ded879164..ef0ebea43 100644 --- a/config/initializers/inflections.rb +++ b/config/initializers/inflections.rb @@ -13,22 +13,10 @@ ActiveSupport::Inflector.inflections(:fr) do |inflect| inflect.plural 'Zone de contrainte', 'Zones de contrainte' end -# These inflection rules are supported but not enabled by default: -# ActiveSupport::Inflector.inflections(:en) do |inflect| -# inflect.acronym 'RESTful' -# end - class String def pluralize_with_i18n count=nil, locale=nil locale ||= I18n.locale pluralize_without_i18n count, locale end - alias_method_chain :pluralize, :i18n -end - -class ActiveRecord::Base - def self.undecorated_table_name(class_name = base_class.name) - table_name = class_name.to_s.demodulize.underscore - pluralize_table_names ? table_name.pluralize(:en) : table_name - end + alias_method :pluralize_without_i18n, :pluralize end |
