Cardinalities
-
CARDINALITY_ONE
Matches
i = 0 or n = 1Example Integers:
0, 1Example Decimals:
0.0, 1.0, 0.00, 0.04 -
CARDINALITY_OTHER
Matches
all other valuesExample Integers:
2, 17, 100, 1000, 10000, 100000, 1000000, …Example Decimals:
1.1, 2.6, 10.0, 100.0, 1000.0, 10000.0, 100000.0, 1000000.0, …
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
{ "Delivery.LeadTime": { "commentary": "Estimated delivery time, expressed in days.", "translation": "{{leadTime}}", "placeholders": { "leadTime": { "value": "dayCount", "translations": { "CARDINALITY_ONE": "{{formattedDayCount}} दीस", "CARDINALITY_OTHER": "{{formattedDayCount}} दीस" } } } } }
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("kok"); 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_ONE Number oneDayCount = 0; String oneFormattedDayCount = numberFormat.format(oneDayCount); // Expected: 0 दीस assertEquals(oneFormattedDayCount + " दीस", strings.get( "Delivery.LeadTime", Map.of("dayCount", oneDayCount, "formattedDayCount", oneFormattedDayCount) )); // CARDINALITY_OTHER Number otherDayCount = 2; String otherFormattedDayCount = numberFormat.format(otherDayCount); // Expected: 2 दीस assertEquals(otherFormattedDayCount + " दीस", strings.get( "Delivery.LeadTime", Map.of("dayCount", otherDayCount, "formattedDayCount", otherFormattedDayCount) ));
Cardinality Ranges
No explicit CLDR cardinality-range mapping is defined for this language. Cardinality.forRange(...) therefore falls back to the ending cardinality for every range.
Cardinality range example
Because CLDR defines no explicit range mapping for this locale, the ending cardinality selects the result. The selected form wraps a separately formatted display range.
Sample localized strings file
{ "Delivery.Window": { "commentary": "Estimated delivery window, expressed as a range of days.", "translation": "{{window}}", "placeholders": { "window": { "range": { "start": "minDays", "end": "maxDays" }, "translations": { "CARDINALITY_ONE": "{{formattedDayRange}} दीस", "CARDINALITY_OTHER": "{{formattedDayRange}} दीस" } } } } }
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("kok"); 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_ONE range (ending-cardinality fallback) Number minDays = 0; String formattedMinDays = numberFormat.format(minDays); Number maxDays = new java.math.BigDecimal("0.04"); NumberFormat maxDaysFormat = NumberFormat.getNumberInstance(locale); maxDaysFormat.setMinimumFractionDigits(2); maxDaysFormat.setMaximumFractionDigits(2); String formattedMaxDays = maxDaysFormat.format(maxDays); String formattedDayRange = formattedMinDays + "-" + formattedMaxDays; assertEquals(Cardinality.ONE, Cardinality.forRange( Cardinality.forNumber(minDays, locale), Cardinality.forNumber(maxDays, locale), locale )); // Expected: 0-0.04 दीस assertEquals(formattedDayRange + " दीस", strings.get( "Delivery.Window", Map.of("minDays", minDays, "maxDays", maxDays, "formattedDayRange", formattedDayRange) ));
Ordinalities
-
ORDINALITY_ONE
Matches
n = 1Example Integers:
1 -
ORDINALITY_TWO
Matches
n = 2,3Example Integers:
2, 3 -
ORDINALITY_FEW
Matches
n = 4Example Integers:
4 -
ORDINALITY_OTHER
Matches
all other valuesExample Integers:
0, 5, 19, 100, 1000, 10000, 100000, 1000000, …
Addendum: Language Form Rules
The language form expressions above are specified by Unicode Technical Standard #35 and use the following notation:
nabsolute value of the source number (integer and decimals)iinteger digits ofnvnumber of visible fraction digits inn, with trailing zeroswnumber of visible fraction digits inn, without trailing zerosfvisible fractional digits inn, with trailing zerostvisible fractional digits inn, without trailing zerosc/ecompact decimal exponent operands used by some CLDR compact-number rules