Cardinalities
-
CARDINALITY_ONE
Matches
i = 0 or n = 1Example Integers:
0, 1Example Decimals:
0.0, 1.0, 0.00, 0.04 -
CARDINALITY_OTHER
Matches
all other valuesExample Integers:
2, 17, 100, 1000, 10000, 100000, 1000000, …Example Decimals:
1.1, 2.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 hi 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 = "hi"; 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 = 0; const oneFormattedCardinalityValue = numberFormat.format(oneCardinality); cardinalityForNumber(oneCardinality, locale).name; // => "CARDINALITY_ONE" strings.get("Cardinality.MinimalPair", { cardinalityValue: oneCardinality, formattedCardinalityValue: oneFormattedCardinalityValue, }); // => "0 घंटा" // 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("hi"); 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 = 0; String oneFormattedCardinalityValue = numberFormat.format(oneCardinality); assertEquals(Cardinality.ONE, Cardinality.forNumber(oneCardinality, locale)); // Expected: 0 घंटा 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("hi") 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("0") let category1 = try Cardinality.forNumber(number1, locale: locale.tag) assert(category1 == .one) // 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("0 घंटा")) // CARDINALITY_OTHER let number2 = try NumericValue.forDecimal("2") let category2 = try Cardinality.forNumber(number2, locale: locale.tag) assert(category2 == .other) // 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 घंटे"))
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_ONE -
CARDINALITY_ONE - CARDINALITY_OTHER
Matches
CARDINALITY_OTHER -
CARDINALITY_OTHER - CARDINALITY_OTHER
Matches
CARDINALITY_OTHER
Ordinalities
-
ORDINALITY_ONE
Matches
n = 1Example Integers:
1 -
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, 5, 7, 20, 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 hi 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": "{{formattedOrdinalValue}}ला दाहिना मोड़ लें.", "ORDINALITY_TWO": "{{formattedOrdinalValue}}रा दाहिना मोड़ लें.", "ORDINALITY_FEW": "{{formattedOrdinalValue}} दाहिना मोड़ लें.", "ORDINALITY_MANY": "{{formattedOrdinalValue}}ठा दाहिना मोड़ लें.", "ORDINALITY_OTHER": "{{formattedOrdinalValue}}वां दाहिना मोड़ लें." } } } } }
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 = "hi"; 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, }); // => "1ला दाहिना मोड़ लें." // ORDINALITY_TWO const twoOrdinalValue = 2; const twoFormattedOrdinalValue = numberFormat.format(twoOrdinalValue); ordinalityForNumber(twoOrdinalValue, locale).name; // => "ORDINALITY_TWO" strings.get("Ordinal.MinimalPair", { ordinalValue: twoOrdinalValue, formattedOrdinalValue: twoFormattedOrdinalValue, }); // => "2रा दाहिना मोड़ लें." // ORDINALITY_FEW const fewOrdinalValue = 4; const fewFormattedOrdinalValue = numberFormat.format(fewOrdinalValue); ordinalityForNumber(fewOrdinalValue, locale).name; // => "ORDINALITY_FEW" strings.get("Ordinal.MinimalPair", { ordinalValue: fewOrdinalValue, formattedOrdinalValue: fewFormattedOrdinalValue, }); // => "4 दाहिना मोड़ लें." // ORDINALITY_MANY const manyOrdinalValue = 6; const manyFormattedOrdinalValue = numberFormat.format(manyOrdinalValue); ordinalityForNumber(manyOrdinalValue, locale).name; // => "ORDINALITY_MANY" strings.get("Ordinal.MinimalPair", { ordinalValue: manyOrdinalValue, formattedOrdinalValue: manyFormattedOrdinalValue, }); // => "6ठा दाहिना मोड़ लें." // ORDINALITY_OTHER const otherOrdinalValue = 5; const otherFormattedOrdinalValue = numberFormat.format(otherOrdinalValue); ordinalityForNumber(otherOrdinalValue, locale).name; // => "ORDINALITY_OTHER" strings.get("Ordinal.MinimalPair", { ordinalValue: otherOrdinalValue, formattedOrdinalValue: otherFormattedOrdinalValue, }); // => "5वां दाहिना मोड़ लें."
Java
The Java code passes each raw number to Ordinality.forNumber(...) and formats its display value separately with NumberFormat.
Locale locale = Locale.forLanguageTag("hi"); 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: 1ला दाहिना मोड़ लें. assertEquals(oneFormattedOrdinalValue + "ला दाहिना मोड़ लें.", strings.get( "Ordinal.MinimalPair", Map.of("ordinalValue", oneOrdinalValue, "formattedOrdinalValue", oneFormattedOrdinalValue) )); // ORDINALITY_TWO Number twoOrdinalValue = 2; String twoFormattedOrdinalValue = numberFormat.format(twoOrdinalValue); assertEquals(Ordinality.TWO, Ordinality.forNumber(twoOrdinalValue, locale)); // Expected: 2रा दाहिना मोड़ लें. assertEquals(twoFormattedOrdinalValue + "रा दाहिना मोड़ लें.", strings.get( "Ordinal.MinimalPair", Map.of("ordinalValue", twoOrdinalValue, "formattedOrdinalValue", twoFormattedOrdinalValue) )); // ORDINALITY_FEW Number fewOrdinalValue = 4; String fewFormattedOrdinalValue = numberFormat.format(fewOrdinalValue); assertEquals(Ordinality.FEW, Ordinality.forNumber(fewOrdinalValue, locale)); // Expected: 4 दाहिना मोड़ लें. assertEquals(fewFormattedOrdinalValue + " दाहिना मोड़ लें.", strings.get( "Ordinal.MinimalPair", Map.of("ordinalValue", fewOrdinalValue, "formattedOrdinalValue", fewFormattedOrdinalValue) )); // ORDINALITY_MANY Number manyOrdinalValue = 6; String manyFormattedOrdinalValue = numberFormat.format(manyOrdinalValue); assertEquals(Ordinality.MANY, Ordinality.forNumber(manyOrdinalValue, locale)); // Expected: 6ठा दाहिना मोड़ लें. assertEquals(manyFormattedOrdinalValue + "ठा दाहिना मोड़ लें.", strings.get( "Ordinal.MinimalPair", Map.of("ordinalValue", manyOrdinalValue, "formattedOrdinalValue", manyFormattedOrdinalValue) )); // ORDINALITY_OTHER Number otherOrdinalValue = 5; String otherFormattedOrdinalValue = numberFormat.format(otherOrdinalValue); assertEquals(Ordinality.OTHER, Ordinality.forNumber(otherOrdinalValue, locale)); // Expected: 5वां दाहिना मोड़ लें. assertEquals(otherFormattedOrdinalValue + "वां दाहिना मोड़ लें.", 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("hi") 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("1ला दाहिना मोड़ लें.")) let number2 = try NumericValue.forDecimal("2") let category2 = try Ordinality.forNumber(number2, locale: locale.tag) assert(category2 == .two) let message2 = try strings.get("Ordinal.MinimalPair", placeholders: [ "ordinalValue": .number(number2), "formattedOrdinalValue": .text("2"), ]) assert(ExactString(message2) == ExactString("2रा दाहिना मोड़ लें.")) let number3 = try NumericValue.forDecimal("4") let category3 = try Ordinality.forNumber(number3, locale: locale.tag) assert(category3 == .few) let message3 = try strings.get("Ordinal.MinimalPair", placeholders: [ "ordinalValue": .number(number3), "formattedOrdinalValue": .text("4"), ]) assert(ExactString(message3) == ExactString("4 दाहिना मोड़ लें.")) let number4 = try NumericValue.forDecimal("6") let category4 = try Ordinality.forNumber(number4, locale: locale.tag) assert(category4 == .many) let message4 = try strings.get("Ordinal.MinimalPair", placeholders: [ "ordinalValue": .number(number4), "formattedOrdinalValue": .text("6"), ]) assert(ExactString(message4) == ExactString("6ठा दाहिना मोड़ लें.")) let number5 = try NumericValue.forDecimal("5") let category5 = try Ordinality.forNumber(number5, locale: locale.tag) assert(category5 == .other) let message5 = try strings.get("Ordinal.MinimalPair", placeholders: [ "ordinalValue": .number(number5), "formattedOrdinalValue": .text("5"), ]) assert(ExactString(message5) == ExactString("5वां दाहिना मोड़ लें."))
Language-Specific Examples
These examples show how Lokalized models grammatical choices and translation behavior that commonly affect Hindi application copy. Each example identifies the Lokalized language forms and other library features it uses.
Gender agreement in an arrival message
Passing GENDER_MASCULINE or GENDER_FEMININE selects the matching singular arrival phrase, आ गया है or आ गई है, while the person's name remains application-supplied data.
Language reference: Michigan State University - Hindi perfective aspect and gender agreement
Language forms used: gender
Sample localized strings file
{ "{{person}} has arrived.": { "translation": "{{person}} {{arrival}}।", "placeholders": { "arrival": { "value": "gender", "translations": { "GENDER_MASCULINE": "आ गया है", "GENDER_FEMININE": "आ गई है" } } } } }
Usage and expected results
JavaScript
import { GENDER_FEMININE, GENDER_MASCULINE, createStrings } from "lokalized"; import { readStringsFromDirectory } from "lokalized/node"; const locale = "hi"; const strings = createStrings({ localizedStringSupplier: () => readStringsFromDirectory("strings").catalogs, fallbackLocale: locale, localeSupplier: () => locale, }); strings.get("{{person}} has arrived.", { person: "अमित", gender: GENDER_MASCULINE }); // => "अमित आ गया है।" strings.get("{{person}} has arrived.", { person: "मीरा", gender: GENDER_FEMININE }); // => "मीरा आ गई है।"
Java
Locale locale = Locale.forLanguageTag("hi"); Strings strings = Strings.withFallbackLocale(locale) .localizedStringSupplier(() -> LocalizedStringLoader.loadFromFilesystem(Paths.get("strings"))) .localeSupplier((matcher) -> matcher.bestMatchFor(locale)) .build(); assertEquals("अमित आ गया है।", strings.get( "{{person}} has arrived.", Map.of("person", "अमित", "gender", Gender.MASCULINE) )); assertEquals("मीरा आ गई है।", strings.get( "{{person}} has arrived.", Map.of("person", "मीरा", "gender", Gender.FEMININE) ));
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("hi") 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 message1 = try strings.get("{{person}} has arrived.", placeholders: [ "person": .text("अमित"), "gender": .languageForm(.gender(.masculine)), ]) assert(ExactString(message1) == ExactString("अमित आ गया है।")) let message2 = try strings.get("{{person}} has arrived.", placeholders: [ "person": .text("मीरा"), "gender": .languageForm(.gender(.feminine)), ]) assert(ExactString(message2) == ExactString("मीरा आ गई है।"))
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