Cardinalities
-
CARDINALITY_ONE
Matches
i = 1 and v = 0Example Integers:
1 -
CARDINALITY_MANY
Matches
e = 0 and i != 0 and i % 1000000 = 0 and v = 0 or e != 0..5Example Integers:
1000000, … -
CARDINALITY_OTHER
Matches
all other valuesExample Integers:
0, 2, 16, 100, 1000, 10000, 100000, …Example Decimals:
0.0, 1.5, 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 it 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}} giorno", "CARDINALITY_MANY": "{{formattedCardinalityValue}} di giorni", "CARDINALITY_OTHER": "{{formattedCardinalityValue}} giorni" } } } } }
Usage and expected results
The Java code passes each raw number for cardinality selection and formats its display value separately with NumberFormat.
Locale locale = Locale.forLanguageTag("it"); 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 oneCardinalityValue = 1; String oneFormattedCardinalityValue = numberFormat.format(oneCardinalityValue); assertEquals(Cardinality.ONE, Cardinality.forNumber(oneCardinalityValue, locale)); // Expected: 1 giorno assertEquals(oneFormattedCardinalityValue + " giorno", strings.get( "Cardinality.MinimalPair", Map.of( "cardinalityValue", oneCardinalityValue, "formattedCardinalityValue", oneFormattedCardinalityValue ) )); // CARDINALITY_MANY Number manyCardinalityValue = 1_000_000; String manyFormattedCardinalityValue = numberFormat.format(manyCardinalityValue); assertEquals(Cardinality.MANY, Cardinality.forNumber(manyCardinalityValue, locale)); // Expected: 1.000.000 di giorni assertEquals(manyFormattedCardinalityValue + " di giorni", strings.get( "Cardinality.MinimalPair", Map.of( "cardinalityValue", manyCardinalityValue, "formattedCardinalityValue", manyFormattedCardinalityValue ) )); // CARDINALITY_OTHER Number otherCardinalityValue = 0; String otherFormattedCardinalityValue = numberFormat.format(otherCardinalityValue); assertEquals(Cardinality.OTHER, Cardinality.forNumber(otherCardinalityValue, locale)); // Expected: 0 giorni assertEquals(otherFormattedCardinalityValue + " giorni", strings.get( "Cardinality.MinimalPair", Map.of( "cardinalityValue", otherCardinalityValue, "formattedCardinalityValue", otherFormattedCardinalityValue ) ));
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_OTHER
Matches
CARDINALITY_OTHER -
CARDINALITY_OTHER - CARDINALITY_ONE
Matches
CARDINALITY_ONE -
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}} giorno", "CARDINALITY_MANY": "{{formattedDayRange}} giorni", "CARDINALITY_OTHER": "{{formattedDayRange}} giorni" } } } } }
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.
Locale locale = Locale.forLanguageTag("it"); 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: 1-2 giorni assertEquals(formattedDayRange + " giorni", strings.get( "Delivery.Window", Map.of("minDays", minDays, "maxDays", maxDays, "formattedDayRange", formattedDayRange) ));
Ordinalities
-
ORDINALITY_MANY
Matches
n = 11,8,80,800Example Integers:
8, 11, 80, 800 -
ORDINALITY_OTHER
Matches
all other valuesExample Integers:
0, 7, 9, 10, 12, 17, 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 it 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_MANY": "Prendi l’{{formattedOrdinalValue}}° a destra.", "ORDINALITY_OTHER": "Prendi la {{formattedOrdinalValue}}° a destra." } } } } }
Usage and expected results
The Java code passes each raw number to Ordinality.forNumber(...) and formats its display value separately with NumberFormat.
Locale locale = Locale.forLanguageTag("it"); 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_MANY Number manyOrdinalValue = 8; String manyFormattedOrdinalValue = numberFormat.format(manyOrdinalValue); assertEquals(Ordinality.MANY, Ordinality.forNumber(manyOrdinalValue, locale)); // Expected: Prendi l’8° a destra. // U+2019 RIGHT SINGLE QUOTATION MARK preserves the punctuation used by the localized source text assertEquals("Prendi l\u2019" + manyFormattedOrdinalValue + "° a destra.", strings.get( "Ordinal.MinimalPair", Map.of("ordinalValue", manyOrdinalValue, "formattedOrdinalValue", manyFormattedOrdinalValue) )); // ORDINALITY_OTHER Number otherOrdinalValue = 7; String otherFormattedOrdinalValue = numberFormat.format(otherOrdinalValue); assertEquals(Ordinality.OTHER, Ordinality.forNumber(otherOrdinalValue, locale)); // Expected: Prendi la 7° a destra. assertEquals("Prendi la " + otherFormattedOrdinalValue + "° a destra.", strings.get( "Ordinal.MinimalPair", Map.of("ordinalValue", otherOrdinalValue, "formattedOrdinalValue", otherFormattedOrdinalValue) ));
Language-Specific Examples
These examples show how Lokalized models grammatical choices and translation behavior that commonly affect Italian application copy. Each example identifies the Lokalized language forms and other library features it uses.
Article forms by phonetic onset
Italian masculine singular articles vary by onset. This example covers a regular consonant, s impura, z, gn, ps, pn, x, and a vowel.
Language reference: Treccani - Italian article selection
Lokalized forms used: Phonetic
Sample localized strings file
{ "I see {{noun}}.": { "translation": "Vedo {{object}}.", "placeholders": { "object": { "value": "noun", "translations": { "PHONETIC_CONSONANT": "il libro", "PHONETIC_S_IMPURE": "lo studente", "PHONETIC_Z": "lo zaino", "PHONETIC_GN": "lo gnomo", "PHONETIC_PS": "lo psicologo", "PHONETIC_PN": "lo pneumatico", "PHONETIC_X": "lo xilofono", "PHONETIC_VOWEL": "l'amico" } } } } }
The application-provided resolver classifies each raw term at runtime. Its small lookup map stands in for application-specific pronunciation logic or a lexicon.
Usage and expected results
Locale locale = Locale.forLanguageTag("it"); Map<String, Phonetic> phoneticsByTerm = Map.ofEntries( Map.entry("libro", Phonetic.CONSONANT), Map.entry("studente", Phonetic.S_IMPURE), Map.entry("zaino", Phonetic.Z), Map.entry("gnomo", Phonetic.GN), Map.entry("psicologo", Phonetic.PS), Map.entry("pneumatico", Phonetic.PN), Map.entry("xilofono", Phonetic.X), Map.entry("amico", Phonetic.VOWEL) ); PhoneticResolver phoneticResolver = (term, ignoredLocale) -> phoneticsByTerm.getOrDefault(term, Phonetic.OTHER); Strings strings = Strings.withFallbackLocale(locale) .localizedStringSupplier(() -> LocalizedStringLoader.loadFromFilesystem(Paths.get("strings"))) .phoneticResolver(phoneticResolver) .localeSupplier((matcher) -> matcher.bestMatchFor(locale)) .build(); assertEquals("Vedo il libro.", strings.get( "I see {{noun}}.", Map.of("noun", "libro") )); assertEquals("Vedo lo studente.", strings.get( "I see {{noun}}.", Map.of("noun", "studente") )); assertEquals("Vedo lo zaino.", strings.get( "I see {{noun}}.", Map.of("noun", "zaino") )); assertEquals("Vedo lo gnomo.", strings.get( "I see {{noun}}.", Map.of("noun", "gnomo") )); assertEquals("Vedo lo psicologo.", strings.get( "I see {{noun}}.", Map.of("noun", "psicologo") )); assertEquals("Vedo lo pneumatico.", strings.get( "I see {{noun}}.", Map.of("noun", "pneumatico") )); assertEquals("Vedo lo xilofono.", strings.get( "I see {{noun}}.", Map.of("noun", "xilofono") )); assertEquals("Vedo l'amico.", strings.get( "I see {{noun}}.", Map.of("noun", "amico") ));
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