Cardinalities
-
CARDINALITY_ONE
Matches
n = 1Example Integers:
1Example Decimals:
1.0, 1.00, 1.000, 1.0000 -
CARDINALITY_TWO
Matches
n = 2Example Integers:
2Example Decimals:
2.0, 2.00, 2.000, 2.0000 -
CARDINALITY_FEW
Matches
n = 3..6Example Integers:
3, 6Example Decimals:
3.0, 4.0, 5.0, 6.0, 3.00, 4.00, 5.00, 6.00, 3.000, 4.000, 5.000, 6.000, 3.0000, 4.0000, 5.0000, 6.0000 -
CARDINALITY_MANY
Matches
n = 7..10Example Integers:
7, 10Example Decimals:
7.0, 8.0, 9.0, 10.0, 7.00, 8.00, 9.00, 10.00, 7.000, 8.000, 9.000, 10.000, 7.0000, 8.0000, 9.0000, 10.0000 -
CARDINALITY_OTHER
Matches
all other valuesExample Integers:
0, 11, 25, 100, 1000, 10000, 100000, 1000000, …Example Decimals:
0.0, 0.9, 1.1, 1.6, 10.1, 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 ga 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}} cheann, {{formattedCardinalityValue}} uair, {{formattedCardinalityValue}} chat, {{formattedCardinalityValue}} éan, {{formattedCardinalityValue}} bhróg", "CARDINALITY_TWO": "{{formattedCardinalityValue}} cheann, {{formattedCardinalityValue}} uair, {{formattedCardinalityValue}} chat, {{formattedCardinalityValue}} éan, {{formattedCardinalityValue}} bhróig", "CARDINALITY_FEW": "{{formattedCardinalityValue}} cinn, {{formattedCardinalityValue}} huaire, {{formattedCardinalityValue}} chat, {{formattedCardinalityValue}} éan, {{formattedCardinalityValue}} bhróg", "CARDINALITY_MANY": "{{formattedCardinalityValue}} gcinn, {{formattedCardinalityValue}} n-uaire, {{formattedCardinalityValue}} gcat, {{formattedCardinalityValue}} n-éan, {{formattedCardinalityValue}} mbróg", "CARDINALITY_OTHER": "{{formattedCardinalityValue}} ceann, {{formattedCardinalityValue}} uair, {{formattedCardinalityValue}} cat, {{formattedCardinalityValue}} éan, {{formattedCardinalityValue}} bróg" } } } } }
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 = "ga"; 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 cheann, 1 uair, 1 chat, 1 éan, 1 bhróg" // CARDINALITY_TWO const twoCardinality = 2; const twoFormattedCardinalityValue = numberFormat.format(twoCardinality); cardinalityForNumber(twoCardinality, locale).name; // => "CARDINALITY_TWO" strings.get("Cardinality.MinimalPair", { cardinalityValue: twoCardinality, formattedCardinalityValue: twoFormattedCardinalityValue, }); // => "2 cheann, 2 uair, 2 chat, 2 éan, 2 bhróig" // CARDINALITY_FEW const fewCardinality = 3; const fewFormattedCardinalityValue = numberFormat.format(fewCardinality); cardinalityForNumber(fewCardinality, locale).name; // => "CARDINALITY_FEW" strings.get("Cardinality.MinimalPair", { cardinalityValue: fewCardinality, formattedCardinalityValue: fewFormattedCardinalityValue, }); // => "3 cinn, 3 huaire, 3 chat, 3 éan, 3 bhróg" // CARDINALITY_MANY const manyCardinality = 7; const manyFormattedCardinalityValue = numberFormat.format(manyCardinality); cardinalityForNumber(manyCardinality, locale).name; // => "CARDINALITY_MANY" strings.get("Cardinality.MinimalPair", { cardinalityValue: manyCardinality, formattedCardinalityValue: manyFormattedCardinalityValue, }); // => "7 gcinn, 7 n-uaire, 7 gcat, 7 n-éan, 7 mbróg" // 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 ceann, 0 uair, 0 cat, 0 éan, 0 bróg"
Java
The Java code passes each raw number for cardinality selection and formats its display value separately with NumberFormat.
Locale locale = Locale.forLanguageTag("ga"); 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 cheann, 1 uair, 1 chat, 1 éan, 1 bhróg assertEquals( oneFormattedCardinalityValue + " cheann, " + oneFormattedCardinalityValue + " uair, " + oneFormattedCardinalityValue + " chat, " + oneFormattedCardinalityValue + " éan, " + oneFormattedCardinalityValue + " bhróg", strings.get( "Cardinality.MinimalPair", Map.of( "cardinalityValue", oneCardinality, "formattedCardinalityValue", oneFormattedCardinalityValue ) ) ); // CARDINALITY_TWO Number twoCardinality = 2; String twoFormattedCardinalityValue = numberFormat.format(twoCardinality); assertEquals(Cardinality.TWO, Cardinality.forNumber(twoCardinality, locale)); // Expected: 2 cheann, 2 uair, 2 chat, 2 éan, 2 bhróig assertEquals( twoFormattedCardinalityValue + " cheann, " + twoFormattedCardinalityValue + " uair, " + twoFormattedCardinalityValue + " chat, " + twoFormattedCardinalityValue + " éan, " + twoFormattedCardinalityValue + " bhróig", strings.get( "Cardinality.MinimalPair", Map.of( "cardinalityValue", twoCardinality, "formattedCardinalityValue", twoFormattedCardinalityValue ) ) ); // CARDINALITY_FEW Number fewCardinality = 3; String fewFormattedCardinalityValue = numberFormat.format(fewCardinality); assertEquals(Cardinality.FEW, Cardinality.forNumber(fewCardinality, locale)); // Expected: 3 cinn, 3 huaire, 3 chat, 3 éan, 3 bhróg assertEquals( fewFormattedCardinalityValue + " cinn, " + fewFormattedCardinalityValue + " huaire, " + fewFormattedCardinalityValue + " chat, " + fewFormattedCardinalityValue + " éan, " + fewFormattedCardinalityValue + " bhróg", strings.get( "Cardinality.MinimalPair", Map.of( "cardinalityValue", fewCardinality, "formattedCardinalityValue", fewFormattedCardinalityValue ) ) ); // CARDINALITY_MANY Number manyCardinality = 7; String manyFormattedCardinalityValue = numberFormat.format(manyCardinality); assertEquals(Cardinality.MANY, Cardinality.forNumber(manyCardinality, locale)); // Expected: 7 gcinn, 7 n-uaire, 7 gcat, 7 n-éan, 7 mbróg assertEquals( manyFormattedCardinalityValue + " gcinn, " + manyFormattedCardinalityValue + " n-uaire, " + manyFormattedCardinalityValue + " gcat, " + manyFormattedCardinalityValue + " n-éan, " + manyFormattedCardinalityValue + " mbróg", strings.get( "Cardinality.MinimalPair", Map.of( "cardinalityValue", manyCardinality, "formattedCardinalityValue", manyFormattedCardinalityValue ) ) ); // CARDINALITY_OTHER Number otherCardinality = 0; String otherFormattedCardinalityValue = numberFormat.format(otherCardinality); assertEquals(Cardinality.OTHER, Cardinality.forNumber(otherCardinality, locale)); // Expected: 0 ceann, 0 uair, 0 cat, 0 éan, 0 bróg assertEquals( otherFormattedCardinalityValue + " ceann, " + otherFormattedCardinalityValue + " uair, " + otherFormattedCardinalityValue + " cat, " + otherFormattedCardinalityValue + " éan, " + otherFormattedCardinalityValue + " bróg", 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("ga") 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 cheann, 1 uair, 1 chat, 1 éan, 1 bhróg")) // CARDINALITY_TWO let number2 = try NumericValue.forDecimal("2") let category2 = try Cardinality.forNumber(number2, locale: locale.tag) assert(category2 == .two) // This fixed display value makes the translation assertion reproducible. let display2 = "2" let message2 = try strings.get("Cardinality.MinimalPair", placeholders: [ "cardinalityValue": .number(number2), "formattedCardinalityValue": .text(display2), ]) assert(ExactString(message2) == ExactString("2 cheann, 2 uair, 2 chat, 2 éan, 2 bhróig")) // CARDINALITY_FEW let number3 = try NumericValue.forDecimal("3") let category3 = try Cardinality.forNumber(number3, locale: locale.tag) assert(category3 == .few) // This fixed display value makes the translation assertion reproducible. let display3 = "3" let message3 = try strings.get("Cardinality.MinimalPair", placeholders: [ "cardinalityValue": .number(number3), "formattedCardinalityValue": .text(display3), ]) assert(ExactString(message3) == ExactString("3 cinn, 3 huaire, 3 chat, 3 éan, 3 bhróg")) // CARDINALITY_MANY let number4 = try NumericValue.forDecimal("7") let category4 = try Cardinality.forNumber(number4, locale: locale.tag) assert(category4 == .many) // This fixed display value makes the translation assertion reproducible. let display4 = "7" let message4 = try strings.get("Cardinality.MinimalPair", placeholders: [ "cardinalityValue": .number(number4), "formattedCardinalityValue": .text(display4), ]) assert(ExactString(message4) == ExactString("7 gcinn, 7 n-uaire, 7 gcat, 7 n-éan, 7 mbróg")) // CARDINALITY_OTHER let number5 = try NumericValue.forDecimal("0") let category5 = try Cardinality.forNumber(number5, locale: locale.tag) assert(category5 == .other) // This fixed display value makes the translation assertion reproducible. let display5 = "0" let message5 = try strings.get("Cardinality.MinimalPair", placeholders: [ "cardinalityValue": .number(number5), "formattedCardinalityValue": .text(display5), ]) assert(ExactString(message5) == ExactString("0 ceann, 0 uair, 0 cat, 0 éan, 0 bróg"))
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_TWO
Matches
CARDINALITY_TWO -
CARDINALITY_ONE - CARDINALITY_FEW
Matches
CARDINALITY_FEW -
CARDINALITY_ONE - CARDINALITY_MANY
Matches
CARDINALITY_MANY -
CARDINALITY_ONE - CARDINALITY_OTHER
Matches
CARDINALITY_OTHER -
CARDINALITY_TWO - CARDINALITY_FEW
Matches
CARDINALITY_FEW -
CARDINALITY_TWO - CARDINALITY_MANY
Matches
CARDINALITY_MANY -
CARDINALITY_TWO - CARDINALITY_OTHER
Matches
CARDINALITY_OTHER -
CARDINALITY_FEW - CARDINALITY_FEW
Matches
CARDINALITY_FEW -
CARDINALITY_FEW - CARDINALITY_MANY
Matches
CARDINALITY_MANY -
CARDINALITY_FEW - CARDINALITY_OTHER
Matches
CARDINALITY_OTHER -
CARDINALITY_MANY - CARDINALITY_MANY
Matches
CARDINALITY_MANY -
CARDINALITY_MANY - CARDINALITY_OTHER
Matches
CARDINALITY_OTHER -
CARDINALITY_OTHER - CARDINALITY_ONE
Matches
CARDINALITY_ONE -
CARDINALITY_OTHER - CARDINALITY_TWO
Matches
CARDINALITY_TWO -
CARDINALITY_OTHER - CARDINALITY_FEW
Matches
CARDINALITY_FEW -
CARDINALITY_OTHER - CARDINALITY_MANY
Matches
CARDINALITY_MANY -
CARDINALITY_OTHER - CARDINALITY_OTHER
Matches
CARDINALITY_OTHER
Ordinalities
-
ORDINALITY_ONE
Matches
n = 1Example Integers:
1 -
ORDINALITY_OTHER
Matches
all other valuesExample Integers:
0, 2, 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 ga 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_ONE": "Glac an {{formattedOrdinalValue}}ú chasadh ar dheis.", "ORDINALITY_OTHER": "Glac an {{formattedOrdinalValue}}ú casadh ar dheis." } } } } }
Usage and expected results
JavaScript
The JavaScript code passes each raw number to ordinalityForNumber(...) and formats its display value separately with Intl.NumberFormat. Ordinal rules are an optional import, lokalized/data/ordinal.
import { createStrings } from "lokalized"; import { ordinalData, ordinalityForNumber } from "lokalized/data/ordinal"; import { readStringsFromDirectory } from "lokalized/node"; const locale = "ga"; const strings = createStrings({ localizedStringSupplier: () => readStringsFromDirectory("strings").catalogs, fallbackLocale: locale, localeSupplier: () => locale, pluralData: { ordinal: ordinalData }, }); const numberFormat = new Intl.NumberFormat(locale); // Raw numbers select language forms; Intl.NumberFormat produces the display values // ORDINALITY_ONE const oneOrdinalValue = 1; const oneFormattedOrdinalValue = numberFormat.format(oneOrdinalValue); ordinalityForNumber(oneOrdinalValue, locale).name; // => "ORDINALITY_ONE" strings.get("Ordinal.MinimalPair", { ordinalValue: oneOrdinalValue, formattedOrdinalValue: oneFormattedOrdinalValue, }); // => "Glac an 1ú chasadh ar dheis." // ORDINALITY_OTHER const otherOrdinalValue = 2; const otherFormattedOrdinalValue = numberFormat.format(otherOrdinalValue); ordinalityForNumber(otherOrdinalValue, locale).name; // => "ORDINALITY_OTHER" strings.get("Ordinal.MinimalPair", { ordinalValue: otherOrdinalValue, formattedOrdinalValue: otherFormattedOrdinalValue, }); // => "Glac an 2ú casadh ar dheis."
Java
The Java code passes each raw number to Ordinality.forNumber(...) and formats its display value separately with NumberFormat.
Locale locale = Locale.forLanguageTag("ga"); 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_ONE Number oneOrdinalValue = 1; String oneFormattedOrdinalValue = numberFormat.format(oneOrdinalValue); assertEquals(Ordinality.ONE, Ordinality.forNumber(oneOrdinalValue, locale)); // Expected: Glac an 1ú chasadh ar dheis. assertEquals("Glac an " + oneFormattedOrdinalValue + "ú chasadh ar dheis.", strings.get( "Ordinal.MinimalPair", Map.of("ordinalValue", oneOrdinalValue, "formattedOrdinalValue", oneFormattedOrdinalValue) )); // ORDINALITY_OTHER Number otherOrdinalValue = 2; String otherFormattedOrdinalValue = numberFormat.format(otherOrdinalValue); assertEquals(Ordinality.OTHER, Ordinality.forNumber(otherOrdinalValue, locale)); // Expected: Glac an 2ú casadh ar dheis. assertEquals("Glac an " + otherFormattedOrdinalValue + "ú casadh ar dheis.", strings.get( "Ordinal.MinimalPair", Map.of("ordinalValue", otherOrdinalValue, "formattedOrdinalValue", otherFormattedOrdinalValue) ));
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("ga") 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 )) let number1 = try NumericValue.forDecimal("1") let category1 = try Ordinality.forNumber(number1, locale: locale.tag) assert(category1 == .one) let message1 = try strings.get("Ordinal.MinimalPair", placeholders: [ "ordinalValue": .number(number1), "formattedOrdinalValue": .text("1"), ]) assert(ExactString(message1) == ExactString("Glac an 1ú chasadh ar dheis.")) let number2 = try NumericValue.forDecimal("2") let category2 = try Ordinality.forNumber(number2, locale: locale.tag) assert(category2 == .other) let message2 = try strings.get("Ordinal.MinimalPair", placeholders: [ "ordinalValue": .number(number2), "formattedOrdinalValue": .text("2"), ]) assert(ExactString(message2) == ExactString("Glac an 2ú casadh ar dheis."))
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