### Start MCP Server Source: https://github.com/elixir-localize/localize/blob/main/plans/mcp_server.md Starts the MCP server using the localize_mcp Mix task. The server boots, loads options and examples into ETS, and builds a search index. ```bash mix localize_mcp.start ``` -------------------------------- ### Fractional Digit Formatting Examples Source: https://github.com/elixir-localize/localize/blob/main/guides/number_formatting.md Demonstrates how to control decimal precision using fractional_digits, min_fractional_digits, and max_fractional_digits options. ```elixir iex> Localize.Number.to_string(1234.5, fractional_digits: 4) {:ok, "1,234.5000"} iex> Localize.Number.to_string(1234.56789, max_fractional_digits: 2) {:ok, "1,234.57"} iex> Localize.Number.to_string(1234.5, min_fractional_digits: 3) {:ok, "1,234.500"} iex> Localize.Number.to_string(1234.56789, min_fractional_digits: 1, max_fractional_digits: 3) {:ok, "1,234.568"} ``` -------------------------------- ### MF2 Markup Syntax Examples Source: https://github.com/elixir-localize/localize/blob/main/guides/message_formatting.md Basic syntax for defining link, image, and button markup elements. ```text {#link}click here{/link} {#img src=|photo.jpg| /} {#button type=|submit|}Click me{/button} ``` -------------------------------- ### MCP Server Lifecycle Source: https://github.com/elixir-localize/localize/blob/main/plans/mcp_server.md Illustrates the server lifecycle, from starting the GenServer to handling JSON-RPC frames via stdio. ```text mix localize_mcp.start ↓ GenServer boots, reads priv/mcp/options + priv/mcp/examples into ETS, builds the search index over Code.fetch_docs(Localize.*) and Calendrical.* if loaded. ↓ Stdio framer reads JSON-RPC frames from stdin, dispatches to tool handlers, writes responses to stdout. Logs go to stderr. ``` -------------------------------- ### MCP Metadata File Structure Source: https://github.com/elixir-localize/localize/blob/main/plans/mcp_server.md Shows the directory structure and example files for MCP metadata, including examples, options, and the invocation whitelist. ```text priv/mcp/ examples/ format_number.exs format_date.exs format_currency.exs ... options/ Elixir.Localize.Number.exs Elixir.Localize.Date.exs Elixir.Localize.Unit.exs ... invocable.exs # the whitelist capabilities.exs # capability → suggested mfas search_index.etf # precomputed at hex publish time ``` -------------------------------- ### One-time Setup for Benchmarks Source: https://github.com/elixir-localize/localize/blob/main/guides/performance_comparison.md Fetches dependencies and compiles the necessary modules for running benchmarks. Ensure you are in the ':bench' Mix environment. ```bash MIX_ENV=bench mix deps.get MIX_ENV=bench mix compile ``` -------------------------------- ### Elixir Localize Configuration Example Source: https://github.com/elixir-localize/localize/blob/main/plans/mf2-translate.md Example configuration for Elixir Localize's translation settings, including default model, glossary path, and locale-specific style guides. This configuration is typically placed in config/dev.exs. ```elixir config :localize, :translation, default_model: "claude-sonnet-4-6", glossary: "priv/translation/glossary.md", locale_styles: %{ "ja" => "Use です/ます polite form throughout. Avoid casual contractions.", "fr" => "Use vous form. Avoid anglicisms where a native French term exists.", "de" => "Use Sie form." } ``` -------------------------------- ### Format messages with variables and patterns Source: https://github.com/elixir-localize/localize/blob/main/skills/localize/references/message-format.md Examples demonstrating variable interpolation, keyword bindings, quoted patterns, and local declarations. ```elixir Localize.Message.format("Hello, {$name}!", %{"name" => "Alice"}) #=> {:ok, "Hello, Alice!"} Localize.Message.format("Hello, {$name}!", name: "Alice") # keyword bindings work too #=> {:ok, "Hello, Alice!"} Localize.Message.format("{{Hello {$name}!}}", %{"name" => "World"}) # quoted pattern #=> {:ok, "Hello World!"} Localize.Message.format("Literal \{brace\} and {$x}", %{"x" => 1}) #=> {:ok, "Literal {brace} and 1"} Localize.Message.format(".local $g = {|Welcome|} {{Dear {$name}, {$g}!}}", %{"name" => "Jane"}) #=> {:ok, "Dear Jane, Welcome!"} ``` -------------------------------- ### MF2 Syntax in Gettext PO Files Source: https://github.com/elixir-localize/localize/blob/main/guides/message_formatting.md Example of using MF2 syntax within Gettext message strings. ```text msgid "You have {$count :number} items." msgstr "Sie haben {$count :number} Artikel." ``` -------------------------------- ### Elixir Semantic Skeleton Date Formatting Example Source: https://github.com/elixir-localize/localize/blob/main/plans/semantic-skeletons.md Demonstrates using a semantic skeleton to format a datetime value. This example shows how to specify a locale and a semantic format like 'year_quarter' with a short length, illustrating the fallback mechanism when a direct match is not found. ```elixir Localize.DateTime.to_string(~U[2026-04-30 19:42:26Z], locale: "en-CA", format: semantic(:year_quarter, length: :short)) ``` -------------------------------- ### Use Built-in Formatting Functions Source: https://github.com/elixir-localize/localize/blob/main/skills/localize/references/message-format.md Examples of formatting numbers, dates, units, and lists using various options and locales. ```elixir Localize.Message.format("{$n :number}", %{"n" => 1234.5}, locale: :de) #=> {:ok, "1.234,5"} Localize.Message.format("{$n :number minimumFractionDigits=2}", %{"n" => 42}) #=> {:ok, "42.00"} Localize.Message.format("{$n :number maximumFractionDigits=2}", %{"n" => 3.14159}) #=> {:ok, "3.14"} Localize.Message.format("{$n :number useGrouping=never}", %{"n" => 12345}) #=> {:ok, "12345"} Localize.Message.format("{$n :number numberingSystem=thai}", %{"n" => 1234}) # any valid system name #=> {:ok, "๑,๒๓๔"} Localize.Message.format("{$n :integer}", %{"n" => 4.7}) # truncates #=> {:ok, "4"} Localize.Message.format("{$ratio :percent}", %{"ratio" => 0.85}) # use :percent, not a style option #=> {:ok, "85%"} Localize.Message.format("{$amt :currency currency=EUR}", %{"amt" => 42.5}, locale: :de) #=> {:ok, "42,50\u00A0€"} Localize.Message.format("{$amt :currency currency=USD currencySign=accounting}", %{"amt" => -50}) #=> {:ok, "($50.00)"} Localize.Message.format("{$d :unit unit=kilometer}", %{"d" => 5}) #=> {:ok, "5 kilometers"} Localize.Message.format("{$d :unit unit=kilogram unitDisplay=short}", %{"d" => 2.5}) #=> {:ok, "2.5 kg"} Localize.Message.format("{$d :unit}", %{"d" => Localize.Unit.new!(5, "mile")}) # Localize.Unit carries its own unit #=> {:ok, "5 miles"} Localize.Message.format("{$when :date style=full}", %{"when" => ~D[2026-07-06]}) #=> {:ok, "Monday, July 6, 2026"} Localize.Message.format("{|2026-07-06| :date style=long}") # ISO literals parse #=> {:ok, "July 6, 2026"} Localize.Message.format("{$dt :datetime dateStyle=long timeStyle=short}", %{"dt" => ~N[2026-07-06 14:30:00]}) #=> {:ok, "July 6, 2026, 2:30 PM"} Localize.Message.format("{$x :string}", %{"x" => 42}) # String.Chars coercion #=> {:ok, "42"} Localize.Message.format("{$n :offset add=1}", %{"n" => 5}) # also subtract= #=> {:ok, "6"} Localize.Message.format("{$items :list}", %{"items" => ["apple", "banana", "cherry"]}) #=> {:ok, "apple, banana, and cherry"} Localize.Message.format("{$items :list style=or}", %{"items" => ["red", "green", "blue"]}) #=> {:ok, "red, green, or blue"} Localize.Message.format("{$items :list}", %{"items" => [1234, 5678]}, locale: :de) # elements format locale-aware #=> {:ok, "1.234 und 5.678"} ``` -------------------------------- ### Rounding Mode Examples Source: https://github.com/elixir-localize/localize/blob/main/guides/number_formatting.md Shows how different rounding strategies affect the output when formatting numbers with zero fractional digits. ```elixir iex> Localize.Number.to_string(2.5, fractional_digits: 0, rounding_mode: :half_even) {:ok, "2"} iex> Localize.Number.to_string(2.5, fractional_digits: 0, rounding_mode: :half_up) {:ok, "3"} iex> Localize.Number.to_string(2.5, fractional_digits: 0, rounding_mode: :ceiling) {:ok, "3"} ``` -------------------------------- ### Verify Localize Supervision Tree with Observer Source: https://github.com/elixir-localize/localize/blob/main/guides/supervision.md After starting your application, you can use `:observer.start()` to inspect the supervision tree. Verify that `Localize.Supervisor` is present among your application's children. ```elixir iex> :observer.start() ``` -------------------------------- ### Example: Locale-Default Year-Month-Day Formatting Source: https://github.com/elixir-localize/localize/blob/main/plans/semantic-skeletons.md Demonstrates formatting a date using the locale's default year-month-day format. The format is resolved from a simple atom. ```elixir Localize.DateTime.to_string(~U[2026-04-30 19:42:26Z], locale: "en", format: :year_month_day) ``` -------------------------------- ### Use NIF Backend for Unit Formatting Source: https://github.com/elixir-localize/localize/blob/main/guides/performance.md Example of using the NIF backend for unit-to-string conversion with short format. ```elixir iex> {:ok, unit} = Localize.Unit.new(100, "meter") iex> Localize.Unit.to_string(unit, format: :short, backend: :nif) {:ok, "100 m"} ``` -------------------------------- ### Install Claude Code skill Source: https://github.com/elixir-localize/localize/blob/main/README.md Commands to add and install the Localize skill for Claude Code. ```bash /plugin marketplace add elixir-localize/localize /plugin install localize@localize ``` -------------------------------- ### Format Dates, Times, and Durations Source: https://github.com/elixir-localize/localize/blob/main/skills/localize/SKILL.md Examples for formatting temporal data using style atoms or skeletons. ```elixir Localize.Date.to_string(~D[2026-07-06]) # {:ok, "Jul 6, 2026"} Localize.Date.to_string(~D[2026-07-06], format: :full) # {:ok, "Monday, July 6, 2026"} Localize.DateTime.to_string(dt, format: :yMMMdHm) # skeleton — locale picks the layout Localize.Interval.to_string(~D[2026-07-06], ~D[2026-07-09]) # {:ok, "Jul 6 – 9, 2026"} (thin spaces around the dash) Localize.DateTime.Relative.to_string(-3600) # {:ok, "1 hour ago"} Localize.Duration.to_string(duration) # {:ok, "11 months and 30 days"} ``` -------------------------------- ### Querying Japanese Eras Data with jq Source: https://github.com/elixir-localize/localize/blob/main/plans/japanese_eras.md A collection of command-line examples using 'jq' to query the Japanese eras JSON data for various insights. ```bash # Count rows by status jq -r '.eras | group_by(.status) | map({(.[0].status): length}) | add' plans/japanese_eras_research.json ``` ```bash # All rows needing primary-source verification jq '.eras[] | select(.status == "disputed") | {idx, era, best_pg, pg_disagreement_days}' plans/japanese_eras_research.json ``` ```bash # All Southern Court eras jq '.eras[] | select(.court == "southern") | {idx, era, best_pg}' plans/japanese_eras_research.json ``` ```bash # Confirmed CLDR errors jq '.metadata.known_cldr_errors' plans/japanese_eras_research.json ``` ```bash # Look up a specific era by idx jq '.eras[] | select(.idx == 4)' plans/japanese_eras_research.json ``` -------------------------------- ### Format Units of Measure Source: https://github.com/elixir-localize/localize/blob/main/skills/localize/SKILL.md Examples for creating and formatting units, including conversion and compound identifiers. ```elixir unit = Localize.Unit.new!(3.5, "kilometer") Localize.Unit.to_string(unit) # {:ok, "3.5 kilometers"} Localize.Unit.to_string(unit, format: :short) # {:ok, "3.5 km"} Localize.Unit.convert(unit, "mile") # {:ok, mile-unit} Localize.Unit.to_string(Localize.Unit.new!(5, "curr-usd-per-100-kilometer")) # {:ok, "$5.00 per 100 kilometers"} ``` -------------------------------- ### Execute programmatic search query Source: https://github.com/elixir-localize/localize/blob/main/plans/cldr-49.md Example of using the query DSL to perform a search without parsing a natural-language string. ```elixir import LocalizeEmoji.Query q = and_([tag("man"), not_(tag("smiling")), tag("dark skin tone")]) LocalizeEmoji.search(q, :en) ``` -------------------------------- ### Format Numbers, Currencies, and Plurals Source: https://github.com/elixir-localize/localize/blob/main/skills/localize/SKILL.md Examples for formatting numeric values and determining plural rules based on locale. ```elixir Localize.Number.to_string(1234.5) # {:ok, "1,234.5"} Localize.Number.to_string(1234.5, format: :currency) # {:ok, "$1,234.50"} (currency from locale) Localize.Number.to_string(1234.5, format: :currency, currency: :EUR, locale: :de) # {:ok, "1.234,50 €"} (no-break space before €) Localize.Number.to_string(0.456, format: :percent) # {:ok, "46%"} Localize.Number.to_string(1_234_000, format: :decimal_short) # {:ok, "1.2M"} Localize.Number.to_string(42, format: :ordinal) # {:ok, "42nd"} Localize.Number.PluralRule.plural_type(1, locale: :en) # :one (drive "file" vs "files") Localize.Number.parse("1,234.56") # parse localized input back ``` -------------------------------- ### Define manifest structure for locale assets Source: https://github.com/elixir-localize/localize/blob/main/plans/cldr-49.md Example JSON schema for mapping locale identifiers to their respective file sizes and SHA-256 checksums. ```json { "version": "0.31.0", "generated": "2026-10-25T00:00:00Z", "locales": { "en": {"size": 152398, "sha256": "abc123…"}, "en-AU": {"size": 156102, "sha256": "def456…"}, ... } } ``` -------------------------------- ### Example: Convenience Atom for Date-Time Combination Source: https://github.com/elixir-localize/localize/blob/main/plans/semantic-skeletons.md Illustrates using a convenience atom to specify both date and time components for formatting. The system automatically combines locale-specific date and time patterns. ```elixir Localize.DateTime.to_string(~U[2026-04-30 19:42:26Z], locale: "ja", format: :year_month_day_hour_minute) ``` -------------------------------- ### Set and Get Process Locale Source: https://github.com/elixir-localize/localize/blob/main/guides/migration.md Demonstrates setting the current process locale and retrieving the active locale identifier. ```elixir iex> {:ok, _} = Localize.put_locale(:de) iex> Localize.get_locale().cldr_locale_id :de ``` -------------------------------- ### Use NIF Backend for Number Formatting Source: https://github.com/elixir-localize/localize/blob/main/guides/performance.md Example of using the NIF backend for number-to-string conversion with German locale settings. ```elixir iex> Localize.Number.to_string(1234.5, locale: :de, backend: :nif) {:ok, "1.234,5"} ``` -------------------------------- ### Manage process locale with put, get, and with Source: https://github.com/elixir-localize/localize/blob/main/skills/localize/references/locales-and-config.md Set and retrieve the process-level locale to avoid passing locale options to every formatter function. ```elixir {:ok, _} = Localize.put_locale("fr") Localize.get_locale().cldr_locale_id #=> :fr Localize.with_locale("de", fn -> Localize.Number.to_string(1234.5) end) #=> {:ok, "1.234,5"} Localize.get_locale().cldr_locale_id # with_locale restored :fr #=> :fr {:ok, _} = Localize.put_locale(:en) # back to :en for the rest of this file Localize.get_locale().cldr_locale_id #=> :en ``` -------------------------------- ### Example: Long Form with Weekday and Specific Zone Source: https://github.com/elixir-localize/localize/blob/main/plans/semantic-skeletons.md Shows how to format a date with a long form, including the weekday and a specific zone. It highlights how contradictory zone components are handled. ```elixir import Localize.DateTime.SemanticSkeleton, only: [semantic: 2] Localize.DateTime.to_string(~U[2026-04-30 19:42:26Z], locale: "en", format: semantic(:year_month_day_weekday, length: :long, zone: :specific)) ``` -------------------------------- ### Example CLDR Era Data Source: https://github.com/elixir-localize/localize/blob/main/plans/japanese_eras.md This snippet shows how an era is represented in CLDR data, including the era number and its start date. The start date format requires careful interpretation due to calendar ambiguities. ```elixir [24, %{start: [898, 4, 26]}] # era 24 — 昌泰 (Shōtai) ``` -------------------------------- ### Format Money to Installment String Source: https://github.com/elixir-localize/localize/blob/main/plans/e_commerce.md Formats a money value to display installment payments, such as '4 payments of $25'. It composes Money, a count, and locale-specific phrasing. ```elixir Money.to_installment_string(money, count, options) ``` -------------------------------- ### Convert Between Size Systems Source: https://github.com/elixir-localize/localize/blob/main/plans/product_and_sizes.md Shows how to convert a size from one system to another using `Localize.Size.convert/2`. Supports different conversion strategies like `:nearest`. ```elixir Localize.Size.convert(size, to_system: :eu_de) # {:ok, %Size{...}} | {:error, _} Localize.Size.convert(size, to_system: :uk, strategy: :nearest) ``` -------------------------------- ### Display Language Names Source: https://github.com/elixir-localize/localize/blob/main/guides/migration.md Get localized language names using Localize.Language.display_name. ```elixir # ex_cldr MyApp.Cldr.Language.to_string("de") MyApp.Cldr.Language.to_string("en", locale: "de") # Localize (renamed from to_string to display_name) iex> Localize.Language.display_name("de") {:ok, "German"} iex> Localize.Language.display_name("en", locale: :de) {:ok, "Englisch"} iex> Localize.Language.display_name("en-GB", style: :short) {:ok, "UK English"} ``` -------------------------------- ### Test Significant Digit Formatting Source: https://github.com/elixir-localize/localize/blob/main/plans/cldr-49.md Example usage of the proposed significant digit options in Localize.Number.to_string/2. ```elixir iex> Localize.Number.to_string(1234.5678, minimum_significant_digits: 3) {:ok, "1,230"} iex> Localize.Number.to_string(0.001234, maximum_significant_digits: 2) {:ok, "0.0012"} ``` -------------------------------- ### Format dates with styles and locales Source: https://github.com/elixir-localize/localize/blob/main/skills/localize/references/dates-times.md Demonstrates formatting a date using different style options and locale settings. ```elixir Localize.Date.to_string(~D[2026-07-06], format: :short) #=> {:ok, "7/6/26"} Localize.Date.to_string(~D[2026-07-06], format: :full) #=> {:ok, "Monday, July 6, 2026"} Localize.Date.to_string(~D[2026-07-06], locale: :de) # same :medium, different locale #=> {:ok, "06.07.2026"} Localize.Date.to_string(~D[2026-07-06], locale: :ja) #=> {:ok, "2026/07/06"} ``` -------------------------------- ### Define complex MF2 messages Source: https://github.com/elixir-localize/localize/blob/main/guides/message_formatting.md Examples of complex messages using declarations and quoted patterns. ```text .input {$name :string} {{Hello, {$name}!}} ``` ```text .input {$count :number} .local $greeting = {|Welcome|} .match $count 1 {{You have one item, {$greeting}.}} * {{You have {$count} items, {$greeting}.}} ``` ```text .input {$pronoun :string} .input {$count :number} .match $pronoun $count he one {{He has {$count} notification.}} he * {{He has {$count} notifications.}} she one {{She has {$count} notification.}} she * {{She has {$count} notifications.}} * one {{They have {$count} notification.}} * * {{They have {$count} notifications.}} ``` -------------------------------- ### Define simple MF2 messages Source: https://github.com/elixir-localize/localize/blob/main/guides/message_formatting.md Examples of simple messages containing plain text and placeholders. ```text Hello, world! Hello, {$name}! Today is {$date :date style=medium}. ``` -------------------------------- ### Download locales at build time Source: https://github.com/elixir-localize/localize/blob/main/guides/migration.md Run the mix task to pre-populate the locale cache during the build process. ```bash # At build time (Dockerfile, CI, or local) mix localize.download_locales ``` -------------------------------- ### Project Directory Structure Source: https://github.com/elixir-localize/localize/blob/main/CLDR_UPDATE_INTEGRATION.md Overview of the project layout, distinguishing between build-time source data, runtime ETF files, and the generation pipeline. ```text priv/ ├── cldr/ # Build-time source data (gitignored except essentials) │ ├── bcp47/ # BCP 47 extension key definitions (XML) │ ├── collation/ # Collation tailoring (XML) + FractionalUCA.txt │ ├── external_sources/ # Script_Metadata.csv, iso_currencies.xml │ ├── locales// # Per-locale JSON from CLDR production data │ ├── supplemental_data/ # Supplemental JSON and XML │ ├── validity/ # Validity XML for subtag validation │ └── FractionalUCA.txt # Fractional UCA table (committed — collation + reorder data) │ ├── localize/ # Runtime data (ETF) — committed except locales/ │ ├── locales/.etf # Only en.etf and und.etf committed / packaged │ ├── supplemental_data/*.etf │ ├── validity/*.etf │ ├── locale_hashes.etf # SHA-256 manifest of CDN locale bytes (packaged) │ ├── collation_table.etf, all_locale_names.etf, known_territories.etf, … │ ├── version # CLDR version (e.g. "48.2") │ └── localize_patch_version # "{cldr_version}:{patch}" (e.g. "48.2:1") │ ├── unicode/ # UCD tables (combining_class.txt, general_category.txt) data/ # Pipeline (compiles in :dev/:test only, not in the package) ├── data.ex # Entry points (Localize.Data.*) ├── locale.ex # Per-locale generation (incl. loader transforms) ├── locale_transformer.ex # Struct transforms applied during generation ├── supplemental.ex, validity.ex, collation.ex, plural_rules.ex, … ├── normalize/ # Per-domain JSON normalizers └── mix/tasks/ # Mix tasks (see reference table below) scripts/ ├── ldml2json # Legacy LDML→JSON wrapper (deprecated; misses annotations) └── ldml2json_v2 # Wraps unicode-org/cldr-json's cldr-generate-json.sh (use this) ``` -------------------------------- ### Format data types using Localize Source: https://github.com/elixir-localize/localize/blob/main/README.md Demonstrates formatting numbers, dates, units, lists, and retrieving display names for territories and languages. ```elixir iex> # Numbers iex> Localize.Number.to_string(1_234_567.89) {:ok, "1,234,567.89"} iex> Localize.Number.to_string(0.456, format: :percent) {:ok, "46%"} iex> # Dates iex> Localize.Date.to_string(~D[2025-03-22]) {:ok, "Mar 22, 2025"} iex> Localize.Date.to_string(~D[2025-03-22], format: :long) {:ok, "March 22, 2025"} iex> # Units iex> Localize.Unit.to_string(Localize.Unit.new!(3.5, "kilometer")) {:ok, "3.5 kilometers"} iex> # Lists iex> Localize.List.to_string(["apple", "banana", "cherry"]) {:ok, "apple, banana, and cherry"} iex> # Territories and languages iex> Localize.Territory.display_name(:US) {:ok, "United States"} iex> Localize.Language.display_name(:fr) {:ok, "French"} iex> # Collation iex> Localize.Collation.sort(["banana", "apple", "Cherry"]) ["apple", "banana", "Cherry"] ``` -------------------------------- ### Define message expressions Source: https://github.com/elixir-localize/localize/blob/main/guides/message_formatting.md Examples of various expression patterns including variable references, function annotations, and attributes. ```text {$variable} Variable reference {$count :number} Variable with function {|literal text| :string} Literal with function {:datetime} Function-only (no operand) {$x :number minimumFractionDigits=2} Function with options ``` -------------------------------- ### Create units with numeric values Source: https://github.com/elixir-localize/localize/blob/main/guides/unit_formatting.md Shows how to initialize units using integers, floats, or Decimal types. ```elixir iex> {:ok, unit} = Localize.Unit.new(100, "meter") iex> unit.value 100 iex> {:ok, unit} = Localize.Unit.new(3.14, "kilogram") iex> unit.value 3.14 iex> {:ok, unit} = Localize.Unit.new(Decimal.new("99.99"), "liter") iex> unit.value Decimal.new("99.99") ``` -------------------------------- ### Pluralization via MessageFormat 2 Source: https://github.com/elixir-localize/localize/blob/main/usage-rules.md Example of using MessageFormat 2 for pluralization based on a count. Uses `Localize.Message.format/3`. ```elixir Localize.Message.format( ~S".input {$count :integer}\n.match $count\n one {{{$count} item}}\n * {{{$count} items}}", %{"count" => 3} ) #=> {:ok, "3 items"} ``` -------------------------------- ### Enable NIF Backend via Environment Variable Source: https://github.com/elixir-localize/localize/blob/main/guides/performance.md Alternatively, enable the NIF backend by setting the LOCALIZE_NIF environment variable to true. ```bash export LOCALIZE_NIF=true ``` -------------------------------- ### Create a New Size Source: https://github.com/elixir-localize/localize/blob/main/plans/product_and_sizes.md Demonstrates how to create new size entries using the `Localize.Size.new/4` function. You can specify system, category, value, and optional measurements. ```elixir Localize.Size.new(:us, :womens_dress, 10) Localize.Size.new(:eu_de, :womens_dress, 38, measurements: %{bust: 91}) Localize.Size.new(:intl_alpha, :mens_shirt, "M") ``` -------------------------------- ### Format date and time intervals with Localize Source: https://github.com/elixir-localize/localize/blob/main/skills/localize/references/dates-times.md Demonstrates various interval formatting scenarios including open-ended ranges, locale-specific separators, and custom styles. ```elixir Localize.Interval.to_string(~D[2026-07-06], ~D[2026-07-09]) #=> {:ok, "Jul 6 – 9, 2026"} Localize.Interval.to_string(~D[2026-01-15], ~D[2026-03-20]) # month differs, both shown #=> {:ok, "Jan 15 – Mar 20, 2026"} Localize.Interval.to_string(~D[2026-07-06], ~D[2026-07-09], style: :month_and_day, format: :long) #=> {:ok, "Mon, Jul 6 – Thu, Jul 9"} Localize.Interval.to_string(~D[2026-01-15], ~D[2026-03-20], style: :year_and_month) #=> {:ok, "Jan – Mar 2026"} Localize.Interval.to_string(~D[2026-07-06], nil) # open-ended #=> {:ok, "Jul 6, 2026 –"} Localize.Interval.to_string(~D[2026-07-06], nil, locale: :ja) #=> {:ok, "2026/07/06~"} Localize.Interval.to_string(~T[10:00:00], ~T[12:30:00], prefer: :ascii) #=> {:ok, "10:00:00 AM – 12:30:00 PM"} Localize.Interval.to_string(~N[2026-07-06 12:00:00], ~N[2026-07-06 14:00:00], time_format: :short, prefer: :ascii) #=> {:ok, "Jul 6, 2026, 12:00 PM – 2:00 PM"} Localize.Interval.to_string(nil, nil) #=> {:error, %Localize.DateTimeInvalidInputError{type: :datetime}} ``` -------------------------------- ### Retrieve and use number systems Source: https://github.com/elixir-localize/localize/blob/main/guides/number_formatting.md Demonstrates how to query available number systems for a locale and format a number using a specific system. ```elixir iex> Localize.Number.System.number_systems_for(:ar) {:ok, %{default: :latn, native: :arab}} iex> Localize.Number.to_string(1234, number_system: :arab, locale: :ar) {:ok, "١٬٢٣٤"} ``` -------------------------------- ### Format units with Localize.Unit Source: https://github.com/elixir-localize/localize/blob/main/guides/unit_formatting.md Demonstrates basic unit creation and string formatting with different length options. ```elixir iex> {:ok, unit} = Localize.Unit.new(42, "meter") iex> Localize.Unit.to_string(unit) {:ok, "42 meters"} iex> Localize.Unit.to_string(unit, format: :short) {:ok, "42 m"} iex> Localize.Unit.to_string(unit, format: :narrow) {:ok, "42m"} ``` -------------------------------- ### Locale-Specific Plural Examples Source: https://github.com/elixir-localize/localize/blob/main/guides/plural_rules.md Demonstrates how different locales map numbers to specific grammatical categories like :zero, :two, or :few. ```elixir iex> Localize.Number.PluralRule.plural_type(0, locale: :ar) :zero iex> Localize.Number.PluralRule.plural_type(2, locale: :ar) :two iex> Localize.Number.PluralRule.plural_type(11, locale: :ar) :many iex> Localize.Number.PluralRule.plural_type(2, locale: :cy) :two iex> Localize.Number.PluralRule.plural_type(3, locale: :cy) :few ``` -------------------------------- ### Create Unit Instances Source: https://github.com/elixir-localize/localize/blob/main/cheatsheets/unit_formatting.md Initialize units with values or as display names. Use the bang variant for raising exceptions on invalid inputs. ```elixir {:ok, unit} = Localize.Unit.new(42, "meter") unit = Localize.Unit.new!(42, "meter") # bang variant {:ok, unit} = Localize.Unit.new(3.14, "kilogram") {:ok, unit} = Localize.Unit.new(Decimal.new("99.99"), "liter") {:ok, unit} = Localize.Unit.new("meter") # no value (for display names) ``` -------------------------------- ### Compare LanguageTag parsing methods Source: https://github.com/elixir-localize/localize/blob/main/guides/locale_validation.md Demonstrates the output differences between LanguageTag.parse/1 and LanguageTag.new/1. ```elixir iex> {:ok, parsed} = Localize.LanguageTag.parse("en-US") iex> {parsed.script, parsed.cldr_locale_id} {nil, nil} iex> {:ok, tag} = Localize.LanguageTag.new("zh-TW") iex> {tag.language, tag.script, tag.territory, tag.cldr_locale_id} {:zh, :Hant, :TW, :"zh-Hant"} ``` -------------------------------- ### Replace Invalid Casing with Localize.InvalidValueError Source: https://github.com/elixir-localize/localize/blob/main/plans/exception_structure.md This example shows replacing an `ArgumentError` for an invalid `:casing` value with `Localize.InvalidValueError`. Use this for validating casing options. ```elixir Localize.InvalidValueError{value: other, expected: :casing, allowed_values: [:sensitive, :insensitive]} ``` -------------------------------- ### Pre-populate locale cache in Docker Source: https://github.com/elixir-localize/localize/blob/main/README.md Execute the download command during the build process to ensure locale data is available on disk. ```bash # Dockerfile RUN mix localize.download_locales ``` -------------------------------- ### Retrieve territory display names Source: https://github.com/elixir-localize/localize/blob/main/guides/display_names.md Examples of retrieving territory names using ISO 3166 codes, containment codes, and world codes. ```elixir iex> Localize.Territory.display_name(:GB) {:ok, "United Kingdom"} iex> Localize.Territory.display_name(:EU) {:ok, "European Union"} iex> Localize.Territory.display_name(:"001") {:ok, "world"} iex> Localize.Territory.display_name("US", locale: :fr) {:ok, "États-Unis"} ``` -------------------------------- ### Shorthand Comparison Options Source: https://github.com/elixir-localize/localize/blob/main/cheatsheets/collation.md Shows convenient shorthand options for common comparison adjustments like ignoring accents or case during comparison. ```elixir Localize.Collation.compare("cafe", "café", ignore_accents: true) Localize.Collation.compare("a", "A", ignore_case: true) Localize.Collation.compare("a", "A", casing: :insensitive) ``` -------------------------------- ### Enable NIF Backend in Configuration Source: https://github.com/elixir-localize/localize/blob/main/guides/performance.md Configure the Localize library to use the NIF backend by setting the :nif option to true in your config file. ```elixir # config/config.exs config :localize, :nif, true ```