Skip to content

Add Brazilian Portuguese (pt-BR) support#275

Open
roperes98 wants to merge 2 commits intoforzagreen:mainfrom
roperes98:pt-br-support
Open

Add Brazilian Portuguese (pt-BR) support#275
roperes98 wants to merge 2 commits intoforzagreen:mainfrom
roperes98:pt-br-support

Conversation

@roperes98
Copy link
Copy Markdown

📌 Pull Request: Add Brazilian Portuguese (pt-BR) support

✨ Summary

This PR adds full support for Brazilian Portuguese (pt-BR) to the library, including:

  • Cardinal numbers (integers and decimals)
  • Ordinal numbers
  • Currency formatting (BRL - Real)

The implementation follows Brazilian Portuguese linguistic rules and CLDR conventions.


🇧🇷 Features

🔢 Cardinal numbers

  • Correct use of conjunction "e" between hundreds, tens, and units

    • Example: cento e vinte e três
  • Proper handling of:

    • "cem" (exact 100)
    • "cento" (100+ remainder)
  • Omission of "um" before "mil"

    • Example: mil (not um mil)
  • Support for large numbers using short scale:

    • milhão (10⁶), bilhão (10⁹), trilhão (10¹²), etc.

🔟 Ordinal numbers

  • Full ordinal support with proper composition:

    • primeiro, décimo segundo, centésimo, etc.
  • Scalable to large numbers using ordinal scale forms:

    • milésimo, milionésimo, etc.

💰 Currency (BRL)

  • Converts values to Brazilian Real format:

    • 1um real
    • 2.50dois reais e cinquenta centavos
  • Handles pluralization correctly:

    • real / reais
    • centavo / centavos
  • Optional "e" conjunction between reais and centavos


⚙️ Implementation details

  • Uses BigInt-based segmentation for efficient large number handling

  • Modular structure aligned with existing parsers:

    • parseCardinalValue
    • parseOrdinalValue
    • parseCurrencyValue
  • Optimized fast paths for:

    • < 1000
    • < 1,000,000
  • Precomputed scale words (singular and plural)


🧠 Language-specific rules covered

  • Conjunction rules with "e"

  • Irregular hundreds:

    • duzentos, trezentos, quinhentos, etc.
  • Decimal separator: "vírgula"

  • Negative numbers: "menos"


✅ Examples

toCardinal(123)
// cento e vinte e três

toOrdinal(21)
// vigésimo primeiro

toCurrency(42.5)
// quarenta e dois reais e cinquenta centavos

🚀 Notes

  • Follows CLDR: pt-BR
  • Designed to be consistent with existing language implementations
  • No breaking changes

@TylerVigario
Copy link
Copy Markdown
Collaborator

Hey @roperes98, thanks for the pt-BR contribution — the implementation looks solid!

A couple of things are missing before we can merge:

  1. Test fixture (test/fixtures/pt-BR.js) — needs cardinal, ordinal, and currency test case mappings filled out
  2. LANGUAGES.md — needs regenerating (happens automatically with npm run lang:add)

I've got the scaffold ready on my end — I can push it to your branch if you'd like, or you can run npm run lang:add pt-BR yourself. Either way, just need you to fill in the test cases.

Let me know how you'd like to proceed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants