|Labs
Book a DemoPlatform
React (Lingo Compiler)
Alpha
React (MCP)React (i18n)
CLI

Overview

  • @lingo.dev/react

Getting started

  • Quickstart

Reference

  • LingoProvider
  • useLingo
  • Plurals and select
  • Formatting

Formatting

Max PrilutskiyMax Prilutskiy·Updated 8 days ago·3 min read

Every Lingo instance carries a set of formatting methods keyed to the active locale. They're thin wrappers around the native Intl.* APIs — no extra bundle weight, no opinionated defaults beyond the locale string you already provided to LingoProvider.

All methods are pure: pass the same input and locale, get the same output. They're safe to call inside render without memoization.

Numbers#

l.num(value, options?)#

Format a number with locale-aware grouping and decimals.

tsx
l.num(1234567);       // "1,234,567" (en) / "1.234.567" (de) / "1 234 567" (fr)
l.num(3.14159, { maximumFractionDigits: 2 }); // "3.14" (en) / "3,14" (de)

options is forwarded to Intl.NumberFormat.

l.currency(value, code, options?)#

tsx
l.currency(29.99, "USD");   // "$29.99" (en) / "29,99 $US" (fr)
l.currency(29.99, "EUR");   // "€29.99" (en) / "29,99 €" (de)

l.percent(value, options?)#

Pass a decimal (0.156, not 15.6).

tsx
l.percent(0.156);                           // "16%" (en) / "16 %" (fr)
l.percent(0.156, { maximumFractionDigits: 1 }); // "15.6%"

l.unit(value, unit, options?)#

unit is an Intl-recognized unit name (celsius, kilometer-per-hour, megabyte, etc).

tsx
l.unit(32, "celsius");        // "32°C" (en) / "32 °C" (de)
l.unit(120, "kilometer-per-hour"); // "120 km/h"

l.compact(value, options?)#

tsx
l.compact(1234567);    // "1.2M" (en) / "123万" (ja) / "1,2 Mio." (de)
l.compact(950);        // "950"

Dates and time#

l.date(value, options?) / l.time / l.datetime#

Accept Date or epoch milliseconds.

tsx
l.date(new Date());     // "3/16/2026" (en) / "16.03.2026" (de)
l.time(new Date());     // "3:45 PM" (en) / "15:45" (de)
l.datetime(new Date()); // "3/16/2026, 3:45 PM" (en)

l.date(now, { dateStyle: "long" });   // "March 16, 2026"
l.date(now, { weekday: "short", month: "short", day: "numeric" }); // "Mon, Mar 16"

l.relative(value, unit, options?)#

Signed offset — negative for past, positive for future.

tsx
l.relative(-3, "day");       // "3 days ago" (en) / "vor 3 Tagen" (de)
l.relative(2, "hour");       // "in 2 hours"
l.relative(0, "second", { numeric: "auto" }); // "now"

Lists#

l.list(items, options?)#

Locale-aware conjunction. Default style is long with type conjunction ("and").

tsx
l.list(["apples", "oranges", "pears"]); // "apples, oranges, and pears" (en)
                                         // "apples, oranges y pears" (es)
l.list(["red", "blue"], { type: "disjunction" }); // "red or blue"

File sizes#

l.fileSize(bytes)#

Convenience wrapper that picks an appropriate unit (B, KB, MB, GB, TB, PB) and formats the result with locale-aware decimals.

tsx
l.fileSize(1024);          // "1 KB"
l.fileSize(1073741824);    // "1 GB" (en) / "1 Go" (fr)
l.fileSize(1536);          // "1.5 KB"

Display names#

l.displayName(code, type)#

Translate a language, region, script, or currency code into a localized name.

tsx
l.displayName("en", "language");  // "English" (en) / "Englisch" (de) / "Английский" (ru)
l.displayName("US", "region");    // "United States" / "Vereinigte Staaten"
l.displayName("USD", "currency"); // "US Dollar" / "US-Dollar"
l.displayName("Cyrl", "script");  // "Cyrillic" / "Kyrillisch"

Returns undefined if the code isn't recognized for the requested type.

Collation#

l.sort(items, options?)#

Returns a new sorted array — doesn't mutate the input.

tsx
l.sort(["ä", "z", "a"]);   // de: ["a", "ä", "z"]   sv: ["a", "z", "ä"]
l.sort(["File 10", "File 2"], { numeric: true }); // ["File 2", "File 10"]

Segmentation#

l.segment(text, granularity?)#

Locale-aware splitting into graphemes, words, or sentences. Essential for CJK where spaces don't separate words.

tsx
l.segment("Hello world", "word");  // ["Hello", " ", "world"]
l.segment("こんにちは世界", "word"); // ["こんにちは", "世界"]   (ja)
l.segment("café", "grapheme");     // ["c", "a", "f", "é"]

Granularity defaults to "grapheme".

Why thin wrappers?#

Every method delegates to a native Intl formatter — no parsing, no number libraries, no extra dependencies. The runtime keeps the bundle small and lets the platform handle the locale data, which means new locales added to the V8 / SpiderMonkey ICU tables work for free.

The only added value over raw Intl is the locale string — you set it once via <LingoProvider locale="..."> and every formatter reads it from there. If you'd prefer raw Intl (for code outside React), createLingo(locale) gives you the same object without the provider.

Where to next#

  • useLingo — translating strings via l.text and l.rich.
  • Plurals and select — picking forms by count or category.

Was this page helpful?