icu4x 0.9.0 → 0.11.0
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 +28 -0
- data/Cargo.lock +118 -139
- data/README.md +2 -2
- data/ext/icu4x/Cargo.toml +9 -9
- data/ext/icu4x/src/data_generator.rs +1 -1
- data/ext/icu4x/src/datetime_format.rs +145 -98
- data/ext/icu4x/src/display_names.rs +3 -3
- data/ext/icu4x/src/locale.rs +57 -0
- data/ext/icu4x/src/number_format.rs +3 -7
- data/ext/icu4x/src/relative_time_format.rs +2 -3
- data/ext/icu4x_macros/Cargo.toml +1 -1
- data/lib/icu4x/version.rb +1 -1
- data/lib/icu4x.rb +28 -17
- data/sig/icu4x.rbs +3 -0
- metadata +18 -4
data/lib/icu4x.rb
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require "bigdecimal"
|
|
3
4
|
require "dry-configurable"
|
|
4
5
|
require "pathname"
|
|
5
6
|
|
|
@@ -52,15 +53,9 @@ module ICU4X
|
|
|
52
53
|
|
|
53
54
|
# Error raised when data generation fails
|
|
54
55
|
class DataGeneratorError < Error; end
|
|
55
|
-
end
|
|
56
56
|
|
|
57
|
-
# Define FormattedPart data class for format_to_parts methods
|
|
58
|
-
module ICU4X
|
|
59
57
|
FormattedPart = Data.define(:type, :value)
|
|
60
|
-
end
|
|
61
58
|
|
|
62
|
-
# Enhance the FormattedPart data class
|
|
63
|
-
module ICU4X
|
|
64
59
|
# Represents a part of a formatted string.
|
|
65
60
|
#
|
|
66
61
|
# Used by format_to_parts methods in DateTimeFormat, NumberFormat,
|
|
@@ -74,18 +69,10 @@ module ICU4X
|
|
|
74
69
|
# @return [String] Human-readable representation
|
|
75
70
|
def inspect = "#<ICU4X::FormattedPart type=#{type.inspect} value=#{value.inspect}>"
|
|
76
71
|
end
|
|
77
|
-
end
|
|
78
72
|
|
|
79
|
-
# Define Segment data class for Segmenter
|
|
80
|
-
module ICU4X
|
|
81
73
|
class Segmenter
|
|
82
74
|
Segment = Data.define(:segment, :index, :word_like)
|
|
83
|
-
end
|
|
84
|
-
end
|
|
85
75
|
|
|
86
|
-
# Enhance the Segment data class
|
|
87
|
-
module ICU4X
|
|
88
|
-
class Segmenter
|
|
89
76
|
# Represents a segment of text.
|
|
90
77
|
#
|
|
91
78
|
# @!attribute [r] segment
|
|
@@ -100,12 +87,36 @@ module ICU4X
|
|
|
100
87
|
private :word_like
|
|
101
88
|
end
|
|
102
89
|
end
|
|
103
|
-
end
|
|
104
90
|
|
|
105
|
-
# Enhance the native Locale class
|
|
106
|
-
module ICU4X
|
|
107
91
|
# Represents a BCP 47 locale identifier.
|
|
108
92
|
class Locale
|
|
93
|
+
POSIX_CATEGORIES = %i[collate ctype messages monetary numeric time].freeze
|
|
94
|
+
private_constant :POSIX_CATEGORIES
|
|
95
|
+
|
|
96
|
+
# Creates a Locale from environment variables.
|
|
97
|
+
#
|
|
98
|
+
# Checks LC_ALL, LC_{category}, and LANG in order,
|
|
99
|
+
# parsing each as a POSIX locale. Falls back to "C" if none are valid.
|
|
100
|
+
#
|
|
101
|
+
# @param category [Symbol] POSIX locale category (default: :messages)
|
|
102
|
+
# @return [Locale]
|
|
103
|
+
# @raise [ArgumentError] if category is not a valid POSIX category
|
|
104
|
+
def self.from_env(category: :messages)
|
|
105
|
+
unless POSIX_CATEGORIES.include?(category)
|
|
106
|
+
raise ArgumentError, "unknown locale category: #{category.inspect}"
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
env_name = "LC_#{category.to_s.upcase}"
|
|
110
|
+
[ENV["LC_ALL"], ENV[env_name], ENV["LANG"]].each do |value|
|
|
111
|
+
next if value.nil? || value.empty?
|
|
112
|
+
|
|
113
|
+
return parse_posix(value)
|
|
114
|
+
rescue LocaleError
|
|
115
|
+
next
|
|
116
|
+
end
|
|
117
|
+
parse_posix("C")
|
|
118
|
+
end
|
|
119
|
+
|
|
109
120
|
# @return [String] Human-readable representation
|
|
110
121
|
def inspect = "#<ICU4X::Locale:#{self}>"
|
|
111
122
|
|
data/sig/icu4x.rbs
CHANGED
|
@@ -35,7 +35,10 @@ module ICU4X
|
|
|
35
35
|
def self.available_markers: () -> Array[String]
|
|
36
36
|
end
|
|
37
37
|
|
|
38
|
+
type locale_category = :collate | :ctype | :messages | :monetary | :numeric | :time
|
|
39
|
+
|
|
38
40
|
class Locale
|
|
41
|
+
def self.from_env: (?category: locale_category) -> Locale
|
|
39
42
|
def self.parse_bcp47: (String locale_str) -> Locale
|
|
40
43
|
alias self.parse self.parse_bcp47
|
|
41
44
|
def self.parse_posix: (String posix_str) -> Locale
|
metadata
CHANGED
|
@@ -1,15 +1,29 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: icu4x
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.11.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- OZAWA Sakuro
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-
|
|
11
|
+
date: 2026-05-18 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: bigdecimal
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '4.0'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '4.0'
|
|
13
27
|
- !ruby/object:Gem::Dependency
|
|
14
28
|
name: dry-configurable
|
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -100,14 +114,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
100
114
|
requirements:
|
|
101
115
|
- - ">="
|
|
102
116
|
- !ruby/object:Gem::Version
|
|
103
|
-
version: '3.
|
|
117
|
+
version: '3.3'
|
|
104
118
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
105
119
|
requirements:
|
|
106
120
|
- - ">="
|
|
107
121
|
- !ruby/object:Gem::Version
|
|
108
122
|
version: '0'
|
|
109
123
|
requirements: []
|
|
110
|
-
rubygems_version: 3.
|
|
124
|
+
rubygems_version: 3.5.22
|
|
111
125
|
signing_key:
|
|
112
126
|
specification_version: 4
|
|
113
127
|
summary: Ruby bindings for ICU4X Unicode internationalization library
|