Skip to main content

Rule-based number formatting using Unicode CLDR data

Project description

Unicode RBNF

A pure Python implementation of rule based number formatting (RBNF) using the Unicode Common Locale Data Repository (CLDR).

This lets you spell out numbers for a large number of locales:

from unicode_rbnf import RbnfEngine

engine = RbnfEngine.for_language("en")
assert engine.format_number(1234) == "one thousand two hundred thirty-four"

Depending on the locale, different rulesets are supported as well:

from unicode_rbnf import RbnfEngine, RulesetName

engine = RbnfEngine.for_language("en")
assert engine.format_number(1999, RulesetName.YEAR) == "nineteen ninety-nine"
assert engine.format_number(11, RulesetName.ORDINAL) == "eleventh"

Supported locales

See: https://github.com/unicode-org/cldr/tree/release-44/common/rbnf

Engine implementation

Not all features of the RBNF engine are implemented. The following features are available:

  • Literal text (hundred)
  • Quotient substitution (<< or ←←)
  • Reminder substitution (>> or →→)
  • Optional substitution ([...])
  • Rule substituton (←%ruleset_name←)
  • Rule replacement (=%ruleset_name=)
  • Special rules:
    • Negative numbers (-x)
    • Improper fractions (x.x)
    • Not a number (NaN)
    • Infinity (Inf)

Some features that will need to be added eventually:

  • Proper fraction rules (0.x)
  • Preceding reminder substitution (>>> or →→→)
  • Number format strings (==)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

unicode_rbnf-1.2.0.tar.gz (82.9 kB view details)

Uploaded Source

Built Distribution

unicode_rbnf-1.2.0-py3-none-any.whl (136.7 kB view details)

Uploaded Python 3

File details

Details for the file unicode_rbnf-1.2.0.tar.gz.

File metadata

  • Download URL: unicode_rbnf-1.2.0.tar.gz
  • Upload date:
  • Size: 82.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.2

File hashes

Hashes for unicode_rbnf-1.2.0.tar.gz
Algorithm Hash digest
SHA256 320d5d75e47e24413cde87ae8e4bcd8684058a524ff349920c1c79d0fe4071f7
MD5 db3e94b459b0253d0536f1c7648ee83e
BLAKE2b-256 a54f55e7e0eac29fcbd043e66b233f5393c0e4110585dc427d8071e9be30cb24

See more details on using hashes here.

Provenance

File details

Details for the file unicode_rbnf-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: unicode_rbnf-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 136.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.2

File hashes

Hashes for unicode_rbnf-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a3e2ad390d7fa50cda591783e18fa30f3d0b663a064cd271b8a95857564bf3e0
MD5 92850dcaeffc2195d8bf9981450445ca
BLAKE2b-256 435f082a1befa9c18962f4740caffbe64feecbc61e8d3d7d41faa261c50b7d02

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page