Class: ICU4X::DisplayNames

Inherits:
Object
  • Object
show all
Defined in:
lib/icu4x/yard_docs.rb

Overview

Provides localized display names for languages, regions, and scripts.

Examples:

Language names

names = ICU4X::DisplayNames.new(locale, type: :language)
names.of("ja")  #=> "Japanese"
names.of("en")  #=> "English"

Region names

names = ICU4X::DisplayNames.new(locale, type: :region)
names.of("JP")  #=> "Japan"
names.of("US")  #=> "United States"

Instance Method Summary collapse

Constructor Details

#initialize(locale, provider: nil, type:, style: :long, fallback: :code) ⇒ DisplayNames

Creates a new DisplayNames instance.

Parameters:

  • locale (Locale)

    the locale for display names

  • provider (DataProvider, nil) (defaults to: nil)

    data provider (uses default if nil)

  • type (Symbol)

    display name type: ‘:language`, `:region`, `:script`, or `:locale`

  • style (Symbol) (defaults to: :long)

    display style: ‘:long`, `:short`, or `:narrow`

  • fallback (Symbol) (defaults to: :code)

    fallback behavior: ‘:code` or `:none`

Raises:

  • (DataError)

    if data for the locale is unavailable



861
# File 'lib/icu4x/yard_docs.rb', line 861

def initialize(locale, provider: nil, type:, style: :long, fallback: :code); end

Instance Method Details

#of(code) ⇒ String?

Returns the display name for a code.

Examples:

names.of("ja")  #=> "Japanese"
names.of("XX")  #=> "XX" (with fallback: :code)
names.of("XX")  #=> nil (with fallback: :none)

Parameters:

  • code (String)

    the code to look up (language, region, script, or locale)

Returns:

  • (String, nil)

    the localized display name, or nil if not found (when fallback is ‘:none`)



874
# File 'lib/icu4x/yard_docs.rb', line 874

def of(code); end

#resolved_optionsHash

Returns the resolved options for this instance.

Returns:

  • (Hash)

    options hash with keys:

    • ‘:locale` [String] the resolved locale identifier

    • ‘:type` [Symbol] the display name type

    • ‘:style` [Symbol] the display style

    • ‘:fallback` [Symbol] the fallback behavior



884
# File 'lib/icu4x/yard_docs.rb', line 884

def resolved_options; end