Skip to content

Commit 53a1f02

Browse files
authored
Merge pull request #2500 from ekylibre/productnature-and-productnature-variant-escaping-key-method
implemented behaviour for escaping key if it contains DOT in it's name
2 parents ad54022 + 9724e9a commit 53a1f02

File tree

4 files changed

+16
-11
lines changed

4 files changed

+16
-11
lines changed

config/initializers/inflections.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131
# Set pluralization active with the algorithms defined in [locale]/i18n.rb
3232
I18n::Backend::Simple.send(:include, I18n::Backend::Pluralization)
3333

34+
def I18n.escape_key(key)
35+
key.to_s.gsub('.', '-').to_sym
36+
end
37+
3438
# set config for humanize
3539
Humanize.configure do |config|
3640
config.default_locale = :en # [:en, :fr], default: :en

config/locales/fra/nomenclatures.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3762,9 +3762,9 @@ fra:
37623762
lettuce_crop: "Culture de laitue"
37633763
lewis_hazelnut: "Noisette Lewis"
37643764
lifter: "Souleveur"
3765-
liquid_10_25_d1.4: "Azote binaire 10-25-0 densité 1.4"
3766-
liquid_10_34_d1.4: "Azote binaire 10-34-0 densité 1.4"
3767-
liquid_nitrogen_30_d1.3: "Azote liquide 30% densité 1.3"
3765+
liquid_10_25_d1-4: "Azote binaire 10-25-0 densité 1.4"
3766+
liquid_10_34_d1-4: "Azote binaire 10-34-0 densité 1.4"
3767+
liquid_nitrogen_30_d1-3: "Azote liquide 30% densité 1.3"
37683768
little_office_equipment: "Petit équipement de bureau"
37693769
little_office_good: "Consommable de bureau"
37703770
livestock_cleanliness_product: "Produit d’hygiène d’élevage"

lib/nomen/item.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,13 @@ def include?(other)
178178

179179
# Return human name of item
180180
def human_name(options = {})
181-
"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]))
181+
"nomenclatures.#{I18n.escape_key(nomenclature.name)}.items.#{I18n.escape_key(name)}"
182+
.t(options.merge(default: [
183+
"items.#{I18n.escape_key(name)}".to_sym,
184+
"enumerize.#{I18n.escape_key(nomenclature.name)}.#{I18n.escape_key(name)}".to_sym,
185+
"labels.#{I18n.escape_key(name)}".to_sym,
186+
name.humanize
187+
]))
182188
end
183189
alias humanize human_name
184190
alias localize human_name

lib/nomen/nomenclature.rb

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -289,12 +289,7 @@ def table_name
289289

290290
# Returns hash with items in tree: {a => nil, b => {c => nil}}
291291
def tree
292-
x = @roots.collect(&:tree).join
293-
return x
294-
i.attributes.merge(parent: i.parent_name, name: i.name, left: i.left, right: i.right, depth: i.depth).deep_stringify_keys
295-
return x
296-
@roots.map do |_i|
297-
end
292+
@roots.collect(&:tree).join
298293
end
299294

300295
def translateable?
@@ -303,7 +298,7 @@ def translateable?
303298

304299
# Return human name
305300
def human_name(options = {})
306-
"nomenclatures.#{name}.name".t(options.merge(default: ["labels.#{name}".to_sym, name.to_s.humanize]))
301+
"nomenclatures.#{I18n.escape_key(name)}.name".t(options.merge(default: ["labels.#{I18n.escape_key(name)}".to_sym, name.to_s.humanize]))
307302
end
308303
alias humanize human_name
309304

0 commit comments

Comments
 (0)