Class: ICU4X::Locale
- Inherits:
-
Object
- Object
- ICU4X::Locale
- Defined in:
- lib/icu4x.rb,
lib/icu4x/yard_docs.rb
Overview
Represents a Unicode Locale Identifier (BCP 47).
Locale provides parsing and access to locale components such as language, script, region, and extensions.
Class Method Summary collapse
-
.from_env(category: :messages) ⇒ Locale
Creates a Locale from environment variables.
-
.parse(locale_str) ⇒ Locale
Parses a BCP 47 locale identifier string.
-
.parse_posix(posix_str) ⇒ Locale
Parses a POSIX locale string.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Compares two locales for equality.
-
#eql?(other) ⇒ Boolean
Compares two locales for equality (used by Hash).
-
#extensions ⇒ Hash
Returns the locale extensions.
-
#hash ⇒ Integer
Returns the hash code for this locale.
-
#inspect ⇒ String
Returns a human-readable representation for debugging.
-
#language ⇒ String?
Returns the language subtag.
-
#maximize ⇒ Locale
Returns a new locale with likely subtags added.
-
#maximize! ⇒ self?
Maximizes the locale in place using the Add Likely Subtags algorithm (UTS #35).
-
#minimize ⇒ Locale
Returns a new locale with redundant subtags removed.
-
#minimize! ⇒ self?
Minimizes the locale in place using the Remove Likely Subtags algorithm (UTS #35).
-
#region ⇒ String?
Returns the region subtag.
-
#script ⇒ String?
Returns the script subtag.
-
#to_s ⇒ String
Returns the string representation of the locale.
Class Method Details
.from_env(category: :messages) ⇒ Locale
Creates a Locale from environment variables.
Checks LC_ALL, LC_category, and LANG in order, parsing each as a POSIX locale. Falls back to “C” if none are valid.
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/icu4x.rb', line 104 def self.from_env(category: :messages) unless POSIX_CATEGORIES.include?(category) raise ArgumentError, "unknown locale category: #{category.inspect}" end env_name = "LC_#{category.to_s.upcase}" [ENV["LC_ALL"], ENV[env_name], ENV["LANG"]].each do |value| next if value.nil? || value.empty? return parse_posix(value) rescue LocaleError next end parse_posix("C") end |
.parse(locale_str) ⇒ Locale
Parses a BCP 47 locale identifier string.
186 |
# File 'lib/icu4x/yard_docs.rb', line 186 def self.parse(locale_str); end |
.parse_posix(posix_str) ⇒ Locale
Parses a POSIX locale string.
Converts POSIX-style locale identifiers (e.g., “ja_JP.UTF-8”) to Unicode locale format.
202 |
# File 'lib/icu4x/yard_docs.rb', line 202 def self.parse_posix(posix_str); end |
Instance Method Details
#==(other) ⇒ Boolean
Compares two locales for equality.
256 |
# File 'lib/icu4x/yard_docs.rb', line 256 def ==(other); end |
#eql?(other) ⇒ Boolean
Compares two locales for equality (used by Hash).
128 |
# File 'lib/icu4x.rb', line 128 def eql?(other) = self == other |
#extensions ⇒ Hash
Returns the locale extensions.
237 |
# File 'lib/icu4x/yard_docs.rb', line 237 def extensions; end |
#hash ⇒ Integer
Returns the hash code for this locale.
124 |
# File 'lib/icu4x.rb', line 124 def hash = to_s.hash |
#inspect ⇒ String
Returns a human-readable representation for debugging.
121 |
# File 'lib/icu4x.rb', line 121 def inspect = "#<ICU4X::Locale:#{self}>" |
#language ⇒ String?
Returns the language subtag.
208 |
# File 'lib/icu4x/yard_docs.rb', line 208 def language; end |
#maximize ⇒ Locale
Returns a new locale with likely subtags added.
Non-destructive version of #maximize!. The original locale is unchanged.
303 |
# File 'lib/icu4x/yard_docs.rb', line 303 def maximize; end |
#maximize! ⇒ self?
Maximizes the locale in place using the Add Likely Subtags algorithm (UTS #35).
Adds likely script and region subtags based on the language. This is useful for language negotiation.
289 |
# File 'lib/icu4x/yard_docs.rb', line 289 def maximize!; end |
#minimize ⇒ Locale
Returns a new locale with redundant subtags removed.
Non-destructive version of #minimize!. The original locale is unchanged.
337 |
# File 'lib/icu4x/yard_docs.rb', line 337 def minimize; end |
#minimize! ⇒ self?
Minimizes the locale in place using the Remove Likely Subtags algorithm (UTS #35).
Removes redundant script and region subtags that can be inferred. This is useful for language negotiation.
323 |
# File 'lib/icu4x/yard_docs.rb', line 323 def minimize!; end |
#region ⇒ String?
Returns the region subtag.
224 |
# File 'lib/icu4x/yard_docs.rb', line 224 def region; end |
#script ⇒ String?
Returns the script subtag.
218 |
# File 'lib/icu4x/yard_docs.rb', line 218 def script; end |
#to_s ⇒ String
Returns the string representation of the locale.
243 |
# File 'lib/icu4x/yard_docs.rb', line 243 def to_s; end |