The Unicode Consortium's Common Locale Data Repository (CLDR) contains tons of high-quality locale data such as formatting rules for dates, times, numbers, currencies as well as language, country, calendar-specific names etc.
For localizing applications in Ruby we obviously want to use this incredibly comprehensive and well-maintained resource.
ruby-cldr
exports the XML-serialized CLDR data as YAML and Ruby files, for consumption in an I18n
context.
ruby-cldr
is a work in progress towards a complete and accurate serialization of the CLDR data as Ruby + YAML files.
There are still a number of issues that need to be addressed before it can be considered production-ready.
- Ruby 2.7+
- Thor
gem install bundler
bundle install
thor cldr:download
By default, the thor cldr:export
command will export all known components from all locales to the target directory:
thor cldr:export
You can also optionally specify locales and/or components to export as well as the target directory:
# Export the `Numbers` and `Plurals` components for the locales `de`, `fr-FR` and `en-ZA` to the `./data` target directory
thor cldr:export --locales de fr-FR en-ZA --components Numbers Plurals --target=./data
CLDR defines a hierarchy of four draft statuses, used to indicate how confident they are in the data: unconfirmed
< provisional
< contributed
< approved
.
By default, ruby-cldr
only exports data with a minimum draft status of contributed
(i.e., contributed
or approved
). This is the same threshold that is used by the Unicode Consortium's International Components for Unicode (ICU).
Set the --draft-status=
parameter to specify the minimum draft status the data needs in order to be exported:
# Export any data with a minimum draft status of `provisional`
# (i.e., `provisional`, `contributed` or `approved`)).
thor cldr:export --draft-status=provisional
bundle exec ruby test/all.rb
unicode-org/cldr
, the official upstream source of CLDR dataunicode-org/cldr-json
, a JSON serialization of the CLDR data- CLDR Markup specification
- Plural Rules table