French français

BCP 47 language tag: fr

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

Additional modeled concepts for French: grammatical gender; sound-dependent word forms.

French is most often spoken in France, Congo - Kinshasa, Cameroon, Algeria, and Germany.

Cardinalities

  • CARDINALITY_ONE

    Matches i = 0,1

    Example Integers: 0, 1

    Example Decimals: 0.0, 1.5

  • CARDINALITY_MANY

    Matches e = 0 and i != 0 and i % 1000000 = 0 and v = 0 or e != 0..5

    Example Integers: 1000000, …

  • CARDINALITY_OTHER

    Matches all other values

    Example Integers: 2, 17, 100, 1000, 10000, 100000, …

    Example Decimals: 2.0, 3.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 fr locale data.

Sample localized strings file
fr.json Localized Strings File (French)
{
  "Cardinality.MinimalPair": {
    "commentary": "Demonstrates every CLDR cardinal category defined for this locale.",
    "translation": "{{cardinalityExample}}",
    "placeholders": {
      "cardinalityExample": {
        "value": "cardinalityValue",
        "translations": {
          "CARDINALITY_ONE": "{{formattedCardinalityValue}} jour",
          "CARDINALITY_MANY": "{{formattedCardinalityValue}} de jours",
          "CARDINALITY_OTHER": "{{formattedCardinalityValue}} jours"
        }
      }
    }
  }
}
Usage and expected results

JavaScript

The JavaScript code passes each raw number for cardinality selection and formats its display value separately with Intl.NumberFormat.

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

const locale = "fr";

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 oneCardinality = 0;
const oneFormattedCardinalityValue = numberFormat.format(oneCardinality);

cardinalityForNumber(oneCardinality, locale).name;   // => "CARDINALITY_ONE"
strings.get("Cardinality.MinimalPair", {
  cardinalityValue: oneCardinality,
  formattedCardinalityValue: oneFormattedCardinalityValue,
});   // => "0 jour"

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

cardinalityForNumber(manyCardinality, locale).name;   // => "CARDINALITY_MANY"
// U+202F NARROW NO-BREAK SPACE preserves exact narrow, nonbreaking spacing from localized source text or locale formatting
strings.get("Cardinality.MinimalPair", {
  cardinalityValue: manyCardinality,
  formattedCardinalityValue: manyFormattedCardinalityValue,
});   // => "1\u202F000\u202F000 de jours"

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

cardinalityForNumber(otherCardinality, locale).name;   // => "CARDINALITY_OTHER"
strings.get("Cardinality.MinimalPair", {
  cardinalityValue: otherCardinality,
  formattedCardinalityValue: otherFormattedCardinalityValue,
});   // => "2 jours"

Java

The Java code passes each raw number for cardinality selection and formats its display value separately with NumberFormat.

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

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 oneCardinality = 0;
String oneFormattedCardinalityValue = numberFormat.format(oneCardinality);

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

// Expected: 0 jour
assertEquals(oneFormattedCardinalityValue + " jour", strings.get(
  "Cardinality.MinimalPair",
  Map.of("cardinalityValue", oneCardinality, "formattedCardinalityValue", oneFormattedCardinalityValue)
));

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

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

// Expected: 1<NNBSP>000<NNBSP>000 de jours
assertEquals(manyFormattedCardinalityValue + " de jours", strings.get(
  "Cardinality.MinimalPair",
  Map.of(
    "cardinalityValue", manyCardinality,
    "formattedCardinalityValue", manyFormattedCardinalityValue
  )
));

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

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

// Expected: 2 jours
assertEquals(otherFormattedCardinalityValue + " jours", 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("fr")
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("0")
let category1 = try Cardinality.forNumber(number1, locale: locale.tag)
assert(category1 == .one)
// 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("0 jour"))

// CARDINALITY_MANY
let number2 = try NumericValue.forDecimal("1000000")
let category2 = try Cardinality.forNumber(number2, locale: locale.tag)
assert(category2 == .many)
// This fixed display value makes the translation assertion reproducible.
let display2 = "1\u{202F}000\u{202F}000"
let message2 = try strings.get("Cardinality.MinimalPair", placeholders: [
  "cardinalityValue": .number(number2),
  "formattedCardinalityValue": .text(display2),
])
assert(ExactString(message2) == ExactString("1\u{202F}000\u{202F}000 de jours"))

// CARDINALITY_OTHER
let number3 = try NumericValue.forDecimal("2")
let category3 = try Cardinality.forNumber(number3, locale: locale.tag)
assert(category3 == .other)
// 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("2 jours"))

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_ONE

    Matches CARDINALITY_ONE

  • CARDINALITY_ONE - CARDINALITY_OTHER

    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
fr.json Localized Strings File (French)
{
  "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}} jour",
          "CARDINALITY_MANY": "{{formattedDayRange}} jours",
          "CARDINALITY_OTHER": "{{formattedDayRange}} jours"
        }
      }
    }
  }
}
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 = "fr";

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_ONE 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_ONE"
strings.get("Delivery.Window", { minDays, maxDays, formattedDayRange });   // => "0-1 jour"

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

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

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

// Expected: 0-1 jour
assertEquals(formattedDayRange + " jour", 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("fr")
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 == .one)
let message1 = try strings.get("Delivery.Window", placeholders: [
  "minDays": .number(start),
  "maxDays": .number(end),
  "formattedDayRange": .text("0-1"),
])
assert(ExactString(message1) == ExactString("0-1 jour"))

Ordinalities

  • ORDINALITY_ONE

    Matches n = 1

    Example Integers: 1

  • ORDINALITY_OTHER

    Matches all other values

    Example 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 fr locale data.

Sample localized strings file
fr.json Localized Strings File (French)
{
  "Ordinal.MinimalPair": {
    "commentary": "Demonstrates every CLDR ordinal category defined for this locale.",
    "translation": "{{ordinalExample}}",
    "placeholders": {
      "ordinalExample": {
        "value": "ordinalValue",
        "translations": {
          "ORDINALITY_ONE": "Prenez la {{formattedOrdinalValue}}re à droite.",
          "ORDINALITY_OTHER": "Prenez la {{formattedOrdinalValue}}e à droite."
        }
      }
    }
  }
}
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 = "fr";

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,
});   // => "Prenez la 1re à droite."

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

ordinalityForNumber(otherOrdinalValue, locale).name;   // => "ORDINALITY_OTHER"
strings.get("Ordinal.MinimalPair", {
  ordinalValue: otherOrdinalValue,
  formattedOrdinalValue: otherFormattedOrdinalValue,
});   // => "Prenez la 2e à droite."

Java

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

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

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: Prenez la 1re à droite.
assertEquals("Prenez la " + oneFormattedOrdinalValue + "re à droite.", 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: Prenez la 2e à droite.
assertEquals("Prenez la " + otherFormattedOrdinalValue + "e à droite.", 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("fr")
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("Prenez la 1re à droite."))

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("Prenez la 2e à droite."))

Language-Specific Examples

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

Customer status by gender

French customer labels and predicate adjectives agree in gender, producing client actif for masculine and cliente active for feminine.

Language references: OQLF: client actif, cliente active, OQLF: subject-complement adjective agreement

Language forms used: gender

Sample localized strings file
fr.json Localized Strings File (French)
{
  "The customer is active.": {
    "translation": "{{customer}} est {{active}}.",
    "placeholders": {
      "customer": {
        "value": "gender",
        "translations": {
          "GENDER_MASCULINE": "Le client",
          "GENDER_FEMININE": "La cliente"
        }
      },
      "active": {
        "value": "gender",
        "translations": {
          "GENDER_MASCULINE": "actif",
          "GENDER_FEMININE": "active"
        }
      }
    }
  }
}
Usage and expected results

JavaScript

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

const locale = "fr";

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

strings.get("The customer is active.", { gender: GENDER_MASCULINE });   // => "Le client est actif."
strings.get("The customer is active.", { gender: GENDER_FEMININE });   // => "La cliente est active."

Java

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

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

assertEquals("Le client est actif.", strings.get(
  "The customer is active.", Map.of("gender", Gender.MASCULINE)
));

assertEquals("La cliente est active.", strings.get(
  "The customer is active.", Map.of("gender", Gender.FEMININE)
));

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("fr")
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("The customer is active.", placeholders: [
  "gender": .languageForm(.gender(.masculine)),
])
assert(ExactString(message1) == ExactString("Le client est actif."))

let message2 = try strings.get("The customer is active.", placeholders: [
  "gender": .languageForm(.gender(.feminine)),
])
assert(ExactString(message2) == ExactString("La cliente est active."))

Definite-article elision by phonetic onset

French elides le or la before a vowel or h muet, but retains the full article before h aspiré; these forms cover common application content and navigation labels.

Language references: OQLF: elision before vowels, h muet, and h aspiré, OQLF: h muet pronunciation and elision

Language forms used: phonetics

Sample localized strings file
fr.json Localized Strings File (French)
{
  "Display {{content}}.": {
    "translation": "Affichez {{content}}.",
    "placeholders": {
      "content": {
        "value": "content",
        "translations": {
          "PHONETIC_VOWEL": "l'aperçu",
          "PHONETIC_H_SILENT": "l'historique",
          "PHONETIC_H_ASPIRATED": "le haut de la page"
        }
      }
    }
  }
}

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

const locale = "fr";

const phoneticsByTerm = new Map([
  ["aperçu", PHONETIC_VOWEL],
  ["historique", PHONETIC_H_SILENT],
  ["haut de la page", PHONETIC_H_ASPIRATED],
]);
const phoneticResolver = (term) => phoneticsByTerm.get(term) ?? PHONETIC_OTHER;

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

strings.get("Display {{content}}.", { content: "aperçu" });   // => "Affichez l'aperçu."
strings.get("Display {{content}}.", { content: "historique" });   // => "Affichez l'historique."
strings.get("Display {{content}}.", { content: "haut de la page" });   // => "Affichez le haut de la page."

Java

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

Map<String, Phonetic> phoneticsByTerm = Map.ofEntries(
  Map.entry("aperçu", Phonetic.VOWEL),
  Map.entry("historique", Phonetic.H_SILENT),
  Map.entry("haut de la page", Phonetic.H_ASPIRATED)
);
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("Affichez l'aperçu.", strings.get(
  "Display {{content}}.", Map.of("content", "aperçu")
));

assertEquals("Affichez l'historique.", strings.get(
  "Display {{content}}.", Map.of("content", "historique")
));

assertEquals("Affichez le haut de la page.", strings.get(
  "Display {{content}}.", Map.of("content", "haut de la page")
));

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

let phoneticsByTerm: [ExactString: Phonetic] = [
  "aperçu": .vowel,
  "historique": .hSilent,
  "haut de la page": .hAspirated,
]
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("Display {{content}}.", placeholders: [
  "content": .text("aperçu"),
])
assert(ExactString(message1) == ExactString("Affichez l'aperçu."))

let message2 = try strings.get("Display {{content}}.", placeholders: [
  "content": .text("historique"),
])
assert(ExactString(message2) == ExactString("Affichez l'historique."))

let message3 = try strings.get("Display {{content}}.", placeholders: [
  "content": .text("haut de la page"),
])
assert(ExactString(message3) == ExactString("Affichez le haut de la page."))

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