Cardinalities
-
CARDINALITY_ONE
Matches
v = 0 and i % 10 = 1 and i % 100 != 11Example Integers:
1, 21, 31, 41, 51, 61, 71, 81, 101, 1001, … -
CARDINALITY_FEW
Matches
v = 0 and i % 10 = 2..4 and i % 100 != 12..14Example Integers:
2, 4, 22, 24, 32, 34, 42, 44, 52, 54, 62, 102, 1002, … -
CARDINALITY_MANY
Matches
v = 0 and i % 10 = 0 or v = 0 and i % 10 = 5..9 or v = 0 and i % 100 = 11..14Example Integers:
0, 5, 19, 100, 1000, 10000, 100000, 1000000, … -
CARDINALITY_OTHER
Matches
all other valuesExample Decimals:
0.0, 1.5, 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_FEW": "{{formattedDayCount}} дні", "CARDINALITY_MANY": "{{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("uk"); 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 = 1; String oneFormattedDayCount = numberFormat.format(oneDayCount); assertEquals(Cardinality.ONE, Cardinality.forNumber(oneDayCount, locale)); // Expected: 1 день assertEquals(oneFormattedDayCount + " день", strings.get( "Delivery.LeadTime", Map.of("dayCount", oneDayCount, "formattedDayCount", oneFormattedDayCount) )); // CARDINALITY_FEW Number fewDayCount = 2; String fewFormattedDayCount = numberFormat.format(fewDayCount); assertEquals(Cardinality.FEW, Cardinality.forNumber(fewDayCount, locale)); // Expected: 2 дні assertEquals(fewFormattedDayCount + " дні", strings.get( "Delivery.LeadTime", Map.of("dayCount", fewDayCount, "formattedDayCount", fewFormattedDayCount) )); // CARDINALITY_MANY Number manyDayCount = 0; String manyFormattedDayCount = numberFormat.format(manyDayCount); assertEquals(Cardinality.MANY, Cardinality.forNumber(manyDayCount, locale)); // Expected: 0 днів assertEquals(manyFormattedDayCount + " днів", strings.get( "Delivery.LeadTime", Map.of("dayCount", manyDayCount, "formattedDayCount", manyFormattedDayCount) )); // CARDINALITY_OTHER Number otherDayCount = new java.math.BigDecimal("0.0"); NumberFormat otherDayCountFormat = NumberFormat.getNumberInstance(locale); otherDayCountFormat.setMinimumFractionDigits(1); otherDayCountFormat.setMaximumFractionDigits(1); String otherFormattedDayCount = otherDayCountFormat.format(otherDayCount); assertEquals(Cardinality.OTHER, Cardinality.forNumber(otherDayCount, locale)); // Expected: 0,0 дня assertEquals(otherFormattedDayCount + " дня", 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_ONE - CARDINALITY_ONE
Matches
CARDINALITY_ONE -
CARDINALITY_ONE - CARDINALITY_FEW
Matches
CARDINALITY_FEW -
CARDINALITY_ONE - CARDINALITY_MANY
Matches
CARDINALITY_MANY -
CARDINALITY_ONE - CARDINALITY_OTHER
Matches
CARDINALITY_OTHER -
CARDINALITY_FEW - CARDINALITY_ONE
Matches
CARDINALITY_ONE -
CARDINALITY_FEW - CARDINALITY_FEW
Matches
CARDINALITY_FEW -
CARDINALITY_FEW - CARDINALITY_MANY
Matches
CARDINALITY_MANY -
CARDINALITY_FEW - CARDINALITY_OTHER
Matches
CARDINALITY_OTHER -
CARDINALITY_MANY - CARDINALITY_ONE
Matches
CARDINALITY_ONE -
CARDINALITY_MANY - CARDINALITY_FEW
Matches
CARDINALITY_FEW -
CARDINALITY_MANY - CARDINALITY_MANY
Matches
CARDINALITY_MANY -
CARDINALITY_MANY - CARDINALITY_OTHER
Matches
CARDINALITY_OTHER -
CARDINALITY_OTHER - CARDINALITY_ONE
Matches
CARDINALITY_ONE -
CARDINALITY_OTHER - CARDINALITY_FEW
Matches
CARDINALITY_FEW -
CARDINALITY_OTHER - CARDINALITY_MANY
Matches
CARDINALITY_MANY -
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
{ "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_FEW": "{{formattedDayRange}} дні", "CARDINALITY_MANY": "{{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("uk"); 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 Number minDays = 1; String formattedMinDays = numberFormat.format(minDays); Number maxDays = 21; String formattedMaxDays = numberFormat.format(maxDays); String formattedDayRange = formattedMinDays + "-" + formattedMaxDays; assertEquals(Cardinality.ONE, Cardinality.forRange( Cardinality.forNumber(minDays, locale), Cardinality.forNumber(maxDays, locale), locale )); // Expected: 1-21 день assertEquals(formattedDayRange + " день", strings.get( "Delivery.Window", Map.of("minDays", minDays, "maxDays", maxDays, "formattedDayRange", formattedDayRange) ));
Ordinalities
-
ORDINALITY_FEW
Matches
n % 10 = 3 and n % 100 != 13Example Integers:
3, 23, 33, 43, 53, 63, 73, 83, 103, 1003, … -
ORDINALITY_OTHER
Matches
all other valuesExample Integers:
0, 2, 4, 16, 100, 1000, 10000, 100000, 1000000, …
Ordinality example
This localized strings example uses complete CLDR minimal-pair patterns to demonstrate every Ordinality category defined for the locale.
Source: Unicode CLDR 48.2 uk locale data.
Sample localized strings file
{ "Ordinal.MinimalPair": { "commentary": "Demonstrates every CLDR ordinal category defined for this locale.", "translation": "{{ordinalExample}}", "placeholders": { "ordinalExample": { "value": "ordinalValue", "translations": { "ORDINALITY_FEW": "{{formattedOrdinalValue}}-я дивізія, {{formattedOrdinalValue}}-є коло", "ORDINALITY_OTHER": "{{formattedOrdinalValue}}-а дивізія, {{formattedOrdinalValue}}-е коло" } } } } }
Usage and expected results
The Java code passes each raw number to Ordinality.forNumber(...) and formats its display value separately with NumberFormat.
Locale locale = Locale.forLanguageTag("uk"); 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 // ORDINALITY_FEW Number fewOrdinalValue = 3; String fewFormattedOrdinalValue = numberFormat.format(fewOrdinalValue); assertEquals(Ordinality.FEW, Ordinality.forNumber(fewOrdinalValue, locale)); // Expected: 3-я дивізія, 3-є коло assertEquals( fewFormattedOrdinalValue + "-я дивізія, " + fewFormattedOrdinalValue + "-є коло", strings.get( "Ordinal.MinimalPair", Map.of("ordinalValue", fewOrdinalValue, "formattedOrdinalValue", fewFormattedOrdinalValue) ) ); // ORDINALITY_OTHER Number otherOrdinalValue = 2; String otherFormattedOrdinalValue = numberFormat.format(otherOrdinalValue); assertEquals(Ordinality.OTHER, Ordinality.forNumber(otherOrdinalValue, locale)); // Expected: 2-а дивізія, 2-е коло assertEquals( otherFormattedOrdinalValue + "-а дивізія, " + otherFormattedOrdinalValue + "-е коло", strings.get( "Ordinal.MinimalPair", Map.of("ordinalValue", otherOrdinalValue, "formattedOrdinalValue", otherFormattedOrdinalValue) ) );
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