Skip to content

Commit

Permalink
Fixes #56 again
Browse files Browse the repository at this point in the history
  • Loading branch information
lentschi committed Apr 19, 2024
1 parent bf2633d commit 59ba7ea
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions lib/article_units_lib.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,23 @@ def self.untranslated_units
end

def self.unit_translations
return @unit_translations unless @unit_translations.nil?
@unit_translations = {} if @unit_translations.nil?
unit_translations_cached_in_current_locale = @unit_translations[I18n.locale]
return unit_translations_cached_in_current_locale unless unit_translations_cached_in_current_locale.nil?

@unit_translations = YAML.safe_load(ERB.new(File.read(File.expand_path(
"config/units-of-measure/locales/unece_#{I18n.locale}.yml", Rails.root
))).result) || {}
@unit_translations[I18n.locale] = YAML.safe_load(ERB.new(File.read(File.expand_path(
"config/units-of-measure/locales/unece_#{I18n.locale}.yml", Rails.root
))).result) || {}
end

def self.units
@units = {} if @units.nil?
units_cached_in_current_locale = @units[I18n.locale]
return units_cached_in_current_locale unless @units_cached_in_current_locale.nil?

units = untranslated_units
@units[I18n.locale] = units.to_h do |code, unit|
@units[I18n.locale] = untranslated_units.to_h do |code, untranslated_unit|
translated_name = ArticleUnitsLib.get_translated_name_for_code(code, default_nil: true)
unit = unit.clone
unit = untranslated_unit.clone
unit[:name] = translated_name || unit[:name]
unit[:untranslated] = translated_name.nil?
unit[:symbol] = ArticleUnitsLib.get_translated_symbol_for_code(code)
Expand Down

0 comments on commit 59ba7ea

Please sign in to comment.