human_number 0.1.6 → 0.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +18 -1
- data/lib/human_number/locale_support.rb +31 -35
- data/lib/human_number/railtie.rb +2 -2
- data/lib/human_number/version.rb +1 -1
- data/lib/human_number.rb +5 -6
- metadata +15 -15
- /data/{config → lib}/locales/bn.yml +0 -0
- /data/{config → lib}/locales/de.yml +0 -0
- /data/{config → lib}/locales/en-GB.yml +0 -0
- /data/{config → lib}/locales/en-IN.yml +0 -0
- /data/{config → lib}/locales/en.yml +0 -0
- /data/{config → lib}/locales/es.yml +0 -0
- /data/{config → lib}/locales/fr.yml +0 -0
- /data/{config → lib}/locales/hi.yml +0 -0
- /data/{config → lib}/locales/ja.yml +0 -0
- /data/{config → lib}/locales/ko.yml +0 -0
- /data/{config → lib}/locales/ur.yml +0 -0
- /data/{config → lib}/locales/zh-CN.yml +0 -0
- /data/{config → lib}/locales/zh-TW.yml +0 -0
- /data/{config → lib}/locales/zh.yml +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 42fe66194bf6870029efef196173647a511774b68b13faee24f237d665972722
|
4
|
+
data.tar.gz: bceac8e6a9b6ff97f8737c72068b0e2e98f11c2525dc0572c42218376e0389dc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d39a9b87d7e0f1a8e7bcecbf7184931bfb35c48047992772a2635aeac8079cbaeb31a766e3443afa789b4fb9f45a1a69abe194ab0f309098c43e6860b384d052
|
7
|
+
data.tar.gz: ea2765ffb9962d98ec8fcd52db74a877edf20cbaa0dae1903c6d8d6edc748016160695734f0f52ca4279a16e65aae3fa235bcce28ec776376440d736fda709cc
|
data/CHANGELOG.md
CHANGED
@@ -5,7 +5,23 @@ All notable changes to this project will be documented in this file.
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
7
7
|
|
8
|
-
## [0.1.
|
8
|
+
## [0.1.8] - 2025-08-05
|
9
|
+
|
10
|
+
### Fixed
|
11
|
+
- **I18n fallback contamination**: Resolved currency symbol cross-contamination where Korean won symbols (원) appeared for other currencies like CAD due to I18n fallback behavior
|
12
|
+
- **Translation missing errors**: Fixed missing translation errors for various currency/locale combinations
|
13
|
+
- **Rails configuration warnings**: Eliminated Rails configuration warnings in test environment
|
14
|
+
|
15
|
+
### Changed
|
16
|
+
- **Currency native locale mappings**: Corrected CURRENCY_NATIVE_LOCALES to use only accurate locale associations (e.g., CAD now maps to en-CA/fr-CA only, not generic en/fr)
|
17
|
+
- **Locale file organization**: Moved locale files from `config/locales/` to `lib/locales/` for better gem structure
|
18
|
+
|
19
|
+
### Improved
|
20
|
+
- **Rails-i18n integration**: Enhanced loading order and initialization to prevent locale conflicts
|
21
|
+
- **Test infrastructure**: Updated RSpec mocks and test expectations for better reliability
|
22
|
+
- **I18n isolation**: Added `fallback: false` parameter to prevent cross-locale pollution
|
23
|
+
|
24
|
+
## [0.1.0] - 2025-07-31
|
9
25
|
|
10
26
|
### Added
|
11
27
|
|
@@ -86,4 +102,5 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
86
102
|
- **Formatters::Currency**: Currency symbol and format string application
|
87
103
|
- **Clean separation**: Number formatting independent of currency concerns
|
88
104
|
|
105
|
+
[0.1.8]: https://github.com/ether-moon/human_number/releases/tag/v0.1.8
|
89
106
|
[0.1.0]: https://github.com/ether-moon/human_number/releases/tag/v0.1.0
|
@@ -12,50 +12,38 @@ module HumanNumber
|
|
12
12
|
CURRENCY_NATIVE_LOCALES = {
|
13
13
|
"KRW" => [:ko],
|
14
14
|
"JPY" => [:ja],
|
15
|
-
"USD" => [
|
15
|
+
"USD" => %i[en en-US],
|
16
16
|
"EUR" => %i[de fr es it nl],
|
17
|
-
"GBP" => %i[en
|
18
|
-
"CAD" => %i[en
|
17
|
+
"GBP" => %i[en-GB],
|
18
|
+
"CAD" => %i[en-CA fr-CA],
|
19
19
|
"CNY" => %i[zh zh-CN],
|
20
20
|
"CHF" => %i[de fr it],
|
21
|
-
"INR" => %i[hi en],
|
21
|
+
"INR" => %i[hi en-IN],
|
22
22
|
"RUB" => [:ru],
|
23
|
-
"BRL" => %i[pt
|
24
|
-
"MXN" => [
|
25
|
-
"AUD" => %i[en
|
26
|
-
"NZD" => %i[en
|
23
|
+
"BRL" => %i[pt-BR],
|
24
|
+
"MXN" => %i[es-MX],
|
25
|
+
"AUD" => %i[en-AU],
|
26
|
+
"NZD" => %i[en-NZ],
|
27
27
|
"SEK" => [:sv],
|
28
28
|
"NOK" => %i[no nb],
|
29
29
|
"DKK" => [:da],
|
30
|
-
"SGD" => %i[en
|
31
|
-
"HKD" => %i[zh
|
32
|
-
"ZAR" => %i[en
|
30
|
+
"SGD" => %i[en-SG zh-SG],
|
31
|
+
"HKD" => %i[zh-HK en-HK],
|
32
|
+
"ZAR" => %i[en-ZA af],
|
33
33
|
"TRY" => [:tr],
|
34
|
-
"ARS" => %i[es
|
34
|
+
"ARS" => %i[es-AR],
|
35
35
|
"IDR" => [:id],
|
36
36
|
"THB" => [:th],
|
37
|
-
"MYR" => %i[ms en
|
38
|
-
"PHP" => %i[en
|
37
|
+
"MYR" => %i[ms en-MY],
|
38
|
+
"PHP" => %i[en-PH tl],
|
39
39
|
"VND" => [:vi],
|
40
40
|
}.freeze
|
41
41
|
|
42
42
|
# Keys supported for native currency formatting
|
43
|
-
SUPPORTED_NATIVE_CURRENCY_KEYS = %i[unit format
|
43
|
+
SUPPORTED_NATIVE_CURRENCY_KEYS = %i[unit format].freeze
|
44
44
|
|
45
45
|
module_function
|
46
46
|
|
47
|
-
# Returns the primary locale for displaying a currency.
|
48
|
-
# If the user's locale matches a native locale for the currency, use it.
|
49
|
-
# Otherwise, use the first native locale for the currency.
|
50
|
-
#
|
51
|
-
# @param currency_code [String] ISO 4217 currency code (e.g., 'USD', 'EUR')
|
52
|
-
# @param user_locale [Symbol] User's preferred locale
|
53
|
-
# @return [Symbol] Primary locale for currency display
|
54
|
-
def primary_locale_for_currency(currency_code, user_locale)
|
55
|
-
locales = native_locales_for_currency(currency_code)
|
56
|
-
(locales.include?(user_locale.to_sym) ? user_locale.to_sym : locales.first) || :en
|
57
|
-
end
|
58
|
-
|
59
47
|
# Returns the locale to use for currency precision rules in standard formatting.
|
60
48
|
# Always returns the currency's primary native locale to ensure consistent
|
61
49
|
# precision (e.g., USD always shows 2 decimals, JPY shows 0 decimals).
|
@@ -113,16 +101,24 @@ module HumanNumber
|
|
113
101
|
# Return nil for unknown currencies so formatters can fall back appropriately
|
114
102
|
return nil if native_locales_for_currency(currency_code).empty?
|
115
103
|
|
116
|
-
# For native locales,
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
104
|
+
# For native locales and supported keys, try native formatting first
|
105
|
+
# Additional validation: only currencies that actually have native symbols
|
106
|
+
if SUPPORTED_NATIVE_CURRENCY_KEYS.include?(key)
|
107
|
+
if native_locale?(currency_code, locale)
|
108
|
+
native_key = native_currency_key(key)
|
109
|
+
return I18n.t(native_key, locale:) if I18n.exists?(native_key, locale, fallback: false)
|
110
|
+
else
|
111
|
+
# For currency symbols (:unit) and format, use currency's native locale to ensure consistency
|
112
|
+
# (e.g., USD always shows "$1,234.56" format, regardless of display locale)
|
113
|
+
target_locale = native_locales_for_currency(currency_code).first || :en
|
114
|
+
standard_key = currency_key(key)
|
115
|
+
return I18n.t(standard_key, locale: target_locale, default: currency_code)
|
116
|
+
end
|
121
117
|
end
|
122
118
|
|
123
|
-
# For
|
124
|
-
|
125
|
-
I18n.t(
|
119
|
+
# For other keys, use user's requested locale
|
120
|
+
standard_key = currency_key(key)
|
121
|
+
I18n.t(standard_key, locale:)
|
126
122
|
end
|
127
123
|
end
|
128
124
|
end
|
data/lib/human_number/railtie.rb
CHANGED
@@ -16,8 +16,8 @@ module HumanNumber
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
-
initializer "human_number.load_locale_data" do
|
20
|
-
I18n.load_path += Dir[File.expand_path("
|
19
|
+
initializer "human_number.load_locale_data", after: "rails-i18n" do
|
20
|
+
I18n.load_path += Dir[File.expand_path("../locales/*.yml", __dir__)]
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
data/lib/human_number/version.rb
CHANGED
data/lib/human_number.rb
CHANGED
@@ -4,9 +4,6 @@ require "i18n"
|
|
4
4
|
require "action_view"
|
5
5
|
require "rails-i18n"
|
6
6
|
|
7
|
-
# Ensure Rails I18n locales are available
|
8
|
-
I18n.load_path += Dir[File.expand_path("**/*.yml", Gem.loaded_specs["rails-i18n"].full_gem_path)]
|
9
|
-
|
10
7
|
require_relative "human_number/version"
|
11
8
|
require_relative "human_number/locale_support"
|
12
9
|
require_relative "human_number/formatters/number"
|
@@ -15,9 +12,6 @@ require_relative "human_number/formatters/currency"
|
|
15
12
|
module HumanNumber
|
16
13
|
class Error < StandardError; end
|
17
14
|
|
18
|
-
# Load locale files
|
19
|
-
I18n.load_path += Dir[File.expand_path("../config/locales/*.yml", __dir__)]
|
20
|
-
|
21
15
|
extend ActionView::Helpers::NumberHelper
|
22
16
|
|
23
17
|
class << self
|
@@ -213,4 +207,9 @@ module HumanNumber
|
|
213
207
|
end
|
214
208
|
end
|
215
209
|
|
210
|
+
# Load locale files for all environments to ensure availability
|
211
|
+
# locale_files = Dir[File.expand_path("locales/*.yml", __dir__)]
|
212
|
+
# I18n.load_path += locale_files unless (I18n.load_path & locale_files).any?
|
213
|
+
# I18n.backend.reload! if I18n.backend.respond_to?(:reload!)
|
214
|
+
|
216
215
|
require_relative "human_number/railtie" if defined?(Rails::Railtie)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: human_number
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ether Moon
|
@@ -77,20 +77,6 @@ files:
|
|
77
77
|
- Makefile
|
78
78
|
- README.md
|
79
79
|
- Rakefile
|
80
|
-
- config/locales/bn.yml
|
81
|
-
- config/locales/de.yml
|
82
|
-
- config/locales/en-GB.yml
|
83
|
-
- config/locales/en-IN.yml
|
84
|
-
- config/locales/en.yml
|
85
|
-
- config/locales/es.yml
|
86
|
-
- config/locales/fr.yml
|
87
|
-
- config/locales/hi.yml
|
88
|
-
- config/locales/ja.yml
|
89
|
-
- config/locales/ko.yml
|
90
|
-
- config/locales/ur.yml
|
91
|
-
- config/locales/zh-CN.yml
|
92
|
-
- config/locales/zh-TW.yml
|
93
|
-
- config/locales/zh.yml
|
94
80
|
- human_number.gemspec
|
95
81
|
- lib/human_number.rb
|
96
82
|
- lib/human_number/formatters/currency.rb
|
@@ -99,6 +85,20 @@ files:
|
|
99
85
|
- lib/human_number/rails/helpers.rb
|
100
86
|
- lib/human_number/railtie.rb
|
101
87
|
- lib/human_number/version.rb
|
88
|
+
- lib/locales/bn.yml
|
89
|
+
- lib/locales/de.yml
|
90
|
+
- lib/locales/en-GB.yml
|
91
|
+
- lib/locales/en-IN.yml
|
92
|
+
- lib/locales/en.yml
|
93
|
+
- lib/locales/es.yml
|
94
|
+
- lib/locales/fr.yml
|
95
|
+
- lib/locales/hi.yml
|
96
|
+
- lib/locales/ja.yml
|
97
|
+
- lib/locales/ko.yml
|
98
|
+
- lib/locales/ur.yml
|
99
|
+
- lib/locales/zh-CN.yml
|
100
|
+
- lib/locales/zh-TW.yml
|
101
|
+
- lib/locales/zh.yml
|
102
102
|
- scripts/build_and_publish.sh
|
103
103
|
homepage: https://github.com/ether-moon/human_number
|
104
104
|
licenses:
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|