Cardinalities
-
CARDINALITY_ONE
Matches
i = 1 and v = 0 or i = 0 and v != 0Example Integers:
1Example Decimals:
0.0, 0.9, 0.00, 0.05 -
CARDINALITY_TWO
Matches
i = 2 and v = 0Example Integers:
2 -
CARDINALITY_OTHER
Matches
all other valuesExample Integers:
0, 3, 17, 100, 1000, 10000, 100000, 1000000, …Example Decimals:
1.0, 2.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_TWO": "יומיים", "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. For this right-to-left locale, Lokalized's default BidiIsolation.RTL_LOCALES wraps caller-supplied formatted values with U+2068 FIRST STRONG ISOLATE and U+2069 POP DIRECTIONAL ISOLATE; the expected expressions below show those escapes.
Locale locale = Locale.forLanguageTag("he"); 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: <FSI>1<PDI> יום // U+2068 FIRST STRONG ISOLATE begins bidirectional isolation around a caller-supplied value in right-to-left text // U+2069 POP DIRECTIONAL ISOLATE ends bidirectional isolation around a caller-supplied value in right-to-left text assertEquals("\u2068" + oneFormattedDayCount + "\u2069 יום", strings.get( "Delivery.LeadTime", Map.of("dayCount", oneDayCount, "formattedDayCount", oneFormattedDayCount) )); // CARDINALITY_TWO Number twoDayCount = 2; String twoFormattedDayCount = numberFormat.format(twoDayCount); assertEquals(Cardinality.TWO, Cardinality.forNumber(twoDayCount, locale)); assertEquals("יומיים", strings.get( "Delivery.LeadTime", Map.of("dayCount", twoDayCount, "formattedDayCount", twoFormattedDayCount) )); // CARDINALITY_OTHER Number otherDayCount = 0; String otherFormattedDayCount = numberFormat.format(otherDayCount); assertEquals(Cardinality.OTHER, Cardinality.forNumber(otherDayCount, locale)); // Expected: <FSI>0<PDI> ימים assertEquals("\u2068" + otherFormattedDayCount + "\u2069 ימים", 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_TWO
Matches
CARDINALITY_OTHER -
CARDINALITY_ONE - CARDINALITY_OTHER
Matches
CARDINALITY_OTHER -
CARDINALITY_TWO - CARDINALITY_OTHER
Matches
CARDINALITY_OTHER -
CARDINALITY_OTHER - CARDINALITY_ONE
Matches
CARDINALITY_OTHER -
CARDINALITY_OTHER - CARDINALITY_TWO
Matches
CARDINALITY_OTHER -
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_TWO": "{{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. For this right-to-left locale, Lokalized's default BidiIsolation.RTL_LOCALES wraps caller-supplied formatted values with U+2068 FIRST STRONG ISOLATE and U+2069 POP DIRECTIONAL ISOLATE; the expected expressions below show those escapes.
Locale locale = Locale.forLanguageTag("he"); 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 = 1; String formattedMinDays = numberFormat.format(minDays); Number maxDays = 2; String formattedMaxDays = numberFormat.format(maxDays); String formattedDayRange = formattedMinDays + "-" + formattedMaxDays; assertEquals(Cardinality.OTHER, Cardinality.forRange( Cardinality.forNumber(minDays, locale), Cardinality.forNumber(maxDays, locale), locale )); // Expected: <FSI>1-2<PDI> ימים // U+2068 FIRST STRONG ISOLATE begins bidirectional isolation around a caller-supplied value in right-to-left text // U+2069 POP DIRECTIONAL ISOLATE ends bidirectional isolation around a caller-supplied value in right-to-left text assertEquals("\u2068" + formattedDayRange + "\u2069 ימים", 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: פנו ימינה בפנייה ה-2.
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