Urdu اردو

BCP 47 language tag: ur

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

Urdu is most often spoken in Pakistan, India, the United Kingdom, Canada, and Mauritius.

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 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 ur locale data.

Sample localized strings file
ur.json Localized Strings File (Urdu)
{
  "Cardinality.MinimalPair": {
    "commentary": "Demonstrates every CLDR cardinal category defined for this locale.",
    "translation": "{{cardinalityExample}}",
    "placeholders": {
      "cardinalityExample": {
        "value": "cardinalityValue",
        "translations": {
          "CARDINALITY_ONE": "{{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 = "ur";

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

cardinalityForNumber(oneCardinality, locale).name;   // => "CARDINALITY_ONE"
// 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: oneCardinality,
  formattedCardinalityValue: oneFormattedCardinalityValue,
});   // => "\u20681\u2069 گھنٹہ"

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

cardinalityForNumber(otherCardinality, locale).name;   // => "CARDINALITY_OTHER"
strings.get("Cardinality.MinimalPair", {
  cardinalityValue: otherCardinality,
  formattedCardinalityValue: otherFormattedCardinalityValue,
});   // => "\u20680\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("ur");

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

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

// Expected: <FSI>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" + oneFormattedCardinalityValue + "\u2069 گھنٹہ", strings.get(
  "Cardinality.MinimalPair",
  Map.of("cardinalityValue", oneCardinality, "formattedCardinalityValue", oneFormattedCardinalityValue)
));

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

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

// Expected: <FSI>0<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("ur")
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("Cardinality.MinimalPair", placeholders: [
  "cardinalityValue": .number(number1),
  "formattedCardinalityValue": .text(display1),
])
assert(ExactString(message1) == ExactString("\u{2068}1\u{2069} گھنٹہ"))

// 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("Cardinality.MinimalPair", placeholders: [
  "cardinalityValue": .number(number2),
  "formattedCardinalityValue": .text(display2),
])
assert(ExactString(message2) == ExactString("\u{2068}0\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_ONE - CARDINALITY_OTHER

    Matches CARDINALITY_OTHER

  • CARDINALITY_OTHER - CARDINALITY_ONE

    Matches CARDINALITY_OTHER

  • CARDINALITY_OTHER - CARDINALITY_OTHER

    Matches CARDINALITY_OTHER

Ordinalities

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

Example: دایاں موڑ نمبر 2 مڑیں۔.

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