Cardinalities
-
CARDINALITY_ONE
Matches
n = 1Example Integers:
1Example Decimals:
1.0, 1.00, 1.000, 1.0000 -
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, 0.9, 1.1, 1.6, 10.0, 100.0, 1000.0, 10000.0, 100000.0, 1000000.0, …
Cardinality example
This localized strings file selects the localized form of “day” for a delivery estimate. Raw numbers choose the CLDR category; values formatted with the JDK NumberFormat are interpolated for display.
Sample localized strings file
{ "Delivery.LeadTime": { "commentary": "Estimated delivery time, expressed in days.", "translation": "{{leadTime}}", "placeholders": { "leadTime": { "value": "dayCount", "translations": { "CARDINALITY_ONE": "{{formattedDayCount}} día", "CARDINALITY_MANY": "{{formattedDayCount}} días", "CARDINALITY_OTHER": "{{formattedDayCount}} días" } } } } }
Usage and expected results
The Java code passes each raw number for cardinality selection and formats its display value separately with NumberFormat. The exact-tag 1,000,000 assertion records JDK 26 output; older JDK locale data can differ.
Locale locale = Locale.forLanguageTag("es-419"); 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 oneDayCount = 1; String oneFormattedDayCount = numberFormat.format(oneDayCount); // Expected: 1 día assertEquals(oneFormattedDayCount + " día", strings.get( "Delivery.LeadTime", Map.of("dayCount", oneDayCount, "formattedDayCount", oneFormattedDayCount) )); // CARDINALITY_MANY Number manyDayCount = 1_000_000; String manyFormattedDayCount = numberFormat.format(manyDayCount); // Expected: 1,000,000 días assertEquals(manyFormattedDayCount + " días", strings.get( "Delivery.LeadTime", Map.of("dayCount", manyDayCount, "formattedDayCount", manyFormattedDayCount) )); // CARDINALITY_OTHER Number otherDayCount = 0; String otherFormattedDayCount = numberFormat.format(otherDayCount); // Expected: 0 días assertEquals(otherFormattedDayCount + " días", strings.get( "Delivery.LeadTime", Map.of("dayCount", otherDayCount, "formattedDayCount", otherFormattedDayCount) )); // Exact-tag formatting sample Number localeProfileDayCount = 1_000_000; String localeProfileFormattedDayCount = numberFormat.format(localeProfileDayCount); assertEquals("1,000,000", localeProfileFormattedDayCount); assertEquals(Cardinality.MANY, Cardinality.forNumber(localeProfileDayCount, locale)); // Expected: 1,000,000 días assertEquals(localeProfileFormattedDayCount + " días", strings.get( "Delivery.LeadTime", Map.of("dayCount", localeProfileDayCount, "formattedDayCount", localeProfileFormattedDayCount) ));
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_OTHER -
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}} día", "CARDINALITY_MANY": "{{formattedDayRange}} días", "CARDINALITY_OTHER": "{{formattedDayRange}} días" } } } } }
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("es-419"); 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 días assertEquals(formattedDayRange + " días", strings.get( "Delivery.Window", Map.of("minDays", minDays, "maxDays", maxDays, "formattedDayRange", formattedDayRange) ));
Ordinalities
All ordinal numbers use ORDINALITY_OTHER; no value selects a different form.
Example: Toma la 2.ª a la derecha..
Language-Specific Examples
These examples show how Lokalized models grammatical choices and translation behavior that commonly affect Latin American Spanish application copy. Each example identifies the Lokalized language forms and other library features it uses.
Gendered subject and adjective agreement
Spanish keeps the article and adjective aligned with the selected subject's gender. This example uses clienta, a standard feminine form; la cliente is standard as well.
Language references: RAE/ASALE - cliente, clienta, RAE/ASALE - listo, lista, RAE - predicate-attribute agreement
Lokalized forms used: Gender
Sample localized strings file
{ "The customer is ready.": { "translation": "{{customer}} está {{ready}}.", "placeholders": { "customer": { "value": "gender", "translations": { "GENDER_MASCULINE": "El cliente", "GENDER_FEMININE": "La clienta" } }, "ready": { "value": "gender", "translations": { "GENDER_MASCULINE": "listo", "GENDER_FEMININE": "lista" } } } } }
Usage and expected results
Locale locale = Locale.forLanguageTag("es-419"); Strings strings = Strings.withFallbackLocale(locale) .localizedStringSupplier(() -> LocalizedStringLoader.loadFromFilesystem(Paths.get("strings"))) .localeSupplier((matcher) -> matcher.bestMatchFor(locale)) .build(); assertEquals("El cliente está listo.", strings.get( "The customer is ready.", Map.of("gender", Gender.MASCULINE) )); assertEquals("La clienta está lista.", strings.get( "The customer is ready.", Map.of("gender", Gender.FEMININE) ));
Stressed-a article selection
Most Spanish feminine nouns beginning with stressed a- or ha- take el in the singular when the article immediately precedes the noun, while remaining feminine, as firmada makes visible here.
Language reference: RAE/ASALE - el before feminine nouns beginning with stressed a- or ha-
Lokalized forms used: Phonetic
Sample localized strings file
{ "I received {{noun}}.": { "translation": "Recibí {{article}} {{noun}} firmada.", "placeholders": { "article": { "value": "noun", "translations": { "PHONETIC_STRESSED_A": "el", "PHONETIC_OTHER": "la" } } } } }
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("es-419"); Map<String, Phonetic> phoneticsByTerm = Map.ofEntries( Map.entry("acta", Phonetic.STRESSED_A), Map.entry("carta", Phonetic.OTHER) ); 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("Recibí el acta firmada.", strings.get( "I received {{noun}}.", Map.of("noun", "acta") )); assertEquals("Recibí la carta firmada.", strings.get( "I received {{noun}}.", Map.of("noun", "carta") ));
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