mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-01 21:47:16 +00:00
Merge pull request #12826 from chahmedejaz/bugfix/12815-fix-inconsistent-unit-values
Fix Inconsistent Behavior When Editing Products to mg Units in Hungarian Locale
This commit is contained in:
@@ -263,10 +263,12 @@ module Spree
|
||||
|
||||
# Format as per WeightsAndMeasures (todo: re-orgnaise maybe after product/variant refactor)
|
||||
def variant_unit_with_scale
|
||||
# Our code is based upon English based number formatting with a period `.`
|
||||
scale_clean = ActiveSupport::NumberHelper.number_to_rounded(variant_unit_scale,
|
||||
precision: nil,
|
||||
significant: false,
|
||||
strip_insignificant_zeros: true)
|
||||
strip_insignificant_zeros: true,
|
||||
locale: :en)
|
||||
[variant_unit, scale_clean].compact_blank.join("_")
|
||||
end
|
||||
|
||||
|
||||
@@ -26,9 +26,15 @@ class WeightsAndMeasures
|
||||
def self.variant_unit_options
|
||||
available_units_sorted.flat_map do |measurement, measurement_info|
|
||||
measurement_info.filter_map do |scale, unit_info|
|
||||
# Our code is based upon English based number formatting
|
||||
# Some language locales like +hu+ uses a comma(,) for decimal separator
|
||||
# While in English, decimal separator is represented by a period.
|
||||
# e.g. en: 0.001, hu: 0,001
|
||||
# Hence the results become "weight_0,001" for hu while or code recognizes "weight_0.001"
|
||||
scale_clean =
|
||||
ActiveSupport::NumberHelper.number_to_rounded(scale, precision: nil, significant: false,
|
||||
strip_insignificant_zeros: true)
|
||||
strip_insignificant_zeros: true,
|
||||
locale: :en)
|
||||
[
|
||||
"#{I18n.t(measurement)} (#{unit_info['name']})", # Label (eg "Weight (g)")
|
||||
"#{measurement}_#{scale_clean}", # Scale ID (eg "weight_1")
|
||||
|
||||
Reference in New Issue
Block a user