From 3c289fbe7334abb413cc366910075bbb9abd9a2c Mon Sep 17 00:00:00 2001 From: Nicolas Brousse Date: Tue, 13 Aug 2019 17:48:43 +0200 Subject: [PATCH 1/2] Add a second scope for i18n enum Add a second scope for i18n enum to follow the syntax in Rails guides --- lib/formtastic/inputs/base/collections.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/formtastic/inputs/base/collections.rb b/lib/formtastic/inputs/base/collections.rb index d3dcdb47d..44671e3de 100644 --- a/lib/formtastic/inputs/base/collections.rb +++ b/lib/formtastic/inputs/base/collections.rb @@ -114,8 +114,11 @@ def collection_from_enum enum_options_hash = object.defined_enums[method_name] enum_options_hash.map do |name, value| - key = "activerecord.attributes.#{object_name}.#{method_name.pluralize}.#{name}" - label = ::I18n.translate(key, :default => name.humanize) + scopes = [ + "activerecord.attributes.#{object_name}/#{method_name.pluralize}" + "activerecord.attributes.#{object_name}.#{method_name.pluralize}", + ] + label = ::I18n.translate(name, scope: scopes, :default => name.humanize) [label, name] end end From 5979dc03a6b9f501d9d4367da0c356e9d4e23bc6 Mon Sep 17 00:00:00 2001 From: Nicolas Brousse Date: Tue, 13 Aug 2019 18:32:28 +0200 Subject: [PATCH 2/2] Fix previous commit --- lib/formtastic/inputs/base/collections.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/formtastic/inputs/base/collections.rb b/lib/formtastic/inputs/base/collections.rb index 44671e3de..dd95cfb19 100644 --- a/lib/formtastic/inputs/base/collections.rb +++ b/lib/formtastic/inputs/base/collections.rb @@ -115,8 +115,8 @@ def collection_from_enum enum_options_hash = object.defined_enums[method_name] enum_options_hash.map do |name, value| scopes = [ - "activerecord.attributes.#{object_name}/#{method_name.pluralize}" - "activerecord.attributes.#{object_name}.#{method_name.pluralize}", + "activerecord.attributes.#{object_name}/#{method_name.pluralize}", + "activerecord.attributes.#{object_name}.#{method_name.pluralize}" ] label = ::I18n.translate(name, scope: scopes, :default => name.humanize) [label, name]