Module: ICU4X

Extended by:
Dry::Configurable
Defined in:
lib/icu4x.rb,
lib/icu4x/version.rb,
lib/icu4x/rake_task.rb,
lib/icu4x/yard_docs.rb,
lib/icu4x/data_gem_task.rb

Overview

ICU4X provides internationalization (i18n) functionality for Ruby applications.

This library wraps ICU4X, a Unicode internationalization library written in Rust, providing locale-aware formatting, parsing, and text processing capabilities.

Examples:

Configure data path

ICU4X.configure do |config|
  config.data_path = Pathname.new("data.postcard")
end

Using environment variable

# Set ICU4X_DATA_PATH environment variable
ENV["ICU4X_DATA_PATH"] = "/path/to/data.postcard"

See Also:

Defined Under Namespace

Classes: Collator, DataError, DataGemTask, DataGenerator, DataGeneratorError, DataProvider, DateTimeFormat, DisplayNames, Error, FormattedPart, ListFormat, Locale, LocaleError, NumberFormat, PluralRules, RakeTask, RelativeTimeFormat, Segmenter

Constant Summary collapse

VERSION =

The version of the icu4x gem.

"0.0.0"

Class Method Summary collapse

Class Method Details

.default_providerDataProvider?

Returns the default data provider, lazily loaded from configuration.

The provider is created from ‘config.data_path` or the `ICU4X_DATA_PATH` environment variable. Once created, the provider is cached.

Examples:

ICU4X.configure { |c| c.data_path = Pathname.new("data.postcard") }
provider = ICU4X.default_provider

Returns:

  • (DataProvider, nil)

    the default provider, or nil if not configured



28
29
30
31
32
33
34
35
# File 'lib/icu4x.rb', line 28

def self.default_provider
  @default_provider_mutex.synchronize do
    @default_provider ||= begin
      path = config.data_path || ENV["ICU4X_DATA_PATH"]&.then {|p| Pathname(p) }
      path && DataProvider.from_blob(path)
    end
  end
end

.reset_default_provider!void

This method returns an undefined value.

Resets the cached default data provider.

After calling this method, the next call to default_provider will create a new provider from the current configuration.



39
40
41
42
43
# File 'lib/icu4x.rb', line 39

def self.reset_default_provider!
  @default_provider_mutex.synchronize do
    @default_provider = nil
  end
end