Cardinalities
-
CARDINALITY_ONE
Matches
n = 1Example Integers:
1Example Decimals:
1.0, 1.00, 1.000, 1.0000 -
CARDINALITY_OTHER
Matches
all other valuesExample Integers:
0, 2, 16, 100, 1000, 10000, 100000, 1000000, …Example Decimals:
0.0, 0.9, 1.1, 1.6, 10.0, 100.0, 1000.0, 10000.0, 100000.0, 1000000.0, …
Cardinality example
This localized strings example uses complete, page-local CLDR minimal-pair patterns to demonstrate every cardinality category defined for the locale. Minimal-pair text contrasts grammatical forms; it is language-reference data, not reusable application copy.
Source: Unicode CLDR 48.2 or locale data.
Sample localized strings file
{ "Cardinality.MinimalPair": { "commentary": "Demonstrates every CLDR cardinal category defined for this locale.", "translation": "{{cardinalityExample}}", "placeholders": { "cardinalityExample": { "value": "cardinalityValue", "translations": { "CARDINALITY_ONE": "{{formattedCardinalityValue}} ଦିନ", "CARDINALITY_OTHER": "{{formattedCardinalityValue}} ଦିନଗୁଡ଼ିକ" } } } } }
Usage and expected results
JavaScript
The JavaScript code passes each raw number for cardinality selection and formats its display value separately with Intl.NumberFormat.
import { cardinalityForNumber, createStrings } from "lokalized"; import { readStringsFromDirectory } from "lokalized/node"; const locale = "or"; const strings = createStrings({ localizedStringSupplier: () => readStringsFromDirectory("strings").catalogs, fallbackLocale: locale, localeSupplier: () => locale, }); const numberFormat = new Intl.NumberFormat(locale); // Raw numbers select language forms; Intl.NumberFormat produces the display values // CARDINALITY_ONE const oneCardinality = 1; const oneFormattedCardinalityValue = numberFormat.format(oneCardinality); cardinalityForNumber(oneCardinality, locale).name; // => "CARDINALITY_ONE" strings.get("Cardinality.MinimalPair", { cardinalityValue: oneCardinality, formattedCardinalityValue: oneFormattedCardinalityValue, }); // => "1 ଦିନ" // CARDINALITY_OTHER const otherCardinality = 0; const otherFormattedCardinalityValue = numberFormat.format(otherCardinality); cardinalityForNumber(otherCardinality, locale).name; // => "CARDINALITY_OTHER" strings.get("Cardinality.MinimalPair", { cardinalityValue: otherCardinality, formattedCardinalityValue: otherFormattedCardinalityValue, }); // => "0 ଦିନଗୁଡ଼ିକ"
Java
The Java code passes each raw number for cardinality selection and formats its display value separately with NumberFormat.
Locale locale = Locale.forLanguageTag("or"); 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 oneCardinality = 1; String oneFormattedCardinalityValue = numberFormat.format(oneCardinality); assertEquals(Cardinality.ONE, Cardinality.forNumber(oneCardinality, locale)); // Expected: 1 ଦିନ assertEquals(oneFormattedCardinalityValue + " ଦିନ", strings.get( "Cardinality.MinimalPair", Map.of("cardinalityValue", oneCardinality, "formattedCardinalityValue", oneFormattedCardinalityValue) )); // CARDINALITY_OTHER Number otherCardinality = 0; String otherFormattedCardinalityValue = numberFormat.format(otherCardinality); assertEquals(Cardinality.OTHER, Cardinality.forNumber(otherCardinality, locale)); // Expected: 0 ଦିନଗୁଡ଼ିକ assertEquals(otherFormattedCardinalityValue + " ଦିନଗୁଡ଼ିକ", strings.get( "Cardinality.MinimalPair", Map.of( "cardinalityValue", otherCardinality, "formattedCardinalityValue", otherFormattedCardinalityValue ) ));
Swift
Swift uses pinned CLDR rules for raw numeric values. The display strings in these assertions are fixed examples; applications format display values separately with Foundation. Default .rtlLocales bidi isolation adds FSI/PDI to interpolated values in right-to-left output.
import Foundation import Lokalized let locale = try LocaleTag("or") let files = try LocalizedStringLoader.loadFromDirectory(URL(fileURLWithPath: "strings")) let catalogs = files.mapValues { LocalizedCatalog(strings: $0.strings) } let strings = try DefaultStrings(configuration: StringsConfiguration( localizedStringSupplier: { catalogs }, localeSupplier: { _ in locale }, fallbackLocale: locale )) // CARDINALITY_ONE let number1 = try NumericValue.forDecimal("1") let category1 = try Cardinality.forNumber(number1, locale: locale.tag) assert(category1 == .one) // This fixed display value makes the translation assertion reproducible. let display1 = "1" let message1 = try strings.get("Cardinality.MinimalPair", placeholders: [ "cardinalityValue": .number(number1), "formattedCardinalityValue": .text(display1), ]) assert(ExactString(message1) == ExactString("1 ଦିନ")) // CARDINALITY_OTHER let number2 = try NumericValue.forDecimal("0") let category2 = try Cardinality.forNumber(number2, locale: locale.tag) assert(category2 == .other) // This fixed display value makes the translation assertion reproducible. let display2 = "0" let message2 = try strings.get("Cardinality.MinimalPair", placeholders: [ "cardinalityValue": .number(number2), "formattedCardinalityValue": .text(display2), ]) assert(ExactString(message2) == ExactString("0 ଦିନଗୁଡ଼ିକ"))
Cardinality Ranges
These are CLDR's explicit range mappings. For any start/end pair not listed, the range falls back to the ending cardinality.
-
CARDINALITY_ONE - CARDINALITY_ONE
Matches
CARDINALITY_OTHER -
CARDINALITY_ONE - CARDINALITY_OTHER
Matches
CARDINALITY_OTHER -
CARDINALITY_OTHER - CARDINALITY_ONE
Matches
CARDINALITY_ONE -
CARDINALITY_OTHER - CARDINALITY_OTHER
Matches
CARDINALITY_OTHER
Ordinalities
-
ORDINALITY_ONE
Matches
n = 1,5,7..9Example Integers:
1, 5, 7, 9 -
ORDINALITY_TWO
Matches
n = 2,3Example Integers:
2, 3 -
ORDINALITY_FEW
Matches
n = 4Example Integers:
4 -
ORDINALITY_MANY
Matches
n = 6Example Integers:
6 -
ORDINALITY_OTHER
Matches
all other valuesExample Integers:
0, 10, 24, 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