Latvian latviešu

BCP 47 language tag: lv

Lokalized supports cardinality, cardinality range, and ordinality rules for Latvian.

Latvian is most often spoken in Latvia.

Cardinalities

  • CARDINALITY_ZERO

    Matches n % 10 = 0 or n % 100 = 11..19 or v = 2 and f % 100 = 11..19

    Example Integers: 0, 10, 20, 30, 40, 50, 60, 100, 1000, 10000, 100000, 1000000, …

    Example Decimals: 0.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 100.0, 1000.0, 10000.0, 100000.0, 1000000.0, …

  • CARDINALITY_ONE

    Matches n % 10 = 1 and n % 100 != 11 or v = 2 and f % 10 = 1 and f % 100 != 11 or v != 2 and f % 10 = 1

    Example Integers: 1, 21, 31, 41, 51, 61, 71, 81, 101, 1001, …

    Example Decimals: 0.1, 1.0, 1.1, 2.1, 3.1, 4.1, 5.1, 6.1, 7.1, 10.1, 100.1, 1000.1, …

  • CARDINALITY_OTHER

    Matches all other values

    Example Integers: 2, 9, 22, 29, 102, 1002, …

    Example Decimals: 0.2, 0.9, 1.2, 1.9, 10.2, 100.2, 1000.2, …

Cardinality example

This localized strings file selects the localized form of “day” for a delivery estimate. Raw numbers choose the CLDR category; values formatted with the JDK NumberFormat are interpolated for display.

Sample localized strings file
lv.json Localized Strings File (Latvian)
{
  "Delivery.LeadTime": {
    "commentary": "Estimated delivery time, expressed in days.",
    "translation": "{{leadTime}}",
    "placeholders": {
      "leadTime": {
        "value": "dayCount",
        "translations": {
          "CARDINALITY_ZERO": "{{formattedDayCount}} dienu",
          "CARDINALITY_ONE": "{{formattedDayCount}} diena",
          "CARDINALITY_OTHER": "{{formattedDayCount}} dienas"
        }
      }
    }
  }
}
Usage and expected results

The Java code passes each raw number for cardinality selection and formats its display value separately with NumberFormat.

Locale locale = Locale.forLanguageTag("lv");

Strings strings = Strings.withFallbackLocale(locale)
  .localizedStringSupplier(() -> LocalizedStringLoader.loadFromFilesystem(Paths.get("strings")))
  .localeSupplier((matcher) -> matcher.bestMatchFor(locale))
  .build();

NumberFormat numberFormat = NumberFormat.getNumberInstance(locale);

// Raw numbers select language forms; NumberFormat produces the display values

// CARDINALITY_ZERO
Number zeroDayCount = 0;
String zeroFormattedDayCount = numberFormat.format(zeroDayCount);

assertEquals(Cardinality.ZERO, Cardinality.forNumber(zeroDayCount, locale));

// Expected: 0 dienu
assertEquals(zeroFormattedDayCount + " dienu", strings.get(
  "Delivery.LeadTime", Map.of("dayCount", zeroDayCount, "formattedDayCount", zeroFormattedDayCount)
));

// CARDINALITY_ONE
Number oneDayCount = 1;
String oneFormattedDayCount = numberFormat.format(oneDayCount);

assertEquals(Cardinality.ONE, Cardinality.forNumber(oneDayCount, locale));

// Expected: 1 diena
assertEquals(oneFormattedDayCount + " diena", strings.get(
  "Delivery.LeadTime", Map.of("dayCount", oneDayCount, "formattedDayCount", oneFormattedDayCount)
));

// CARDINALITY_OTHER
Number otherDayCount = 2;
String otherFormattedDayCount = numberFormat.format(otherDayCount);

assertEquals(Cardinality.OTHER, Cardinality.forNumber(otherDayCount, locale));

// Expected: 2 dienas
assertEquals(otherFormattedDayCount + " dienas", strings.get(
  "Delivery.LeadTime", Map.of("dayCount", otherDayCount, "formattedDayCount", otherFormattedDayCount)
));

Cardinality Ranges

These are CLDR's explicit range mappings. For any start/end pair not listed, Cardinality.forRange(...) falls back to the ending cardinality.

  • CARDINALITY_ZERO - CARDINALITY_ZERO

    Matches CARDINALITY_OTHER

  • CARDINALITY_ZERO - CARDINALITY_ONE

    Matches CARDINALITY_ONE

  • CARDINALITY_ZERO - CARDINALITY_OTHER

    Matches CARDINALITY_OTHER

  • CARDINALITY_ONE - CARDINALITY_ZERO

    Matches CARDINALITY_OTHER

  • CARDINALITY_ONE - CARDINALITY_ONE

    Matches CARDINALITY_ONE

  • CARDINALITY_ONE - CARDINALITY_OTHER

    Matches CARDINALITY_OTHER

  • CARDINALITY_OTHER - CARDINALITY_ZERO

    Matches CARDINALITY_OTHER

  • CARDINALITY_OTHER - CARDINALITY_ONE

    Matches CARDINALITY_ONE

  • CARDINALITY_OTHER - CARDINALITY_OTHER

    Matches CARDINALITY_OTHER

Cardinality range example

The start and end cardinalities select the locale's CLDR range result. The selected form wraps a separately formatted display range.

Sample localized strings file
lv.json Localized Strings File (Latvian)
{
  "Delivery.Window": {
    "commentary": "Estimated delivery window, expressed as a range of days.",
    "translation": "{{window}}",
    "placeholders": {
      "window": {
        "range": {
          "start": "minDays",
          "end": "maxDays"
        },
        "translations": {
          "CARDINALITY_ZERO": "{{formattedDayRange}} dienu",
          "CARDINALITY_ONE": "{{formattedDayRange}} diena",
          "CARDINALITY_OTHER": "{{formattedDayRange}} dienas"
        }
      }
    }
  }
}
Usage and expected results

The Java code passes raw range endpoints for selection. Because NumberFormat formats one number at a time, it formats both endpoints separately and joins them for display; choose range punctuation appropriate to your application.

Locale locale = Locale.forLanguageTag("lv");

Strings strings = Strings.withFallbackLocale(locale)
  .localizedStringSupplier(() -> LocalizedStringLoader.loadFromFilesystem(Paths.get("strings")))
  .localeSupplier((matcher) -> matcher.bestMatchFor(locale))
  .build();

NumberFormat numberFormat = NumberFormat.getNumberInstance(locale);

// Raw numbers select language forms; NumberFormat produces the display values

// CARDINALITY_OTHER range
Number minDays = 0;
String formattedMinDays = numberFormat.format(minDays);
Number maxDays = 10;
String formattedMaxDays = numberFormat.format(maxDays);
String formattedDayRange = formattedMinDays + "-" + formattedMaxDays;

assertEquals(Cardinality.OTHER, Cardinality.forRange(
  Cardinality.forNumber(minDays, locale),
  Cardinality.forNumber(maxDays, locale),
  locale
));

// Expected: 0-10 dienas
assertEquals(formattedDayRange + " dienas", strings.get(
  "Delivery.Window",
  Map.of("minDays", minDays, "maxDays", maxDays, "formattedDayRange", formattedDayRange)
));

Ordinalities

All ordinal numbers use ORDINALITY_OTHER; no value selects a different form.

Example: Dodieties 2. pagriezienā pa labi..

Addendum: Language Form Rules

The language form expressions above are specified by Unicode Technical Standard #35 and use the following notation:

  • n absolute value of the source number (integer and decimals)
  • i integer digits of n
  • v number of visible fraction digits in n, with trailing zeros
  • w number of visible fraction digits in n, without trailing zeros
  • f visible fractional digits in n, with trailing zeros
  • t visible fractional digits in n, without trailing zeros
  • c/e compact decimal exponent operands used by some CLDR compact-number rules