Cardinalities
All numbers use CARDINALITY_OTHER; no value selects a different form.
Example: 2 hari.
Cardinality Ranges
Every range resolves to CARDINALITY_OTHER because every endpoint is CARDINALITY_OTHER, so no range can select a different form.
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 ms 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": "Ambil belokan kanan {{formattedOrdinalValue}}.", "ORDINALITY_OTHER": "Ambil belokan kanan yang ke-{{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 = "ms"; 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, }); // => "Ambil belokan kanan 1." // ORDINALITY_OTHER const otherOrdinalValue = 2; const otherFormattedOrdinalValue = numberFormat.format(otherOrdinalValue); ordinalityForNumber(otherOrdinalValue, locale).name; // => "ORDINALITY_OTHER" strings.get("Ordinal.MinimalPair", { ordinalValue: otherOrdinalValue, formattedOrdinalValue: otherFormattedOrdinalValue, }); // => "Ambil belokan kanan yang ke-2."
Java
The Java code passes each raw number to Ordinality.forNumber(...) and formats its display value separately with NumberFormat.
Locale locale = Locale.forLanguageTag("ms"); 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: Ambil belokan kanan 1. assertEquals("Ambil belokan kanan " + oneFormattedOrdinalValue + ".", 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: Ambil belokan kanan yang ke-2. assertEquals("Ambil belokan kanan yang ke-" + 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("ms") 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("Ambil belokan kanan 1.")) 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("Ambil belokan kanan yang ke-2."))
Language-Specific Examples
These examples show how Lokalized models grammatical choices and translation behavior that commonly affect Malay application copy. Each example identifies the Lokalized language forms and other library features it uses.
Inclusive and exclusive we
Malay distinguishes kita, which includes the addressee, from kami, which excludes the addressee.
Language references: Dewan Bahasa dan Pustaka - kami and kita, University of Malaya - inclusive kita and exclusive kami
Language forms used: clusivity
Sample localized strings file
{ "We will meet at noon.": { "translation": "{{we}} akan bertemu pada tengah hari.", "placeholders": { "we": { "value": "clusivity", "translations": { "CLUSIVITY_INCLUSIVE": "Kita", "CLUSIVITY_EXCLUSIVE": "Kami" } } } } }
Usage and expected results
JavaScript
import { CLUSIVITY_EXCLUSIVE, CLUSIVITY_INCLUSIVE, createStrings } from "lokalized"; import { readStringsFromDirectory } from "lokalized/node"; const locale = "ms"; const strings = createStrings({ localizedStringSupplier: () => readStringsFromDirectory("strings").catalogs, fallbackLocale: locale, localeSupplier: () => locale, }); strings.get("We will meet at noon.", { clusivity: CLUSIVITY_INCLUSIVE }); // => "Kita akan bertemu pada tengah hari." strings.get("We will meet at noon.", { clusivity: CLUSIVITY_EXCLUSIVE }); // => "Kami akan bertemu pada tengah hari."
Java
Locale locale = Locale.forLanguageTag("ms"); Strings strings = Strings.withFallbackLocale(locale) .localizedStringSupplier(() -> LocalizedStringLoader.loadFromFilesystem(Paths.get("strings"))) .localeSupplier((matcher) -> matcher.bestMatchFor(locale)) .build(); assertEquals("Kita akan bertemu pada tengah hari.", strings.get( "We will meet at noon.", Map.of("clusivity", Clusivity.INCLUSIVE) )); assertEquals("Kami akan bertemu pada tengah hari.", strings.get( "We will meet at noon.", Map.of("clusivity", Clusivity.EXCLUSIVE) ));
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("ms") 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("We will meet at noon.", placeholders: [ "clusivity": .languageForm(.clusivity(.inclusive)), ]) assert(ExactString(message1) == ExactString("Kita akan bertemu pada tengah hari.")) let message2 = try strings.get("We will meet at noon.", placeholders: [ "clusivity": .languageForm(.clusivity(.exclusive)), ]) assert(ExactString(message2) == ExactString("Kami akan bertemu pada tengah hari."))
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