### Usage example for Cldr.Install Source: https://github.com/elixir-cldr/cldr/blob/main/_autodocs/api-reference/install.md Example usage of the installation functions. Shows how to get the config, install a locale, force re-download, and check installation/staleness. ```elixir config = MyApp.Cldr.__cldr__(:config) Cldr.Install.install_locale_name(:fr, config) # compiles-time download Cldr.Install.install_locale_name(:fr, config, force: true) # re-download Cldr.Install.locale_installed?(:fr, config) # true | false Cldr.Install.locale_stale?(:fr, config) # true | false ``` -------------------------------- ### Number formatting examples with MyApp.Cldr.Number.to_string Source: https://github.com/elixir-cldr/cldr/blob/main/README.md These examples show various number formatting options using the Cldr.Number module. They demonstrate default formatting, locale-specific formatting, currency, scientific notation, roman numerals, ordinals, and spellout. The examples are executed in iex and show the expected output. ```elixir iex> MyApp.Cldr.Number.to_string 12345 "12,345" ``` ```elixir iex> MyApp.Cldr.Number.to_string 12345, locale: "fr" "12 345" ``` ```elixir iex> MyApp.Cldr.Number.to_string 12345, locale: "fr", currency: "USD" "12 345,00 $US" ``` ```elixir iex> MyApp.Cldr.Number.to_string 12345, format: "#E0" "1.2345E4" ``` ```elixir iex(> MyApp.Cldr.Number.to_string 1234, format: :roman "MCCXXXIV" ``` ```elixir iex> MyApp.Cldr.Number.to_string 1234, format: :ordinal "1,234th" ``` ```elixir iex> MyApp.Cldr.Number.to_string 1234, format: :spellout "one thousand two hundred thirty-four" ``` -------------------------------- ### Example: territory chain and flags Source: https://github.com/elixir-cldr/cldr/blob/main/_autodocs/api-reference/cldr.md Creates a territory chain for a locale with the 'rg' extension, returning a list of territories. Also gets the flag for a territory, returning an empty string for macro-territories or an error tuple for unknown territories. ```elixir {:ok, chain} = Cldr.territory_chain("en-US-u-rg-CAzzzz", MyApp.Cldr) # {:ok, [:CA, :UN, :"001"]} Cldr.flag(:AU) # "🇦🇺" Cldr.flag(:UX) # {:error, {Cldr.UnknownTerritoryError, # "The territory :UX is unknown"}} ``` -------------------------------- ### Example validations for field modules Source: https://github.com/elixir-cldr/cldr/blob/main/_autodocs/api-reference/validity.md Shows example calls to `validate/1` for Language, Script, Territory, and Variant modules, demonstrating typical return values including statuses like `:regular` and `:obsolete`. ```elixir Cldr.Validity.Language.validate("en") # {:ok, "en", :regular} Cldr.Validity.Language.validate("zzz") # {:error, "zzz"} Cldr.Validity.Script.validate("thai") # {:ok, :Thai, :regular} Cldr.Validity.Territory.validate("gb") # {:ok, :GB, :regular} Cldr.Validity.Variant.validate(["posix"]) # {:ok, ["posix"], :obsolete} ``` -------------------------------- ### tokenize/1 example Source: https://github.com/elixir-cldr/cldr/blob/main/_autodocs/api-reference/accept-language.md Example call to tokenize/1 with a header containing a language range with a quality value. The output shows the resulting list of {quality, language} tuples with the language downcased. ```elixir Cldr.AcceptLanguage.tokenize("da,zh-TW;q=0.3") # [{1.0, "da"}, {0.3, "zh-tw"}] ``` -------------------------------- ### Development configuration for locales Source: https://github.com/elixir-cldr/cldr/blob/main/README.md Example config.exs for development, using a single locale for fast compilation. ```elixir # config/config.exs config :my_app, MyApp.Cldr, # a single locale, for fast compilation in dev / test locales: ["en"] ``` -------------------------------- ### Production configuration for locales and transliterations Source: https://github.com/elixir-cldr/cldr/blob/main/README.md Example config/production.exs with multiple locales and precompiled transliterations, noting that these will take a while to compile. ```elixir # config/production.exs config :my_app, MyApp.Cldr, # these will take a while to compile locales: ["fr", "en", "bs", "si", "ak", "th"], precompile_transliterations: [{:latn, :arab}, {:thai, :latn}] ``` -------------------------------- ### Locale with U extension example Source: https://github.com/elixir-cldr/cldr/blob/main/README.md Demonstrates using the U extension to request a specific timezone and currency format. The example shows the resulting Cldr.LanguageTag struct with the requested extensions. ```elixir iex> MyApp.Cldr.validate_locale "en-AU-u-tz-ausyd-cf-account" {:ok, %Cldr.LanguageTag{ canonical_locale_name: "en-Latn-AU", cldr_locale_name: "en-AU", extensions: %{}, gettext_locale_name: "en", language: "en", language_subtags: [], language_variants: nil, locale: %Cldr.LanguageTag.U{cf: :account, timezone: "Australia/Sydney"}, private_use: [], rbnf_locale_name: "en", requested_locale_name: "en-AU", script: :Latn, territory: :AU, transform: %{} }} ``` -------------------------------- ### Install git-lfs with Homebrew Source: https://github.com/elixir-cldr/cldr/blob/main/DEVELOPMENT.md Install git-lfs using Homebrew and configure it. This must be done before cloning the CLDR repository because the repo contains large objects referenced via git-lfs. ```bash brew install git-lfs git lfs install ``` -------------------------------- ### best_match/2 usage examples Source: https://github.com/elixir-cldr/cldr/blob/main/_autodocs/api-reference/locale-matching.md Examples of best_match/2 with different supported lists. Shows successful matches with distances, an error when no match is found, and a case pattern for handling both outcomes. ```elixir Cldr.Locale.Match.best_match("zh-HK", supported: ["zh", "zh-Hans", "zh-Hant", "en", "fr", "en-Hant"]) # {:ok, "zh-Hant", 5} supported = Cldr.known_gettext_locale_names() # ["bg_BG", "en", "en_GB", "es", "it"] Cldr.Locale.Match.best_match("en-GB", supported: supported) # {:ok, "en_GB", 0} Cldr.Locale.Match.best_match("zh-HK", supported: supported) # {:error, {Cldr.NoMatchingLocale, "No match for desired locales \"zh-HK\""}} # Best-match error handling: case Cldr.Locale.Match.best_match("fr-CA", supported: ["en", "de"]) do {:ok, best, distance} -> IO.puts("Best: #{best} (#{distance})") {:error, {Cldr.NoMatchingLocale, message}} -> IO.puts("No match: #{message}") end ``` -------------------------------- ### Install Maven with Homebrew Source: https://github.com/elixir-cldr/cldr/blob/main/DEVELOPMENT.md Install Maven using Homebrew on macOS. Maven is required to generate the CLDR toolchain and is not installed by default on macOS. ```bash brew install maven ``` -------------------------------- ### Configure OTP-app Scoped Settings Source: https://github.com/elixir-cldr/cldr/blob/main/_autodocs/configuration.md Example of using environment-specific configuration files to override backend settings for different environments. ```elixir # config/dev.exs config :my_app, MyApp.Cldr, locales: ["en"] # config/prod.exs config :my_app, MyApp.Cldr, locales: ["fr", "en", "bs", "si", "ak", "th"], precompile_transliterations: [{:latn, :arab}, {:thai, :latn}] ``` -------------------------------- ### install_locale_name/3 Source: https://github.com/elixir-cldr/cldr/blob/main/_autodocs/api-reference/install.md Installs a single locale. Options only support `:force` (default `false`); if truthy, always re-download. Returns `{:ok, output_file_name}`, `:already_installed`, or `{:error, reason}`. ```elixir def install_locale_name(locale_name, config, options \\ []) ``` -------------------------------- ### install_all_locale_names/1 Source: https://github.com/elixir-cldr/cldr/blob/main/_autodocs/api-reference/install.md Installs every locale in the CLDR repository (`Cldr.Config.all_locale_names/0`). Returns `:ok`. ```elixir def install_all_locale_names(config) ``` -------------------------------- ### Cldr.Locale.new/2 usage example Source: https://github.com/elixir-cldr/cldr/blob/main/_autodocs/api-reference/locale.md Example usage of Cldr.Locale.new/2. Shows matching to the nearest configured locale (en-CN resolves to en-GB) and error handling for an invalid language. ```elixir {:ok, tag} = Cldr.Locale.new("en-CN", MyApp.Cldr) tag.cldr_locale_name # :"en-GB" — nearest configured locale {:error, {Cldr.InvalidLanguageError, _}} = Cldr.Locale.new("zzz", MyApp.Cldr) ``` -------------------------------- ### best_match/2 usage example Source: https://github.com/elixir-cldr/cldr/blob/main/_autodocs/api-reference/accept-language.md Example usage of `best_match/2` showing a successful match returning `{:ok, zh_hant}` and a failure returning `{:error, {Cldr.NoMatchingLocale, _}}` when no configured locale matches. ```elixir {:ok, zh_hant} = Cldr.AcceptLanguage.best_match("da;q=0.1,zh-TW;q=0.3", MyApp.Cldr) # zh_hant.cldr_locale_name == :"zh-Hant" {:error, {Cldr.NoMatchingLocale, _}} = Cldr.AcceptLanguage.best_match("xx,yy;q=0.3", MyApp.Cldr) ``` -------------------------------- ### plural/2 usage examples Source: https://github.com/elixir-cldr/cldr/blob/main/_autodocs/api-reference/gettext.md Example calls to `plural/2` showing plural indices for Polish and English locales, including a POSIX locale name `en_GB`. ```elixir MyApp.Gettext.Plural.plural("pl", 1) # 0 MyApp.Gettext.Plural.plural("pl", 2) # 1 MyApp.Gettext.Plural.plural("pl", 5) # 2 MyApp.Gettext.Plural.plural("en", 112) # 1 MyApp.Gettext.Plural.plural("en_GB", 1) # 0 ``` -------------------------------- ### locale_installed?/2 Source: https://github.com/elixir-cldr/cldr/blob/main/_autodocs/api-reference/install.md Returns a boolean indicating whether the locale is installed. `{:ok, _path}` from `Cldr.Config.locale_path/2` means installed. No locale validity checking. ```elixir def locale_installed?(locale, config) ``` -------------------------------- ### parse/2 examples Source: https://github.com/elixir-cldr/cldr/blob/main/_autodocs/api-reference/accept-language.md Examples of parse/2 with a valid header, an invalid tag, and a mixed header. The valid header returns a list of {quality, LanguageTag} tuples; the invalid tag returns an error tuple; the mixed header returns an {:ok, result} where errors/1 extracts the error tuples. ```elixir {:ok, parsed} = Cldr.AcceptLanguage.parse("da,zh-TW;q=0.3", MyApp.Cldr) # [{1.0, %Cldr.LanguageTag{... da ...}}, {0.3, %Cldr.LanguageTag{... zh-Hant ...}}] Cldr.AcceptLanguage.parse("invalid_tag", MyApp.Cldr) # {:error, {Cldr.LanguageTag.ParseError, # "Expected a BCP47 language tag. Could not parse the remaining \"g\" starting at position 11"}} {:ok, result} = Cldr.AcceptLanguage.parse("da,zh-TW;q=0.3,invalid_tag", MyApp.Cldr) Cldr.AcceptLanguage.errors(result) # [error: {Cldr.LanguageTag.ParseError, ...}] ``` -------------------------------- ### install_known_locale_names/1 Source: https://github.com/elixir-cldr/cldr/blob/main/_autodocs/api-reference/install.md Installs every configured locale by delegating to `Cldr.Locale.Loader.known_locale_names/1` and calling `install_locale_name/2` for each. Called automatically by the backend compiler. ```elixir def install_known_locale_names(config) do config |> Cldr.Locale.Loader.known_locale_names() |> Enum.each(&install_locale_name(&1, config)) :ok end ``` -------------------------------- ### Formatting dates and times with Cldr.DateTime.Relative Source: https://github.com/elixir-cldr/cldr/blob/main/README.md Examples of using MyApp.Cldr.Date.to_string/2, MyApp.Cldr.Time.to_string/2, MyApp.Cldr.DateTime.to_string/2, and MyApp.Cldr.DateTime.Relative.to_string/2 to format dates, times, and relative dates. The examples show default locale and explicit locale ("fr") outputs, including narrow format and large numbers with thousands separators. ```elixir iex> MyApp.Cldr.Date.to_string Date.utc_today() {:ok, "Aug 18, 2017"} iex> MyApp.Cldr.Time.to_string Time.utc_now {:ok, "11:38:55 AM"} iex> MyApp.Cldr.DateTime.to_string DateTime.utc_now {:ok, "Aug 18, 2017, 11:39:08 AM"} iex> MyApp.Cldr.DateTime.Relative.to_string 1, unit: :day, format: :narrow {:ok, "tomorrow"} iex> MyApp.Cldr.DateTime.Relative.to_string(1, unit: :day, locale: "fr") "demain" iex> MyApp.Cldr.DateTime.Relative.to_string(1, unit: :day, format: :narrow) "tomorrow" iex> MyApp.Cldr.DateTime.Relative.to_string(1234, unit: :year) "in 1,234 years" iex> MyApp.Cldr.DateTime.Relative.to_string(1234, unit: :year, locale: "fr") "dans 1 234 ans" ``` -------------------------------- ### Unit localization with Cldr.Unit.to_string/3 Source: https://github.com/elixir-cldr/cldr/blob/main/README.md Shows how to localize units with different formats and how to list available units. The first example uses the default format, the second and third use :long and :short formats, the fourth shows a number with thousands separators, and the last lists all available units. ```elixir iex> MyApp.Cldr.Unit.to_string 123, :gallon "123 gallons" iex> MyApp.Cldr.Unit.to_string 1234, :gallon, format: :long "1 thousand gallons" iex> MyApp.Cldr.Unit.to_string 1234, :gallon, format: :short "1K gallons" iex> MyApp.Cldr.Unit.to_string 1234, :megahertz "1,234 megahertz" iex> MyApp.Cldr.Unit.available_units [:acre, :acre_foot, :ampere, :arc_minute, :arc_second, :astronomical_unit, :bit, :bushel, :byte, :calorie, :carat, :celsius, :centiliter, :centimeter, :century, :cubic_centimeter, :cubic_foot, :cubic_inch, :cubic_kilometer, :cubic_meter, :cubic_mile, :cubic_yard, :cup, :cup_metric, :day, :deciliter, :decimeter, :degree, :fahrenheit, :fathom, :fluid_ounce, :foodcalorie, :foot, :furlong, :g_force, :gallon, :gallon_imperial, :generic, :gigabit, :gigabyte, :gigahertz, :gigawatt, :gram, :hectare, :hectoliter, :hectopascal, :hertz, :horsepower, :hour, :inch, ...] ``` -------------------------------- ### Generated backend wrapper parse!/1 usage Source: https://github.com/elixir-cldr/cldr/blob/main/_autodocs/api-reference/accept-language.md Example of using the generated backend wrapper `MyApp.Cldr.AcceptLanguage.parse!/1`, which does not require a backend argument because it is fixed to the backend. ```elixir MyApp.Cldr.AcceptLanguage.parse!("da,zh-TW;q=0.3") # no backend argument required ``` -------------------------------- ### List formatting with Cldr.List.to_string/2 Source: https://github.com/elixir-cldr/cldr/blob/main/README.md Shows how to format lists in different locales and formats. The first example uses the default format for English, the second uses the :unit_narrow format, and the third uses French. Results are shown as comments. ```elixir iex> MyApp.Cldr.List.to_string(["a", "b", "c"], locale: "en") "a, b, and c" iex> MyApp.Cldr.List.to_string(["a", "b", "c"], locale: "en", format: :unit_narrow) "a b c" iex> MyApp.Cldr.List.to_string(["a", "b", "c"], locale: "fr") "a, b et c" ``` -------------------------------- ### Cldr.Timezone usage examples Source: https://github.com/elixir-cldr/cldr/blob/main/_autodocs/api-reference/helpers.md Shows how to use Cldr.Timezone.get_short_zone/1 and fetch_short_zone/1. get_short_zone returns a map or nil for unknown codes; fetch_short_zone returns {:ok, map} or :error. ```elixir Cldr.Timezone.get_short_zone("ausyd") # %{preferred: nil, territory: :AU, # aliases: ["Australia/Sydney", "Australia/ACT", "Australia/Canberra", "Australia/NSW"]} Cldr.Timezone.get_short_zone("nope") # nil {:ok, zone} = Cldr.Timezone.fetch_short_zone("ausyd") ``` -------------------------------- ### use Cldr Source: https://github.com/elixir-cldr/cldr/blob/main/_autodocs/api-reference/cldr.md Macro that turns the host module into a backend module. It stores options and installs a before_compile hook. ```APIDOC ## use Cldr ### Description Invoking `use Cldr` turns the host module into a *backend* module. Full option reference: [configuration.md](../configuration.md). Generated API: [backend.md](backend.md). ### Macro `defmacro __using__(opts \\ [])` ### Parameters - **opts** (keyword list) - Optional - Options for backend configuration. ### Example ```elixir defmodule MyApp.Cldr do use Cldr, default_locale: "en" end ``` ``` -------------------------------- ### Sigil_l usage examples Source: https://github.com/elixir-cldr/cldr/blob/main/README.md Shows how to use the ~l sigil to create and validate Cldr.LanguageTag structs. The first two examples return validated locales, the third parses without validation, and the fourth demonstrates a complex language tag with extensions. ```elixir iex> import Cldr.LanguageTag.Sigil Cldr.LanguageTag.Sigil # Returns a locale that is valid and known to # the default backend module iex> ~l(en-US) #Cldr.LanguageTag # Same, but specifying the backend module # MyApp.Cldr specifically iex> ~l(en-US|MyApp.Cldr) #Cldr.LanguageTag # The `u` flag will parse and validate # the language tag but it may not be known # as a configured locale iex> ~l(zh)u #Cldr.LanguageTag # Language tags can convey a lot more information # than might be initially expected! iex> ~l(en-u-ca-ethiopic-cu-aud-sd-gbsct-t-d0-lower-k0-extended-m0-ungegn-x-ux) #Cldr.LanguageTag ``` -------------------------------- ### Configure ex_cldr backend with providers and force_locale_download Source: https://github.com/elixir-cldr/cldr/blob/main/README.md Example of a backend module using the Cldr macro with locales, default_locale, and force_locale_download set to Mix.env() == :prod. This configuration forces locale downloads in production to ensure version compatibility. ```elixir defmodule MyApp.Cldr do use Cldr, locales: ["en", "zh"], default_locale: "en", force_locale_download: Mix.env() == :prod end ``` -------------------------------- ### Define a Cldr Backend Module Source: https://github.com/elixir-cldr/cldr/blob/main/_autodocs/configuration.md Example of defining a backend module using the Cldr macro with various configuration options. ```elixir defmodule MyApp.Cldr do use Cldr, default_locale: "en", locales: ["en-*", "fr"], add_fallback_locales: false, gettext: MyApp.Gettext, data_dir: "./priv/cldr", otp_app: :my_app, precompile_number_formats: ["¤¤#,##0.##"], precompile_transliterations: [{:latn, :arab}, {:thai, :latn}], providers: [Cldr.Number], generate_docs: true, force_locale_download: Mix.env() == :prod, https_proxy: nil end ``` -------------------------------- ### locale_from_host/3 example Source: https://github.com/elixir-cldr/cldr/blob/main/_autodocs/api-reference/locale.md Shows the return values of Cldr.Locale.locale_from_host/3 for a generic TLD (com.au) and a non-generic TLD (com.tv). The first call returns {:ok, tag} with en-AU, the second returns an error tuple with Cldr.UnknownLocaleError. ```elixir {:ok, tag} = Cldr.Locale.locale_from_host("a.b.com.au", MyApp.Cldr) # en-AU {:error, {Cldr.UnknownLocaleError, _}} = Cldr.Locale.locale_from_host("a.b.com.tv", MyApp.Cldr) ``` -------------------------------- ### Define a Cldr backend module and use generated functions Source: https://github.com/elixir-cldr/cldr/blob/main/_autodocs/api-reference/backend.md Defines a backend module using `use Cldr` with locales `["en", "fr"]` and default locale `"en"`. Shows example calls to `known_locale_names/0`, `put_locale/1`, `with_locale/2`, and `quote/2` with their expected outputs. ```elixir defmodule MyApp.Cldr do use Cldr, locales: ["en", "fr"], default_locale: "en" end MyApp.Cldr.known_locale_names() # [:en, :fr] MyApp.Cldr.put_locale("fr") # {:ok, %Cldr.LanguageTag{...}} MyApp.Cldr.with_locale("fr", fn -> ... end) MyApp.Cldr.quote("hello", locale: :en) # "“hello”" ``` -------------------------------- ### Create staging and production directories Source: https://github.com/elixir-cldr/cldr/blob/main/DEVELOPMENT.md Create the staging and production directories. ldml2json will exit if they do not exist. ```bash mkdir $CLDR_STAGING mkdir $CLDR_PRODUCTION ``` -------------------------------- ### Call plural_rule/3 on generated Number.PluralRule.Range Source: https://github.com/elixir-cldr/cldr/blob/main/_autodocs/api-reference/plural-rules.md Example call to the generated MyApp.Cldr.Number.PluralRule.Range.plural_rule/3 function, passing a start and end plural type and a locale. For the locale "ar" and the range {:other, :few}, it returns :few. ```elixir MyApp.Cldr.Number.PluralRule.Range.plural_rule(:other, :few, "ar") # :few ``` -------------------------------- ### Cldr.Locale.canonical_language_tag/3 usage example Source: https://github.com/elixir-cldr/cldr/blob/main/_autodocs/api-reference/locale.md Example of canonical_language_tag/3 with add_likely_subtags: false, resulting in nil script and territory. ```elixir {:ok, tag} = Cldr.Locale.canonical_language_tag("en", MyApp.Cldr, add_likely_subtags: false) # tag.script == nil, tag.territory == nil ``` -------------------------------- ### quote/3 usage examples Source: https://github.com/elixir-cldr/cldr/blob/main/_autodocs/api-reference/cldr.md Shows example calls to Cldr.quote/3 with different locales and preferences, producing locale-specific quotation marks. ```elixir Cldr.quote("Quoted String", MyApp.Cldr, locale: :en) # "“Quoted String”" Cldr.quote("Quoted String", MyApp.Cldr, prefer: :variant, locale: :de) # "‚Quoted String‘" ``` -------------------------------- ### nplurals/1 usage examples Source: https://github.com/elixir-cldr/cldr/blob/main/_autodocs/api-reference/gettext.md Example calls to `nplurals/1` showing the number of plural forms for Polish (4) and English (2). ```elixir MyApp.Gettext.Plural.nplurals("pl") # 4 MyApp.Gettext.Plural.nplurals("en") # 2 ``` -------------------------------- ### Configure Maven settings.xml for GitHub token Source: https://github.com/elixir-cldr/cldr/blob/main/DEVELOPMENT.md Create or modify $HOME/.m2/settings.xml to add a Maven server entry with id 'githubicu'. Replace the username and password placeholders with your GitHub user ID and the generated access token (scope read:packages). ```xml githubicu your github user id your access token ``` -------------------------------- ### match_distance/3 usage examples Source: https://github.com/elixir-cldr/cldr/blob/main/_autodocs/api-reference/locale-matching.md Examples of match_distance/3 with various locale pairs and their resulting distances. Distances are CLDR match scores; smaller is better. ```elixir Cldr.Locale.Match.match_distance("en", "en") # 0 Cldr.Locale.Match.match_distance("en-AU", "en") # 5 Cldr.Locale.Match.match_distance("en-AU", "en-GB") # 3 Cldr.Locale.Match.match_distance("zh-HK", "zh-Hant") # 5 Cldr.Locale.Match.match_distance("en", "zh-Hans") # 134 ``` -------------------------------- ### Download ISO currency database with mix cldr.download.iso_currency Source: https://github.com/elixir-cldr/cldr/blob/main/DEVELOPMENT.md Download the up-to-date ISO currency database. ```bash mix cldr.download.iso_currency ``` -------------------------------- ### Cldr.Substitution.parse/1 and substitute/2 usage example Source: https://github.com/elixir-cldr/cldr/blob/main/_autodocs/api-reference/helpers.md Parses a template string and substitutes a list of items, returning the interpolated list. The example shows the expected output for the given input. ```elixir template = Cldr.Substitution.parse("{0} This is something {1}") # [0, " This is something ", 1] Cldr.Substitution.substitute(["a", "b"], template) # ["a", " This is something ", "b"] ``` -------------------------------- ### Plural rule and pluralize usage examples Source: https://github.com/elixir-cldr/cldr/blob/main/_autodocs/api-reference/plural-rules.md Example calls to the generated plural rule functions. Shows plural_rule returning a plural type and pluralize applying a substitution map, including a range input for Arabic. ```elixir MyApp.Cldr.Number.Cardinal.plural_rule(0, "fr") # :one MyApp.Cldr.Number.Ordinal.plural_rule(123, "en") # :other MyApp.Cldr.Number.Cardinal.pluralize(2, "en", %{one: "one", two: "two", other: "other"}) # "two" MyApp.Cldr.Number.Cardinal.pluralize(1..10, "ar", %{one: "one", few: "few", other: "other"}) # "few" ``` -------------------------------- ### plural_type/3 usage examples Source: https://github.com/elixir-cldr/cldr/blob/main/_autodocs/api-reference/plural-rules.md Example calls to plural_type/3 showing the returned plural category for different inputs and options. The first uses the default Cardinal type, the second uses Ordinal, and the third uses a German locale. ```elixir Cldr.Number.PluralRule.plural_type(123) # :other Cldr.Number.PluralRule.plural_type(123, type: Ordinal) # :few Cldr.Number.PluralRule.plural_type(2, locale: "de") # :other ``` -------------------------------- ### Retrieve and compile dependencies Source: https://github.com/elixir-cldr/cldr/blob/main/README.md Commands to fetch and compile the project dependencies after adding ex_cldr to mix.exs. ```elixir mix deps.get mix deps.compile ``` -------------------------------- ### client_locale_file/2 Source: https://github.com/elixir-cldr/cldr/blob/main/_autodocs/api-reference/install.md Returns the path to the client locale file: `Path.join(client_locales_dir(config), "#{locale}.json")`. ```elixir def client_locale_file(locale, config) ``` -------------------------------- ### Backend module configuration with otp_app Source: https://github.com/elixir-cldr/cldr/blob/main/README.md Defines a backend module that reads additional configuration from the :otp_app key. The configuration is looked up under the :my_app key with sub-key MyApp.Cldr. ```elixir # cldr.ex defmodule MyApp.Cldr do use Cldr, otp_app: :my_app, default_locale: "en", gettext: MyApp.Gettext, json_library: Jason, data_dir: "./priv/cldr", precompile_number_formats: ["¤¤#,##0.##"], providers: [Cldr.Number] end ```