Arabic العربية

BCP 47 language tag: ar

Lokalized supports cardinality, cardinality range, and ordinality rules for Arabic.

Additional modeled concepts for Arabic: definiteness; sound-dependent word forms.

Arabic is most often spoken in Egypt, Saudi Arabia, Algeria, Sudan, and Iraq.

Cardinalities

  • CARDINALITY_ZERO

    Matches n = 0

    Example Integers: 0

    Example Decimals: 0.0, 0.00, 0.000, 0.0000

  • CARDINALITY_ONE

    Matches n = 1

    Example Integers: 1

    Example Decimals: 1.0, 1.00, 1.000, 1.0000

  • CARDINALITY_TWO

    Matches n = 2

    Example Integers: 2

    Example Decimals: 2.0, 2.00, 2.000, 2.0000

  • CARDINALITY_FEW

    Matches n % 100 = 3..10

    Example Integers: 3, 10, 103, 110, 1003, …

    Example Decimals: 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 103.0, 1003.0, …

  • CARDINALITY_MANY

    Matches n % 100 = 11..99

    Example Integers: 11, 26, 111, 1011, …

    Example Decimals: 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0, 111.0, 1011.0, …

  • CARDINALITY_OTHER

    Matches all other values

    Example Integers: 100, 102, 200, 202, 300, 302, 400, 402, 500, 502, 600, 1000, 10000, 100000, 1000000, …

    Example Decimals: 0.1, 0.9, 1.1, 1.7, 10.1, 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 ar locale data.

Sample localized strings file
ar.json Localized Strings File (Arabic)
{
  "Cardinality.MinimalPair": {
    "commentary": "Demonstrates every CLDR cardinal category defined for this locale.",
    "translation": "{{cardinalityExample}}",
    "placeholders": {
      "cardinalityExample": {
        "value": "cardinalityValue",
        "translations": {
          "CARDINALITY_ZERO": "{{formattedCardinalityValue}} ولد حضر",
          "CARDINALITY_ONE": "ولد واحد حضر",
          "CARDINALITY_TWO": "ولدان حضرا",
          "CARDINALITY_FEW": "{{formattedCardinalityValue}} أولاد حضروا",
          "CARDINALITY_MANY": "{{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. For this right-to-left locale, the default bidiIsolation, "rtl-locales", wraps caller-supplied formatted values with U+2068 FIRST STRONG ISOLATE and U+2069 POP DIRECTIONAL ISOLATE; the expected strings below show those escapes.

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

const locale = "ar";

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_ZERO
const zeroCardinality = 0;
const zeroFormattedCardinalityValue = numberFormat.format(zeroCardinality);

cardinalityForNumber(zeroCardinality, locale).name;   // => "CARDINALITY_ZERO"
// U+2068 FIRST STRONG ISOLATE begins bidirectional isolation around a caller-supplied value in right-to-left text
// U+2069 POP DIRECTIONAL ISOLATE ends bidirectional isolation around a caller-supplied value in right-to-left text
strings.get("Cardinality.MinimalPair", {
  cardinalityValue: zeroCardinality,
  formattedCardinalityValue: zeroFormattedCardinalityValue,
});   // => "\u20680\u2069 ولد حضر"

// CARDINALITY_ONE
const oneCardinality = 1;
const oneFormattedCardinalityValue = numberFormat.format(oneCardinality);

cardinalityForNumber(oneCardinality, locale).name;   // => "CARDINALITY_ONE"
strings.get("Cardinality.MinimalPair", {
  cardinalityValue: oneCardinality,
  formattedCardinalityValue: oneFormattedCardinalityValue,
});   // => "ولد واحد حضر"

// CARDINALITY_TWO
const twoCardinality = 2;
const twoFormattedCardinalityValue = numberFormat.format(twoCardinality);

cardinalityForNumber(twoCardinality, locale).name;   // => "CARDINALITY_TWO"
strings.get("Cardinality.MinimalPair", {
  cardinalityValue: twoCardinality,
  formattedCardinalityValue: twoFormattedCardinalityValue,
});   // => "ولدان حضرا"

// CARDINALITY_FEW
const fewCardinality = 3;
const fewFormattedCardinalityValue = numberFormat.format(fewCardinality);

cardinalityForNumber(fewCardinality, locale).name;   // => "CARDINALITY_FEW"
strings.get("Cardinality.MinimalPair", {
  cardinalityValue: fewCardinality,
  formattedCardinalityValue: fewFormattedCardinalityValue,
});   // => "\u20683\u2069 أولاد حضروا"

// CARDINALITY_MANY
const manyCardinality = 11;
const manyFormattedCardinalityValue = numberFormat.format(manyCardinality);

cardinalityForNumber(manyCardinality, locale).name;   // => "CARDINALITY_MANY"
strings.get("Cardinality.MinimalPair", {
  cardinalityValue: manyCardinality,
  formattedCardinalityValue: manyFormattedCardinalityValue,
});   // => "\u206811\u2069 ولدًا حضروا"

// CARDINALITY_OTHER
const otherCardinality = 100;
const otherFormattedCardinalityValue = numberFormat.format(otherCardinality);

cardinalityForNumber(otherCardinality, locale).name;   // => "CARDINALITY_OTHER"
strings.get("Cardinality.MinimalPair", {
  cardinalityValue: otherCardinality,
  formattedCardinalityValue: otherFormattedCardinalityValue,
});   // => "\u2068100\u2069 ولد حضروا"

Java

The Java code passes each raw number for cardinality selection and formats its display value separately with NumberFormat. For this right-to-left locale, Lokalized's default BidiIsolation.RTL_LOCALES wraps caller-supplied formatted values with U+2068 FIRST STRONG ISOLATE and U+2069 POP DIRECTIONAL ISOLATE; the expected expressions below show those escapes.

Locale locale = Locale.forLanguageTag("ar");

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_ZERO
Number zeroCardinality = 0;
String zeroFormattedCardinalityValue = numberFormat.format(zeroCardinality);

assertEquals(Cardinality.ZERO, Cardinality.forNumber(zeroCardinality, locale));

// Expected: <FSI>0<PDI> ولد حضر
// U+2068 FIRST STRONG ISOLATE begins bidirectional isolation around a caller-supplied value in right-to-left text
// U+2069 POP DIRECTIONAL ISOLATE ends bidirectional isolation around a caller-supplied value in right-to-left text
assertEquals("\u2068" + zeroFormattedCardinalityValue + "\u2069 ولد حضر", strings.get(
  "Cardinality.MinimalPair",
  Map.of(
    "cardinalityValue", zeroCardinality,
    "formattedCardinalityValue", zeroFormattedCardinalityValue
  )
));

// CARDINALITY_ONE
Number oneCardinality = 1;
String oneFormattedCardinalityValue = numberFormat.format(oneCardinality);

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

assertEquals("ولد واحد حضر", strings.get(
  "Cardinality.MinimalPair",
  Map.of("cardinalityValue", oneCardinality, "formattedCardinalityValue", oneFormattedCardinalityValue)
));

// CARDINALITY_TWO
Number twoCardinality = 2;
String twoFormattedCardinalityValue = numberFormat.format(twoCardinality);

assertEquals(Cardinality.TWO, Cardinality.forNumber(twoCardinality, locale));

assertEquals("ولدان حضرا", strings.get(
  "Cardinality.MinimalPair",
  Map.of("cardinalityValue", twoCardinality, "formattedCardinalityValue", twoFormattedCardinalityValue)
));

// CARDINALITY_FEW
Number fewCardinality = 3;
String fewFormattedCardinalityValue = numberFormat.format(fewCardinality);

assertEquals(Cardinality.FEW, Cardinality.forNumber(fewCardinality, locale));

// Expected: <FSI>3<PDI> أولاد حضروا
assertEquals("\u2068" + fewFormattedCardinalityValue + "\u2069 أولاد حضروا", strings.get(
  "Cardinality.MinimalPair",
  Map.of("cardinalityValue", fewCardinality, "formattedCardinalityValue", fewFormattedCardinalityValue)
));

// CARDINALITY_MANY
Number manyCardinality = 11;
String manyFormattedCardinalityValue = numberFormat.format(manyCardinality);

assertEquals(Cardinality.MANY, Cardinality.forNumber(manyCardinality, locale));

// Expected: <FSI>11<PDI> ولدًا حضروا
assertEquals("\u2068" + manyFormattedCardinalityValue + "\u2069 ولدًا حضروا", strings.get(
  "Cardinality.MinimalPair",
  Map.of(
    "cardinalityValue", manyCardinality,
    "formattedCardinalityValue", manyFormattedCardinalityValue
  )
));

// CARDINALITY_OTHER
Number otherCardinality = 100;
String otherFormattedCardinalityValue = numberFormat.format(otherCardinality);

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

// Expected: <FSI>100<PDI> ولد حضروا
assertEquals("\u2068" + otherFormattedCardinalityValue + "\u2069 ولد حضروا", 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("ar")
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_ZERO
let number1 = try NumericValue.forDecimal("0")
let category1 = try Cardinality.forNumber(number1, locale: locale.tag)
assert(category1 == .zero)
// 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("\u{2068}0\u{2069} ولد حضر"))

// CARDINALITY_ONE
let number2 = try NumericValue.forDecimal("1")
let category2 = try Cardinality.forNumber(number2, locale: locale.tag)
assert(category2 == .one)
// This fixed display value makes the translation assertion reproducible.
let display2 = "1"
let message2 = try strings.get("Cardinality.MinimalPair", placeholders: [
  "cardinalityValue": .number(number2),
  "formattedCardinalityValue": .text(display2),
])
assert(ExactString(message2) == ExactString("ولد واحد حضر"))

// CARDINALITY_TWO
let number3 = try NumericValue.forDecimal("2")
let category3 = try Cardinality.forNumber(number3, locale: locale.tag)
assert(category3 == .two)
// This fixed display value makes the translation assertion reproducible.
let display3 = "2"
let message3 = try strings.get("Cardinality.MinimalPair", placeholders: [
  "cardinalityValue": .number(number3),
  "formattedCardinalityValue": .text(display3),
])
assert(ExactString(message3) == ExactString("ولدان حضرا"))

// CARDINALITY_FEW
let number4 = try NumericValue.forDecimal("3")
let category4 = try Cardinality.forNumber(number4, locale: locale.tag)
assert(category4 == .few)
// This fixed display value makes the translation assertion reproducible.
let display4 = "3"
let message4 = try strings.get("Cardinality.MinimalPair", placeholders: [
  "cardinalityValue": .number(number4),
  "formattedCardinalityValue": .text(display4),
])
assert(ExactString(message4) == ExactString("\u{2068}3\u{2069} أولاد حضروا"))

// CARDINALITY_MANY
let number5 = try NumericValue.forDecimal("11")
let category5 = try Cardinality.forNumber(number5, locale: locale.tag)
assert(category5 == .many)
// This fixed display value makes the translation assertion reproducible.
let display5 = "11"
let message5 = try strings.get("Cardinality.MinimalPair", placeholders: [
  "cardinalityValue": .number(number5),
  "formattedCardinalityValue": .text(display5),
])
assert(ExactString(message5) == ExactString("\u{2068}11\u{2069} ولدًا حضروا"))

// CARDINALITY_OTHER
let number6 = try NumericValue.forDecimal("100")
let category6 = try Cardinality.forNumber(number6, locale: locale.tag)
assert(category6 == .other)
// This fixed display value makes the translation assertion reproducible.
let display6 = "100"
let message6 = try strings.get("Cardinality.MinimalPair", placeholders: [
  "cardinalityValue": .number(number6),
  "formattedCardinalityValue": .text(display6),
])
assert(ExactString(message6) == ExactString("\u{2068}100\u{2069} ولد حضروا"))

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_ZERO - CARDINALITY_ONE

    Matches CARDINALITY_ZERO

  • CARDINALITY_ZERO - CARDINALITY_TWO

    Matches CARDINALITY_ZERO

  • CARDINALITY_ZERO - CARDINALITY_FEW

    Matches CARDINALITY_FEW

  • CARDINALITY_ZERO - CARDINALITY_MANY

    Matches CARDINALITY_MANY

  • CARDINALITY_ZERO - CARDINALITY_OTHER

    Matches CARDINALITY_OTHER

  • CARDINALITY_ONE - CARDINALITY_TWO

    Matches CARDINALITY_OTHER

  • CARDINALITY_ONE - CARDINALITY_FEW

    Matches CARDINALITY_FEW

  • CARDINALITY_ONE - CARDINALITY_MANY

    Matches CARDINALITY_MANY

  • CARDINALITY_ONE - CARDINALITY_OTHER

    Matches CARDINALITY_OTHER

  • CARDINALITY_TWO - CARDINALITY_FEW

    Matches CARDINALITY_FEW

  • CARDINALITY_TWO - CARDINALITY_MANY

    Matches CARDINALITY_MANY

  • CARDINALITY_TWO - CARDINALITY_OTHER

    Matches CARDINALITY_OTHER

  • CARDINALITY_FEW - CARDINALITY_FEW

    Matches CARDINALITY_FEW

  • CARDINALITY_FEW - CARDINALITY_MANY

    Matches CARDINALITY_MANY

  • CARDINALITY_FEW - CARDINALITY_OTHER

    Matches CARDINALITY_OTHER

  • CARDINALITY_MANY - CARDINALITY_FEW

    Matches CARDINALITY_FEW

  • CARDINALITY_MANY - CARDINALITY_MANY

    Matches CARDINALITY_MANY

  • CARDINALITY_MANY - CARDINALITY_OTHER

    Matches CARDINALITY_OTHER

  • CARDINALITY_OTHER - CARDINALITY_ONE

    Matches CARDINALITY_OTHER

  • CARDINALITY_OTHER - CARDINALITY_TWO

    Matches CARDINALITY_OTHER

  • CARDINALITY_OTHER - CARDINALITY_FEW

    Matches CARDINALITY_FEW

  • CARDINALITY_OTHER - CARDINALITY_MANY

    Matches CARDINALITY_MANY

  • 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
ar.json Localized Strings File (Arabic)
{
  "Delivery.Window": {
    "commentary": "Estimated delivery window, expressed as a range of days.",
    "translation": "{{window}}",
    "placeholders": {
      "window": {
        "range": {
          "start": "minDays",
          "end": "maxDays"
        },
        "translations": {
          "CARDINALITY_ZERO": "{{formattedDayRange}} يوم",
          "CARDINALITY_ONE": "{{formattedDayRange}} يوم",
          "CARDINALITY_TWO": "{{formattedDayRange}} يومان",
          "CARDINALITY_FEW": "{{formattedDayRange}} أيام",
          "CARDINALITY_MANY": "{{formattedDayRange}} يومًا",
          "CARDINALITY_OTHER": "{{formattedDayRange}} يوم"
        }
      }
    }
  }
}
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. For this right-to-left locale, the default bidiIsolation, "rtl-locales", wraps caller-supplied formatted values with U+2068 FIRST STRONG ISOLATE and U+2069 POP DIRECTIONAL ISOLATE; the expected strings below show those escapes.

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

const locale = "ar";

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_ZERO range
const minDays = 0;
const formattedMinDays = numberFormat.format(minDays);
const maxDays = 1;
const formattedMaxDays = numberFormat.format(maxDays);
const formattedDayRange = formattedMinDays + "-" + formattedMaxDays;

cardinalityForRange(
  cardinalityForNumber(minDays, locale),
  cardinalityForNumber(maxDays, locale),
  locale
).name;   // => "CARDINALITY_ZERO"
// U+2068 FIRST STRONG ISOLATE begins bidirectional isolation around a caller-supplied value in right-to-left text
// U+2069 POP DIRECTIONAL ISOLATE ends bidirectional isolation around a caller-supplied value in right-to-left text
strings.get("Delivery.Window", { minDays, maxDays, formattedDayRange });   // => "\u20680-1\u2069 يوم"

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. For this right-to-left locale, Lokalized's default BidiIsolation.RTL_LOCALES wraps caller-supplied formatted values with U+2068 FIRST STRONG ISOLATE and U+2069 POP DIRECTIONAL ISOLATE; the expected expressions below show those escapes.

Locale locale = Locale.forLanguageTag("ar");

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_ZERO range
Number minDays = 0;
String formattedMinDays = numberFormat.format(minDays);
Number maxDays = 1;
String formattedMaxDays = numberFormat.format(maxDays);
String formattedDayRange = formattedMinDays + "-" + formattedMaxDays;

assertEquals(Cardinality.ZERO, Cardinality.forRange(
  Cardinality.forNumber(minDays, locale),
  Cardinality.forNumber(maxDays, locale),
  locale
));

// Expected: <FSI>0-1<PDI> يوم
// U+2068 FIRST STRONG ISOLATE begins bidirectional isolation around a caller-supplied value in right-to-left text
// U+2069 POP DIRECTIONAL ISOLATE ends bidirectional isolation around a caller-supplied value in right-to-left text
assertEquals("\u2068" + formattedDayRange + "\u2069 يوم", 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("ar")
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("0")
let end = try NumericValue.forDecimal("1")
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 == .zero)
let message1 = try strings.get("Delivery.Window", placeholders: [
  "minDays": .number(start),
  "maxDays": .number(end),
  "formattedDayRange": .text("0-1"),
])
assert(ExactString(message1) == ExactString("\u{2068}0-1\u{2069} يوم"))

Ordinalities

All ordinal numbers use ORDINALITY_OTHER; no value selects a different form.

Example: اتجه إلى المنعطف الـ 2 يمينًا..

Language-Specific Examples

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

Definiteness in noun phrases

This example contrasts an indefinite direct object, a definite noun, and a definite iḍāfa construct phrase. Construct state describes the relationship between the nouns; it is not a third degree of definiteness.

Language references: University of Oregon - the Arabic definite article, University of Oregon - the iḍāfa construct, Western Kentucky University - Arabic accusative forms

Language forms used: definiteness

Sample localized strings file
ar.json Localized Strings File (Arabic)
{
  "Open {{document}}.": {
    "translation": "افتح {{document}}.",
    "placeholders": {
      "document": {
        "value": "definiteness",
        "translations": {
          "DEFINITENESS_DEFINITE": "الكتاب",
          "DEFINITENESS_INDEFINITE": "كتابًا",
          "DEFINITENESS_CONSTRUCT": "كتاب الطالب"
        }
      }
    }
  }
}
Usage and expected results

JavaScript

import { DEFINITENESS_CONSTRUCT, DEFINITENESS_DEFINITE, DEFINITENESS_INDEFINITE, createStrings } from "lokalized";
import { readStringsFromDirectory } from "lokalized/node";

const locale = "ar";

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

strings.get("Open {{document}}.", { definiteness: DEFINITENESS_DEFINITE });   // => "افتح الكتاب."
strings.get("Open {{document}}.", { definiteness: DEFINITENESS_INDEFINITE });   // => "افتح كتابًا."
strings.get("Open {{document}}.", { definiteness: DEFINITENESS_CONSTRUCT });   // => "افتح كتاب الطالب."

Java

Locale locale = Locale.forLanguageTag("ar");

Strings strings = Strings.withFallbackLocale(locale)
  .localizedStringSupplier(() -> LocalizedStringLoader.loadFromFilesystem(Paths.get("strings")))
  .localeSupplier((matcher) -> matcher.bestMatchFor(locale))
  .build();

assertEquals("افتح الكتاب.", strings.get(
  "Open {{document}}.", Map.of("definiteness", Definiteness.DEFINITE)
));

assertEquals("افتح كتابًا.", strings.get(
  "Open {{document}}.", Map.of("definiteness", Definiteness.INDEFINITE)
));

assertEquals("افتح كتاب الطالب.", strings.get(
  "Open {{document}}.", Map.of("definiteness", Definiteness.CONSTRUCT)
));

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("ar")
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("Open {{document}}.", placeholders: [
  "definiteness": .languageForm(.definiteness(.definite)),
])
assert(ExactString(message1) == ExactString("افتح الكتاب."))

let message2 = try strings.get("Open {{document}}.", placeholders: [
  "definiteness": .languageForm(.definiteness(.indefinite)),
])
assert(ExactString(message2) == ExactString("افتح كتابًا."))

let message3 = try strings.get("Open {{document}}.", placeholders: [
  "definiteness": .languageForm(.definiteness(.construct)),
])
assert(ExactString(message3) == ExactString("افتح كتاب الطالب."))

Solar and lunar article pronunciation

The definite article is written ال in both cases, but its pronunciation assimilates before solar letters. Transliteration makes the selected pronunciation visible: ash-shams versus al-qamar.

Language reference: University of Oregon - the Arabic definite article

Language forms used: phonetics

Sample localized strings file
ar.json Localized Strings File (Arabic)
{
  "Pronounce the definite noun.": {
    "translation": "{{word}}",
    "placeholders": {
      "word": {
        "value": "word",
        "translations": {
          "PHONETIC_SOLAR": "ash-shams (الشمس)",
          "PHONETIC_LUNAR": "al-qamar (القمر)"
        }
      }
    }
  }
}

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_LUNAR, PHONETIC_OTHER, PHONETIC_SOLAR, createStrings } from "lokalized";
import { readStringsFromDirectory } from "lokalized/node";

const locale = "ar";

const phoneticsByTerm = new Map([
  ["الشمس", PHONETIC_SOLAR],
  ["القمر", PHONETIC_LUNAR],
]);
const phoneticResolver = (term) => phoneticsByTerm.get(term) ?? PHONETIC_OTHER;

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

strings.get("Pronounce the definite noun.", { word: "الشمس" });   // => "ash-shams (الشمس)"
strings.get("Pronounce the definite noun.", { word: "القمر" });   // => "al-qamar (القمر)"

Java

Locale locale = Locale.forLanguageTag("ar");

Map<String, Phonetic> phoneticsByTerm = Map.ofEntries(
  Map.entry("الشمس", Phonetic.SOLAR),
  Map.entry("القمر", Phonetic.LUNAR)
);
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("ash-shams (الشمس)", strings.get(
  "Pronounce the definite noun.", Map.of("word", "الشمس")
));

assertEquals("al-qamar (القمر)", strings.get(
  "Pronounce the definite noun.", Map.of("word", "القمر")
));

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

let phoneticsByTerm: [ExactString: Phonetic] = [
  "الشمس": .solar,
  "القمر": .lunar,
]
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("Pronounce the definite noun.", placeholders: [
  "word": .text("الشمس"),
])
assert(ExactString(message1) == ExactString("ash-shams (الشمس)"))

let message2 = try strings.get("Pronounce the definite noun.", placeholders: [
  "word": .text("القمر"),
])
assert(ExactString(message2) == ExactString("al-qamar (القمر)"))

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