Cardinalities
-
CARDINALITY_ZERO
Matches
n = 0Example Integers:
0Example Decimals:
0.0, 0.00, 0.000, 0.0000 -
CARDINALITY_ONE
Matches
n = 1Example Integers:
1Example Decimals:
1.0, 1.00, 1.000, 1.0000 -
CARDINALITY_OTHER
Matches
all other valuesExample Integers:
2, 17, 100, 1000, 10000, 100000, 1000000, …Example Decimals:
0.1, 0.9, 1.1, 1.7, 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 cv 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_ZERO": "Пан улми ҫук.", "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 = "cv"; 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_ZERO const zeroCardinality = 0; const zeroFormattedCardinalityValue = numberFormat.format(zeroCardinality); cardinalityForNumber(zeroCardinality, locale).name; // => "CARDINALITY_ZERO" strings.get("Cardinality.MinimalPair", { cardinalityValue: zeroCardinality, formattedCardinalityValue: zeroFormattedCardinalityValue, }); // => "Пан улми ҫук." // 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 = 2; const otherFormattedCardinalityValue = numberFormat.format(otherCardinality); cardinalityForNumber(otherCardinality, locale).name; // => "CARDINALITY_OTHER" strings.get("Cardinality.MinimalPair", { cardinalityValue: otherCardinality, formattedCardinalityValue: otherFormattedCardinalityValue, }); // => "2 пан улми пур. Вӗсене илесшӗн-и?"
Java
The Java code passes each raw number for cardinality selection and formats its display value separately with NumberFormat.
Locale locale = Locale.forLanguageTag("cv"); 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 zeroCardinality = 0; String zeroFormattedCardinalityValue = numberFormat.format(zeroCardinality); assertEquals(Cardinality.ZERO, Cardinality.forNumber(zeroCardinality, locale)); assertEquals("Пан улми ҫук.", strings.get( "Cardinality.MinimalPair", Map.of( "cardinalityValue", zeroCardinality, "formattedCardinalityValue", zeroFormattedCardinalityValue ) )); // 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 = 2; String otherFormattedCardinalityValue = numberFormat.format(otherCardinality); assertEquals(Cardinality.OTHER, Cardinality.forNumber(otherCardinality, locale)); // Expected: 2 пан улми пур. Вӗсене илесшӗн-и? 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("cv") 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_ZERO let number1 = try NumericValue.forDecimal("0") let category1 = try Cardinality.forNumber(number1, locale: locale.tag) assert(category1 == .zero) // This fixed display value makes the translation assertion reproducible. let display1 = "0" let message1 = try strings.get("Cardinality.MinimalPair", placeholders: [ "cardinalityValue": .number(number1), "formattedCardinalityValue": .text(display1), ]) assert(ExactString(message1) == ExactString("Пан улми ҫук.")) // CARDINALITY_ONE let number2 = try NumericValue.forDecimal("1") let category2 = try Cardinality.forNumber(number2, locale: locale.tag) assert(category2 == .one) // This fixed display value makes the translation assertion reproducible. let display2 = "1" let message2 = try strings.get("Cardinality.MinimalPair", placeholders: [ "cardinalityValue": .number(number2), "formattedCardinalityValue": .text(display2), ]) assert(ExactString(message2) == ExactString("1 пан улми пур. Ӑна илесшӗн-и?")) // CARDINALITY_OTHER let number3 = try NumericValue.forDecimal("2") let category3 = try Cardinality.forNumber(number3, locale: locale.tag) assert(category3 == .other) // This fixed display value makes the translation assertion reproducible. let display3 = "2" let message3 = try strings.get("Cardinality.MinimalPair", placeholders: [ "cardinalityValue": .number(number3), "formattedCardinalityValue": .text(display3), ]) assert(ExactString(message3) == ExactString("2 пан улми пур. Вӗсене илесшӗн-и?"))
Cardinality Ranges
No explicit CLDR cardinality-range mapping is defined for this language, so every range falls back to the ending cardinality.
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