English (India)

BCP 47 language tag: en-IN

Lokalized supports cardinality, cardinality range, and ordinality rules for English (India).

Additional modeled concepts for English (India): sound-dependent word forms.

Cardinalities

  • CARDINALITY_ONE

    Matches i = 1 and v = 0

    Example Integers: 1

  • CARDINALITY_OTHER

    Matches all other values

    Example Integers: 0, 2, 16, 100, 1000, 10000, 100000, 1000000, …

    Example Decimals: 0.0, 1.5, 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 for display are interpolated.

Sample localized strings file
en-IN.json Localized Strings File (English (India))
{
  "Delivery.LeadTime": {
    "commentary": "Estimated delivery time, expressed in days.",
    "translation": "{{leadTime}}",
    "placeholders": {
      "leadTime": {
        "value": "dayCount",
        "translations": {
          "CARDINALITY_ONE": "{{formattedDayCount}} day",
          "CARDINALITY_OTHER": "{{formattedDayCount}} days"
        }
      }
    }
  }
}
Usage and expected results

JavaScript

The JavaScript code passes each raw number for cardinality selection and formats its display value separately with Intl.NumberFormat. The exact-tag 1,000,000 assertion records the output of Node.js 24.15.0; other runtimes' locale data can differ.

import { cardinalityForNumber, createStrings } from "lokalized";
import { readStringsFromDirectory } from "lokalized/node";

const locale = "en-IN";

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 oneDayCount = 1;
const oneFormattedDayCount = numberFormat.format(oneDayCount);

cardinalityForNumber(oneDayCount, locale).name;   // => "CARDINALITY_ONE"
strings.get("Delivery.LeadTime", {
  dayCount: oneDayCount,
  formattedDayCount: oneFormattedDayCount,
});   // => "1 day"

// CARDINALITY_OTHER
const otherDayCount = 0;
const otherFormattedDayCount = numberFormat.format(otherDayCount);

cardinalityForNumber(otherDayCount, locale).name;   // => "CARDINALITY_OTHER"
strings.get("Delivery.LeadTime", {
  dayCount: otherDayCount,
  formattedDayCount: otherFormattedDayCount,
});   // => "0 days"

// Exact-tag formatting sample
const localeProfileDayCount = 1_000_000;
const localeProfileFormattedDayCount = numberFormat.format(localeProfileDayCount);

localeProfileFormattedDayCount;   // => "10,00,000"
cardinalityForNumber(localeProfileDayCount, locale).name;   // => "CARDINALITY_OTHER"
strings.get("Delivery.LeadTime", {
  dayCount: localeProfileDayCount,
  formattedDayCount: localeProfileFormattedDayCount,
});   // => "10,00,000 days"

Java

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("en-IN");

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);

assertEquals(Cardinality.ONE, Cardinality.forNumber(oneDayCount, locale));

// Expected: 1 day
assertEquals(oneFormattedDayCount + " day", strings.get(
  "Delivery.LeadTime", Map.of("dayCount", oneDayCount, "formattedDayCount", oneFormattedDayCount)
));

// CARDINALITY_OTHER
Number otherDayCount = 0;
String otherFormattedDayCount = numberFormat.format(otherDayCount);

assertEquals(Cardinality.OTHER, Cardinality.forNumber(otherDayCount, locale));

// Expected: 0 days
assertEquals(otherFormattedDayCount + " days", 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.OTHER, Cardinality.forNumber(localeProfileDayCount, locale));

// Expected: 1,000,000 days
assertEquals(localeProfileFormattedDayCount + " days", strings.get(
  "Delivery.LeadTime",
  Map.of("dayCount", localeProfileDayCount, "formattedDayCount", localeProfileFormattedDayCount)
));

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("en-IN")
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("Delivery.LeadTime", placeholders: [
  "dayCount": .number(number1),
  "formattedDayCount": .text(display1),
])
assert(ExactString(message1) == ExactString("1 day"))

// CARDINALITY_OTHER
let number2 = try NumericValue.forDecimal("0")
let category2 = try Cardinality.forNumber(number2, locale: locale.tag)
assert(category2 == .other)
// This fixed display value makes the translation assertion reproducible.
let display2 = "0"
let message2 = try strings.get("Delivery.LeadTime", placeholders: [
  "dayCount": .number(number2),
  "formattedDayCount": .text(display2),
])
assert(ExactString(message2) == ExactString("0 days"))

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_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
en-IN.json Localized Strings File (English (India))
{
  "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}} day",
          "CARDINALITY_OTHER": "{{formattedDayRange}} days"
        }
      }
    }
  }
}
Usage and expected results

JavaScript

The JavaScript code passes raw range endpoints for selection, formats both endpoints separately with Intl.NumberFormat, and joins them for display; choose range punctuation appropriate to your application. Range rules are an optional import, lokalized/data/ranges.

import { cardinalityForNumber, createStrings } from "lokalized";
import { cardinalRangeData, cardinalityForRange } from "lokalized/data/ranges";
import { readStringsFromDirectory } from "lokalized/node";

const locale = "en-IN";

const strings = createStrings({
  localizedStringSupplier: () => readStringsFromDirectory("strings").catalogs,
  fallbackLocale: locale,
  localeSupplier: () => locale,
  pluralData: { ranges: cardinalRangeData },
});

const numberFormat = new Intl.NumberFormat(locale);

// Raw numbers select language forms; Intl.NumberFormat produces the display values

// CARDINALITY_OTHER range
const minDays = 1;
const formattedMinDays = numberFormat.format(minDays);
const maxDays = 2;
const formattedMaxDays = numberFormat.format(maxDays);
const formattedDayRange = formattedMinDays + "-" + formattedMaxDays;

cardinalityForRange(
  cardinalityForNumber(minDays, locale),
  cardinalityForNumber(maxDays, locale),
  locale
).name;   // => "CARDINALITY_OTHER"
strings.get("Delivery.Window", { minDays, maxDays, formattedDayRange });   // => "1-2 days"

Java

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("en-IN");

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 days
assertEquals(formattedDayRange + " days", strings.get(
  "Delivery.Window",
  Map.of("minDays", minDays, "maxDays", maxDays, "formattedDayRange", formattedDayRange)
));

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("en-IN")
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 start = try NumericValue.forDecimal("1")
let end = try NumericValue.forDecimal("2")
let startForm = try Cardinality.forNumber(start, locale: locale.tag)
let endForm = try Cardinality.forNumber(end, locale: locale.tag)
let rangeForm = try Cardinality.forRange(startForm, endForm, locale: locale.tag)
assert(rangeForm == .other)
let message1 = try strings.get("Delivery.Window", placeholders: [
  "minDays": .number(start),
  "maxDays": .number(end),
  "formattedDayRange": .text("1-2"),
])
assert(ExactString(message1) == ExactString("1-2 days"))

Ordinalities

  • ORDINALITY_ONE

    Matches n % 10 = 1 and n % 100 != 11

    Example Integers: 1, 21, 31, 41, 51, 61, 71, 81, 101, 1001, …

  • ORDINALITY_TWO

    Matches n % 10 = 2 and n % 100 != 12

    Example Integers: 2, 22, 32, 42, 52, 62, 72, 82, 102, 1002, …

  • ORDINALITY_FEW

    Matches n % 10 = 3 and n % 100 != 13

    Example Integers: 3, 23, 33, 43, 53, 63, 73, 83, 103, 1003, …

  • ORDINALITY_OTHER

    Matches all other values

    Example Integers: 0, 4, 18, 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 en locale data.

Sample localized strings file
en-IN.json Localized Strings File (English (India))
{
  "Ordinal.MinimalPair": {
    "commentary": "Demonstrates every CLDR ordinal category defined for this locale.",
    "translation": "{{ordinalExample}}",
    "placeholders": {
      "ordinalExample": {
        "value": "ordinalValue",
        "translations": {
          "ORDINALITY_ONE": "Take the {{formattedOrdinalValue}}st right.",
          "ORDINALITY_TWO": "Take the {{formattedOrdinalValue}}nd right.",
          "ORDINALITY_FEW": "Take the {{formattedOrdinalValue}}rd right.",
          "ORDINALITY_OTHER": "Take the {{formattedOrdinalValue}}th right."
        }
      }
    }
  }
}
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 = "en-IN";

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,
});   // => "Take the 1st right."

// ORDINALITY_TWO
const twoOrdinalValue = 2;
const twoFormattedOrdinalValue = numberFormat.format(twoOrdinalValue);

ordinalityForNumber(twoOrdinalValue, locale).name;   // => "ORDINALITY_TWO"
strings.get("Ordinal.MinimalPair", {
  ordinalValue: twoOrdinalValue,
  formattedOrdinalValue: twoFormattedOrdinalValue,
});   // => "Take the 2nd right."

// ORDINALITY_FEW
const fewOrdinalValue = 3;
const fewFormattedOrdinalValue = numberFormat.format(fewOrdinalValue);

ordinalityForNumber(fewOrdinalValue, locale).name;   // => "ORDINALITY_FEW"
strings.get("Ordinal.MinimalPair", {
  ordinalValue: fewOrdinalValue,
  formattedOrdinalValue: fewFormattedOrdinalValue,
});   // => "Take the 3rd right."

// ORDINALITY_OTHER
const otherOrdinalValue = 4;
const otherFormattedOrdinalValue = numberFormat.format(otherOrdinalValue);

ordinalityForNumber(otherOrdinalValue, locale).name;   // => "ORDINALITY_OTHER"
strings.get("Ordinal.MinimalPair", {
  ordinalValue: otherOrdinalValue,
  formattedOrdinalValue: otherFormattedOrdinalValue,
});   // => "Take the 4th right."

Java

The Java code passes each raw number to Ordinality.forNumber(...) and formats its display value separately with NumberFormat.

Locale locale = Locale.forLanguageTag("en-IN");

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: Take the 1st right.
assertEquals("Take the " + oneFormattedOrdinalValue + "st right.", 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: Take the 2nd right.
assertEquals("Take the " + twoFormattedOrdinalValue + "nd right.", strings.get(
  "Ordinal.MinimalPair",
  Map.of("ordinalValue", twoOrdinalValue, "formattedOrdinalValue", twoFormattedOrdinalValue)
));

// ORDINALITY_FEW
Number fewOrdinalValue = 3;
String fewFormattedOrdinalValue = numberFormat.format(fewOrdinalValue);

assertEquals(Ordinality.FEW, Ordinality.forNumber(fewOrdinalValue, locale));

// Expected: Take the 3rd right.
assertEquals("Take the " + fewFormattedOrdinalValue + "rd right.", strings.get(
  "Ordinal.MinimalPair",
  Map.of("ordinalValue", fewOrdinalValue, "formattedOrdinalValue", fewFormattedOrdinalValue)
));

// ORDINALITY_OTHER
Number otherOrdinalValue = 4;
String otherFormattedOrdinalValue = numberFormat.format(otherOrdinalValue);

assertEquals(Ordinality.OTHER, Ordinality.forNumber(otherOrdinalValue, locale));

// Expected: Take the 4th right.
assertEquals("Take the " + otherFormattedOrdinalValue + "th right.", 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("en-IN")
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("Take the 1st right."))

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("Take the 2nd right."))

let number3 = try NumericValue.forDecimal("3")
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("3"),
])
assert(ExactString(message3) == ExactString("Take the 3rd right."))

let number4 = try NumericValue.forDecimal("4")
let category4 = try Ordinality.forNumber(number4, locale: locale.tag)
assert(category4 == .other)
let message4 = try strings.get("Ordinal.MinimalPair", placeholders: [
  "ordinalValue": .number(number4),
  "formattedOrdinalValue": .text("4"),
])
assert(ExactString(message4) == ExactString("Take the 4th right."))

Language-Specific Examples

These examples show how Lokalized models grammatical choices and translation behavior that commonly affect English (India) application copy. Each example identifies the Lokalized language forms and other library features it uses.

Indefinite articles by initial sound

English chooses a or an from the first sound rather than the first letter, including silent-h and consonantal y-glide onsets.

Language reference: Cambridge Dictionary: a/an follows the initial sound

Language forms used: phonetics

Sample localized strings file
en-IN.json Localized Strings File (English (India))
{
  "Create a {{resource}}.": {
    "translation": "Create {{article}} {{resource}}.",
    "placeholders": {
      "article": {
        "value": "resource",
        "translations": {
          "PHONETIC_VOWEL": "an",
          "PHONETIC_CONSONANT": "a",
          "PHONETIC_H_SILENT": "an",
          "PHONETIC_GLIDE_Y": "a"
        }
      }
    }
  }
}

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

JavaScript

import { PHONETIC_CONSONANT, PHONETIC_GLIDE_Y, PHONETIC_H_SILENT, PHONETIC_OTHER, PHONETIC_VOWEL, createStrings } from "lokalized";
import { readStringsFromDirectory } from "lokalized/node";

const locale = "en-IN";

const phoneticsByTerm = new Map([
  ["account", PHONETIC_VOWEL],
  ["report", PHONETIC_CONSONANT],
  ["hourly reminder", PHONETIC_H_SILENT],
  ["user account", PHONETIC_GLIDE_Y],
]);
const phoneticResolver = (term) => phoneticsByTerm.get(term) ?? PHONETIC_OTHER;

const strings = createStrings({
  localizedStringSupplier: () => readStringsFromDirectory("strings").catalogs,
  fallbackLocale: locale,
  localeSupplier: () => locale,
  phoneticResolver,
});

strings.get("Create a {{resource}}.", { resource: "account" });   // => "Create an account."
strings.get("Create a {{resource}}.", { resource: "report" });   // => "Create a report."
strings.get("Create a {{resource}}.", { resource: "hourly reminder" });   // => "Create an hourly reminder."
strings.get("Create a {{resource}}.", { resource: "user account" });   // => "Create a user account."

Java

Locale locale = Locale.forLanguageTag("en-IN");

Map<String, Phonetic> phoneticsByTerm = Map.ofEntries(
  Map.entry("account", Phonetic.VOWEL),
  Map.entry("report", Phonetic.CONSONANT),
  Map.entry("hourly reminder", Phonetic.H_SILENT),
  Map.entry("user account", Phonetic.GLIDE_Y)
);
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("Create an account.", strings.get(
  "Create a {{resource}}.", Map.of("resource", "account")
));

assertEquals("Create a report.", strings.get(
  "Create a {{resource}}.", Map.of("resource", "report")
));

assertEquals("Create an hourly reminder.", strings.get(
  "Create a {{resource}}.", Map.of("resource", "hourly reminder")
));

assertEquals("Create a user account.", strings.get(
  "Create a {{resource}}.", Map.of("resource", "user account")
));

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("en-IN")
let files = try LocalizedStringLoader.loadFromDirectory(URL(fileURLWithPath: "strings"))
let catalogs = files.mapValues { LocalizedCatalog(strings: $0.strings) }

let phoneticsByTerm: [ExactString: Phonetic] = [
  "account": .vowel,
  "report": .consonant,
  "hourly reminder": .hSilent,
  "user account": .glideY,
]
let phoneticResolver: PhoneticResolver = { term, _ in phoneticsByTerm[ExactString(term)] ?? .other }

let strings = try DefaultStrings(configuration: StringsConfiguration(
  localizedStringSupplier: { catalogs }, localeSupplier: { _ in locale },
  fallbackLocale: locale, phoneticResolver: phoneticResolver
))

let message1 = try strings.get("Create a {{resource}}.", placeholders: [
  "resource": .text("account"),
])
assert(ExactString(message1) == ExactString("Create an account."))

let message2 = try strings.get("Create a {{resource}}.", placeholders: [
  "resource": .text("report"),
])
assert(ExactString(message2) == ExactString("Create a report."))

let message3 = try strings.get("Create a {{resource}}.", placeholders: [
  "resource": .text("hourly reminder"),
])
assert(ExactString(message3) == ExactString("Create an hourly reminder."))

let message4 = try strings.get("Create a {{resource}}.", placeholders: [
  "resource": .text("user account"),
])
assert(ExactString(message4) == ExactString("Create a user account."))

Addendum: Language Form Rules

The language form expressions above are specified by Unicode Technical Standard #35 and use the following notation:

  • n absolute value of the source number (integer and decimals)
  • i integer digits of n
  • v number of visible fraction digits in n, with trailing zeros
  • w number of visible fraction digits in n, without trailing zeros
  • f visible fractional digits in n, with trailing zeros
  • t visible fractional digits in n, without trailing zeros
  • c/e compact decimal exponent operands used by some CLDR compact-number rules