Brazilian Portuguese português (Brasil)

BCP 47 language tag: pt-BR

Lokalized supports cardinality, cardinality range, and ordinality rules for Brazilian Portuguese.

Additional modeled concepts for Brazilian Portuguese: grammatical gender.

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 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
pt-BR.json Localized Strings File (Brazilian Portuguese)
{
  "Delivery.LeadTime": {
    "commentary": "Estimated delivery time, expressed in days.",
    "translation": "{{leadTime}}",
    "placeholders": {
      "leadTime": {
        "value": "dayCount",
        "translations": {
          "CARDINALITY_ONE": "{{formattedDayCount}} dia",
          "CARDINALITY_MANY": "{{formattedDayCount}} dias",
          "CARDINALITY_OTHER": "{{formattedDayCount}} dias"
        }
      }
    }
  }
}
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 = "pt-BR";

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

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

// CARDINALITY_MANY
const manyDayCount = 1_000_000;
const manyFormattedDayCount = numberFormat.format(manyDayCount);

cardinalityForNumber(manyDayCount, locale).name;   // => "CARDINALITY_MANY"
strings.get("Delivery.LeadTime", {
  dayCount: manyDayCount,
  formattedDayCount: manyFormattedDayCount,
});   // => "1.000.000 dias"

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

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

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

localeProfileFormattedDayCount;   // => "1.000.000"
cardinalityForNumber(localeProfileDayCount, locale).name;   // => "CARDINALITY_MANY"
strings.get("Delivery.LeadTime", {
  dayCount: localeProfileDayCount,
  formattedDayCount: localeProfileFormattedDayCount,
});   // => "1.000.000 dias"

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

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

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

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

// CARDINALITY_MANY
Number manyDayCount = 1_000_000;
String manyFormattedDayCount = numberFormat.format(manyDayCount);

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

// Expected: 1.000.000 dias
assertEquals(manyFormattedDayCount + " dias", strings.get(
  "Delivery.LeadTime", Map.of("dayCount", manyDayCount, "formattedDayCount", manyFormattedDayCount)
));

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

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

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

// Expected: 1.000.000 dias
assertEquals(localeProfileFormattedDayCount + " dias", 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("pt-BR")
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("Delivery.LeadTime", placeholders: [
  "dayCount": .number(number1),
  "formattedDayCount": .text(display1),
])
assert(ExactString(message1) == ExactString("0 dia"))

// 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.000.000"
let message2 = try strings.get("Delivery.LeadTime", placeholders: [
  "dayCount": .number(number2),
  "formattedDayCount": .text(display2),
])
assert(ExactString(message2) == ExactString("1.000.000 dias"))

// 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("Delivery.LeadTime", placeholders: [
  "dayCount": .number(number3),
  "formattedDayCount": .text(display3),
])
assert(ExactString(message3) == ExactString("2 dias"))

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
pt-BR.json Localized Strings File (Brazilian Portuguese)
{
  "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}} dia",
          "CARDINALITY_MANY": "{{formattedDayRange}} dias",
          "CARDINALITY_OTHER": "{{formattedDayRange}} dias"
        }
      }
    }
  }
}
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 = "pt-BR";

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 dia"

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

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 dia
assertEquals(formattedDayRange + " dia", 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("pt-BR")
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 dia"))

Ordinalities

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

Example: Pegue a 2ª à direita..

Language-Specific Examples

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

Customer status by gender

Portuguese articles and predicate adjectives can change together when a customer label refers to a man or a woman.

Language references: Infopédia: cliente is a two-gender noun, Ciberdúvidas: adjective agreement in Portuguese

Language forms used: gender

Sample localized strings file
pt-BR.json Localized Strings File (Brazilian Portuguese)
{
  "The customer is active.": {
    "translation": "{{customer}} está {{active}}.",
    "placeholders": {
      "customer": {
        "value": "gender",
        "translations": {
          "GENDER_MASCULINE": "O cliente",
          "GENDER_FEMININE": "A cliente"
        }
      },
      "active": {
        "value": "gender",
        "translations": {
          "GENDER_MASCULINE": "ativo",
          "GENDER_FEMININE": "ativa"
        }
      }
    }
  }
}
Usage and expected results

JavaScript

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

const locale = "pt-BR";

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

strings.get("The customer is active.", { gender: GENDER_MASCULINE });   // => "O cliente está ativo."
strings.get("The customer is active.", { gender: GENDER_FEMININE });   // => "A cliente está ativa."

Java

Locale locale = Locale.forLanguageTag("pt-BR");

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

assertEquals("O cliente está ativo.", strings.get(
  "The customer is active.", Map.of("gender", Gender.MASCULINE)
));

assertEquals("A cliente está ativa.", 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("pt-BR")
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("O cliente está ativo."))

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

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