Skip to content

Commit

Permalink
Merge pull request #2500 from ekylibre/productnature-and-productnatur…
Browse files Browse the repository at this point in the history
…e-variant-escaping-key-method

implemented behaviour for escaping key if it contains DOT in it's name
  • Loading branch information
Aquaj committed Apr 10, 2019
2 parents ad54022 + 9724e9a commit 53a1f02
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
4 changes: 4 additions & 0 deletions config/initializers/inflections.rb
Expand Up @@ -31,6 +31,10 @@
# Set pluralization active with the algorithms defined in [locale]/i18n.rb # Set pluralization active with the algorithms defined in [locale]/i18n.rb
I18n::Backend::Simple.send(:include, I18n::Backend::Pluralization) I18n::Backend::Simple.send(:include, I18n::Backend::Pluralization)


def I18n.escape_key(key)
key.to_s.gsub('.', '-').to_sym
end

# set config for humanize # set config for humanize
Humanize.configure do |config| Humanize.configure do |config|
config.default_locale = :en # [:en, :fr], default: :en config.default_locale = :en # [:en, :fr], default: :en
Expand Down
6 changes: 3 additions & 3 deletions config/locales/fra/nomenclatures.yml
Expand Up @@ -3762,9 +3762,9 @@ fra:
lettuce_crop: "Culture de laitue" lettuce_crop: "Culture de laitue"
lewis_hazelnut: "Noisette Lewis" lewis_hazelnut: "Noisette Lewis"
lifter: "Souleveur" lifter: "Souleveur"
liquid_10_25_d1.4: "Azote binaire 10-25-0 densité 1.4" liquid_10_25_d1-4: "Azote binaire 10-25-0 densité 1.4"
liquid_10_34_d1.4: "Azote binaire 10-34-0 densité 1.4" liquid_10_34_d1-4: "Azote binaire 10-34-0 densité 1.4"
liquid_nitrogen_30_d1.3: "Azote liquide 30% densité 1.3" liquid_nitrogen_30_d1-3: "Azote liquide 30% densité 1.3"
little_office_equipment: "Petit équipement de bureau" little_office_equipment: "Petit équipement de bureau"
little_office_good: "Consommable de bureau" little_office_good: "Consommable de bureau"
livestock_cleanliness_product: "Produit d’hygiène d’élevage" livestock_cleanliness_product: "Produit d’hygiène d’élevage"
Expand Down
8 changes: 7 additions & 1 deletion lib/nomen/item.rb
Expand Up @@ -178,7 +178,13 @@ def include?(other)


# Return human name of item # Return human name of item
def human_name(options = {}) def human_name(options = {})
"nomenclatures.#{nomenclature.name}.items.#{name}".t(options.merge(default: ["items.#{name}".to_sym, "enumerize.#{nomenclature.name}.#{name}".to_sym, "labels.#{name}".to_sym, name.humanize])) "nomenclatures.#{I18n.escape_key(nomenclature.name)}.items.#{I18n.escape_key(name)}"
.t(options.merge(default: [
"items.#{I18n.escape_key(name)}".to_sym,
"enumerize.#{I18n.escape_key(nomenclature.name)}.#{I18n.escape_key(name)}".to_sym,
"labels.#{I18n.escape_key(name)}".to_sym,
name.humanize
]))
end end
alias humanize human_name alias humanize human_name
alias localize human_name alias localize human_name
Expand Down
9 changes: 2 additions & 7 deletions lib/nomen/nomenclature.rb
Expand Up @@ -289,12 +289,7 @@ def table_name


# Returns hash with items in tree: {a => nil, b => {c => nil}} # Returns hash with items in tree: {a => nil, b => {c => nil}}
def tree def tree
x = @roots.collect(&:tree).join @roots.collect(&:tree).join
return x
i.attributes.merge(parent: i.parent_name, name: i.name, left: i.left, right: i.right, depth: i.depth).deep_stringify_keys
return x
@roots.map do |_i|
end
end end


def translateable? def translateable?
Expand All @@ -303,7 +298,7 @@ def translateable?


# Return human name # Return human name
def human_name(options = {}) def human_name(options = {})
"nomenclatures.#{name}.name".t(options.merge(default: ["labels.#{name}".to_sym, name.to_s.humanize])) "nomenclatures.#{I18n.escape_key(name)}.name".t(options.merge(default: ["labels.#{I18n.escape_key(name)}".to_sym, name.to_s.humanize]))
end end
alias humanize human_name alias humanize human_name


Expand Down

0 comments on commit 53a1f02

Please sign in to comment.