class
ICU::Locale
- ICU::Locale
- Reference
- Object
Overview
Locales
This class provides a high-level wrapper around ICU's locale functionality. It allows querying locale components, getting display names, canonicalizing locale identifiers, and accessing locale-specific data like measurement systems and paper sizes.
See also:
Defined in:
icu/locale.crConstructors
-
.default : Locale
Returns the default locale for the system.
-
.from_language_tag(langtag : String) : Locale
Creates a Locale from a BCP 47 language tag.
-
.new(id : String)
Creates a new Locale instance.
Class Method Summary
-
.available_locales : Array(Locale)
Returns an enumerator for all available locale IDs.
-
.display_keyword(keyword : String, display_locale : String) : String
Returns the display name for a keyword in the specified display locale.
Instance Method Summary
-
#add_keyword_value(keyword_name : String, keyword_value : String) : Locale
Sets the value for a keyword in this locale, returning a new Locale instance.
-
#add_likely_subtags : Locale
Adds likely subtags to the locale ID.
-
#base_name : String
Returns the base name (language, script, country, variant) for this locale.
-
#canonicalize : Locale
Canonicalizes the locale ID.
-
#character_orientation : LayoutType
Returns the character orientation for this locale (Left-to-Right or Right-to-Left).
-
#country : String
Returns the country code for this locale.
-
#delimiter(type : DelimiterType) : String
Returns the delimiter string for the specified type.
-
#display_country(display_locale : String) : String
Returns the display country for this locale in the specified display locale.
-
#display_keyword_value(keyword : String, display_locale : String) : String
Returns the display name for a keyword value in the specified display locale.
-
#display_language(display_locale : String) : String
Returns the display language for this locale in the specified display locale.
-
#display_name(display_locale : String) : String
Returns the display name for this locale in the specified display locale.
-
#display_script(display_locale : String) : String
Returns the display script for this locale in the specified display locale.
-
#display_variant(display_locale : String) : String
Returns the display variant for this locale in the specified display locale.
-
#id : String
Represents a locale identifier string.
-
#keyword_value(keyword_name : String) : String
Returns the value for a keyword in this locale.
-
#keywords : Enumerable(String)
Returns an enumerator for the keywords in this locale.
-
#language : String
Returns the language code for this locale.
-
#line_orientation : LayoutType
Returns the line orientation for this locale (Top-to-Bottom or Bottom-to-Top).
-
#locale_display_pattern : String
Returns the locale display pattern.
-
#locale_separator : String
Returns the locale separator string.
-
#measurement_system : MeasurementSystem
Returns the measurement system for this locale.
-
#minimize_subtags : Locale
Minimizes the subtags of the locale ID.
-
#name : String
Returns the full name (identifier) for this locale.
-
#right_to_left? : Bool
Checks if the character orientation is Right-to-Left.
-
#script : String
Returns the script code for this locale.
-
#to_language_tag(strict : Bool = false) : String
Converts the locale ID to a BCP 47 language tag.
-
#variant : String
Returns the variant code for this locale.
Constructor Detail
Returns the default locale for the system.
ICU::Locale.default # => ICU::Locale.new("en_US") # or your system's default
Creates a Locale from a BCP 47 language tag.
ICU::Locale.from_language_tag("en-US") # => ICU::Locale.new("en_US")
Creates a new Locale instance.
locale = ICU::Locale.new("en_US")
locale = ICU::Locale.new("fr_FR@collation=phonebook")
Class Method Detail
Returns an enumerator for all available locale IDs.
ICU::Locale.available_locales.each { |locale| puts locale.name }
Returns the display name for a keyword in the specified display locale.
ICU::Locale.display_keyword("collation", "en_US") # => "Collation"
Instance Method Detail
Sets the value for a keyword in this locale, returning a new Locale instance.
ICU::Locale.new("fr_FR").set_keyword_value("collation", "phonebook") # => ICU::Locale.new("fr_FR@collation=phonebook")
Adds likely subtags to the locale ID.
ICU::Locale.new("en").add_likely_subtags # => ICU::Locale.new("en_Latn_US")
Returns the base name (language, script, country, variant) for this locale.
ICU::Locale.new("en_US@collation=phonebook").base_name # => "en_US"
Canonicalizes the locale ID.
ICU::Locale.new("en-us").canonicalize # => ICU::Locale.new("en_US")
Returns the character orientation for this locale (Left-to-Right or Right-to-Left).
ICU::Locale.new("en_US").character_orientation # => :LayoutLtr
Returns the country code for this locale.
ICU::Locale.new("en_US").country # => "US"
Returns the delimiter string for the specified type.
ICU::Locale.new("en_US").delimiter(:QuotationStart) # => "“"
Returns the display country for this locale in the specified display locale.
ICU::Locale.new("fr_FR").display_country("en_US") # => "France"
Returns the display name for a keyword value in the specified display locale.
ICU::Locale.new("fr_FR@collation=phonebook").display_keyword_value("collation", "en_US") # => "Phonebook Collation"
Returns the display language for this locale in the specified display locale.
ICU::Locale.new("fr_FR").display_language("en_US") # => "French"
Returns the display name for this locale in the specified display locale.
ICU::Locale.new("fr_FR").display_name("en_US") # => "French (France)"
ICU::Locale.new("en_US").display_name("fr_FR") # => "anglais (États-Unis)"
Returns the display script for this locale in the specified display locale.
ICU::Locale.new("zh-Hans-CN").display_script("en_US") # => "Simplified Han"
Returns the display variant for this locale in the specified display locale.
ICU::Locale.new("en_US_POSIX").display_variant("en_US") # => "POSIX"
Returns the value for a keyword in this locale. Returns an empty string if the keyword is not found.
ICU::Locale.new("fr_FR@collation=phonebook;calendar=gregorian").keyword_value("collation") # => "phonebook"
ICU::Locale.new("en_US").keyword_value("collation") # => ""
Returns an enumerator for the keywords in this locale.
ICU::Locale.new("fr_FR@collation=phonebook;calendar=gregorian").keywords.to_a # => ["collation", "calendar"]
Returns the language code for this locale.
ICU::Locale.new("en_US").language # => "en"
Returns the line orientation for this locale (Top-to-Bottom or Bottom-to-Top).
ICU::Locale.new("en_US").line_orientation # => :LayoutTtb
Returns the locale display pattern.
ICU::Locale.new("en_US").locale_display_pattern # => "{0} ({1})"
Returns the locale separator string.
ICU::Locale.new("en_US").locale_separator # => ", "
Returns the measurement system for this locale.
ICU::Locale.new("en_US").measurement_system # => :Us
Minimizes the subtags of the locale ID.
ICU::Locale.new("en_Latn_US").minimize_subtags # => ICU::Locale.new("en")
Returns the full name (identifier) for this locale.
Same as #id
.
ICU::Locale.new("en_US").name # => "en_US"
Checks if the character orientation is Right-to-Left.
ICU::Locale.new("en_US").right_to_left? # => false
Returns the script code for this locale.
ICU::Locale.new("zh-Hans-CN").script # => "Hans"
Converts the locale ID to a BCP 47 language tag.
ICU::Locale.new("en_US").to_language_tag # => "en-US"
ICU::Locale.new("en_US_POSIX").to_language_tag(strict: true) # => "en-US-posix"
Returns the variant code for this locale.
ICU::Locale.new("en_US_POSIX").variant # => "POSIX"