Skip to main content

Lang

Trait Lang 

Source
pub trait Lang {
Show 45 methods // Provided methods fn cards(&self) -> &Cards { ... } fn maxval(&self) -> &BigInt { ... } fn negword(&self) -> &str { ... } fn pointword(&self) -> &str { ... } fn is_title(&self) -> bool { ... } fn exclude_title(&self) -> &[String] { ... } fn merge( &self, _l: (&str, &BigInt), _r: (&str, &BigInt), ) -> (String, BigInt) { ... } fn title(&self, value: &str) -> String { ... } fn to_cardinal(&self, value: &BigInt) -> Result<String> { ... } fn to_ordinal(&self, value: &BigInt) -> Result<String> { ... } fn to_ordinal_num(&self, value: &BigInt) -> Result<String> { ... } fn to_year(&self, value: &BigInt) -> Result<String> { ... } fn lang_name(&self) -> &str { ... } fn currency_forms(&self, _code: &str) -> Option<&CurrencyForms> { ... } fn currency_adjective(&self, _code: &str) -> Option<&str> { ... } fn currency_precision(&self, _code: &str) -> i64 { ... } fn pluralize(&self, _n: &BigInt, _forms: &[String]) -> Result<String> { ... } fn money_verbose(&self, number: &BigInt, _currency: &str) -> Result<String> { ... } fn cents_verbose(&self, number: &BigInt, _currency: &str) -> Result<String> { ... } fn cents_terse(&self, number: &BigInt, currency: &str) -> Result<String> { ... } fn to_cardinal_float( &self, value: &FloatValue, precision_override: Option<u32>, ) -> Result<String> { ... } fn cardinal_from_decimal(&self, value: &BigDecimal) -> Result<String> { ... } fn to_currency( &self, val: &CurrencyValue, currency: &str, cents: bool, separator: Option<&str>, adjective: bool, ) -> Result<String> { ... } fn default_separator(&self) -> &str { ... } fn default_adjective(&self) -> bool { ... } fn default_currency(&self) -> &str { ... } fn to_cheque(&self, val: &BigDecimal, currency: &str) -> Result<String> { ... } fn to_fraction( &self, numerator: &BigInt, denominator: &BigInt, ) -> Result<String> { ... } fn cardinal_float_entry( &self, value: &FloatValue, precision_override: Option<u32>, ) -> Result<String> { ... } fn ordinal_float_entry(&self, value: &FloatValue) -> Result<String> { ... } fn ordinal_num_float_entry( &self, _value: &FloatValue, repr_str: &str, ) -> Result<String> { ... } fn year_float_entry(&self, value: &FloatValue) -> Result<String> { ... } fn str_to_number(&self, s: &str) -> Result<ParsedNumber> { ... } fn cardinal_with_pointword( &self, _value: &FloatValue, _pointword: &str, _precision_override: Option<u32>, ) -> Result<String> { ... } fn to_cardinal_kw(&self, value: &BigInt, kw: &Kwargs) -> Result<String> { ... } fn to_ordinal_kw(&self, value: &BigInt, kw: &Kwargs) -> Result<String> { ... } fn to_ordinal_num_kw(&self, value: &BigInt, kw: &Kwargs) -> Result<String> { ... } fn to_year_kw(&self, value: &BigInt, kw: &Kwargs) -> Result<String> { ... } fn to_currency_kw( &self, val: &CurrencyValue, currency: &str, cents: bool, separator: Option<&str>, adjective: bool, kw: &Kwargs, ) -> Result<String> { ... } fn to_cardinal_float_kw( &self, value: &FloatValue, precision_override: Option<u32>, kw: &Kwargs, ) -> Result<String> { ... } fn es_currency_ordinal_fires(&self) -> bool { ... } fn neg_zero_decimal(&self, _to: &str) -> Option<Result<String>> { ... } fn inf_result(&self, _negative: bool, _to: &str) -> Result<String> { ... } fn nan_result(&self, _to: &str) -> Result<String> { ... } fn python_maxval(&self) -> Option<BigInt> { ... }
}
Expand description

The per-language behaviour that base.py leaves abstract or overridable.

Defaults mirror Num2Word_Base; each language overrides what it needs, exactly as the Python subclasses do.

Two shapes exist in the wild, and both must be expressible:

  1. Engine languages supply cards + merge and let the default to_cardinal drive splitnum/clean (as Num2Word_Base does).
  2. Self-contained languages override to_cardinal outright and never touch cards or merge — 121 of the 156 Python modules do this.

So cards/maxval/merge carry defaults rather than being required; a shape-2 language simply ignores them.

Provided Methods§

Source

fn cards(&self) -> &Cards

Source

fn maxval(&self) -> &BigInt

Source

fn negword(&self) -> &str

Source

fn pointword(&self) -> &str

Source

fn is_title(&self) -> bool

Source

fn exclude_title(&self) -> &[String]

Source

fn merge(&self, _l: (&str, &BigInt), _r: (&str, &BigInt)) -> (String, BigInt)

merge is abstract in Python (raise NotImplementedError). Languages that override to_cardinal never reach it.

Source

fn title(&self, value: &str) -> String

Source

fn to_cardinal(&self, value: &BigInt) -> Result<String>

Source

fn to_ordinal(&self, value: &BigInt) -> Result<String>

Source

fn to_ordinal_num(&self, value: &BigInt) -> Result<String>

Source

fn to_year(&self, value: &BigInt) -> Result<String>

Source

fn lang_name(&self) -> &str

Class name, for the 'X' not implemented for 'Num2Word_Y' message.

Source

fn currency_forms(&self, _code: &str) -> Option<&CurrencyForms>

CURRENCY_FORMS[code]. None -> NotImplementedError, as in Python.

Source

fn currency_adjective(&self, _code: &str) -> Option<&str>

CURRENCY_ADJECTIVES[code].

Source

fn currency_precision(&self, _code: &str) -> i64

CURRENCY_PRECISION.get(code, 100) — subunits per unit. 1000 for 3-decimal currencies (BHD/KWD/…), 1 for no-subunit currencies.

Source

fn pluralize(&self, _n: &BigInt, _forms: &[String]) -> Result<String>

pluralize(n, forms). Abstract in Python (raise NotImplementedError), so the default raises rather than guessing a plural rule.

Source

fn money_verbose(&self, number: &BigInt, _currency: &str) -> Result<String>

Source

fn cents_verbose(&self, number: &BigInt, _currency: &str) -> Result<String>

Source

fn cents_terse(&self, number: &BigInt, currency: &str) -> Result<String>

Source

fn to_cardinal_float( &self, value: &FloatValue, precision_override: Option<u32>, ) -> Result<String>

Num2Word_Base.to_cardinal_float. precision_override is the precision= kwarg (issue #580).

Source

fn cardinal_from_decimal(&self, value: &BigDecimal) -> Result<String>

Render a non-integral value, for the fractional-cents branch. Python reaches this as self.to_cardinal(float(right)), i.e. through the float path, so the default routes there rather than raising.

Source

fn to_currency( &self, val: &CurrencyValue, currency: &str, cents: bool, separator: Option<&str>, adjective: bool, ) -> Result<String>

separator: None means the caller omitted the kwarg, so the language’s own default applies. Python expresses this as a per-method default (Num2Word_CA.to_currency(..., separator=" amb")), which a plain &str cannot represent: once the shim substitutes Base’s “,”, “caller omitted it” and “caller passed a comma” are indistinguishable.

Source

fn default_separator(&self) -> &str

This language’s own separator= default. Base’s is “,”.

Source

fn default_adjective(&self) -> bool

This language’s own to_currency(adjective=...) default. Base’s is False; only Mongolian defaults to True.

Source

fn default_currency(&self) -> &str

This language’s own to_currency(currency=...) default. Base’s is “EUR”, but only 44 of 156 languages actually use it — en_IN defaults to INR, id to IDR, af to ZAR, and so on. Hardcoding EUR in the dispatcher silently converts the wrong currency.

Source

fn to_cheque(&self, val: &BigDecimal, currency: &str) -> Result<String>

Source

fn to_fraction( &self, numerator: &BigInt, denominator: &BigInt, ) -> Result<String>

Num2Word_Base.to_fraction (issue #584). EN/DE/ES/FR/IT/PT and the aero profiles override with idiomatic forms (half/quarter/Drittel).

Source

fn cardinal_float_entry( &self, value: &FloatValue, precision_override: Option<u32>, ) -> Result<String>

to_cardinal(float/Decimal) — the full entry, whole values included.

Source

fn ordinal_float_entry(&self, value: &FloatValue) -> Result<String>

to_ordinal(float/Decimal). Base’s to_ordinal is to_cardinal, so the default routes identically; languages with verify_ordinal-style type checks (TypeError on non-int) override.

Source

fn ordinal_num_float_entry( &self, _value: &FloatValue, repr_str: &str, ) -> Result<String>

to_ordinal_num(float/Decimal). Base returns the value unchanged and the dispatcher str()s it, so the default echoes the Python repr the binding computed.

Source

fn year_float_entry(&self, value: &FloatValue) -> Result<String>

to_year(float/Decimal). Base’s to_year is to_cardinal.

Source

fn str_to_number(&self, s: &str) -> Result<ParsedNumber>

converter.str_to_number. Base is Decimal(value); ES (“1ro” -> ordinal handshake), PT_BR (“1.50” -> ‘ponto’), DV (TypeError instead of InvalidOperation), BN (abs()) and ID override.

Source

fn cardinal_with_pointword( &self, _value: &FloatValue, _pointword: &str, _precision_override: Option<u32>, ) -> Result<String>

The pt_BR ‘ponto’ rendering: to_cardinal(value) with the pointword swapped for this one call. Only reachable through ParsedNumber::DecPoint, so only PT_BR implements it.

Source

fn to_cardinal_kw(&self, value: &BigInt, kw: &Kwargs) -> Result<String>

Source

fn to_ordinal_kw(&self, value: &BigInt, kw: &Kwargs) -> Result<String>

Source

fn to_ordinal_num_kw(&self, value: &BigInt, kw: &Kwargs) -> Result<String>

Source

fn to_year_kw(&self, value: &BigInt, kw: &Kwargs) -> Result<String>

Source

fn to_currency_kw( &self, val: &CurrencyValue, currency: &str, cents: bool, separator: Option<&str>, adjective: bool, kw: &Kwargs, ) -> Result<String>

Source

fn to_cardinal_float_kw( &self, value: &FloatValue, precision_override: Option<u32>, kw: &Kwargs, ) -> Result<String>

Source

fn es_currency_ordinal_fires(&self) -> bool

Spanish “1ro” currency: does the stashed ordinal fire? Num2Word_ES apocopates 1 → “un euro” in to_currency, bypassing to_cardinal, so the stash never fires (false, the default). The regional es_XX classes inherit Base.to_currency, whose _money_verbose calls to_cardinal(1) → the stash fires → “primero córdoba” (true).

Source

fn neg_zero_decimal(&self, _to: &str) -> Option<Result<String>>

Render Decimal('-0.0') for mode to, which BigDecimal cannot represent (it has no signed zero). None — the default — means the value coincides with float -0.0, so the binding’s Float{-0.0} demotion is exact. The ~10 languages that render the Decimal form differently (ce/cy “dim”/“ноль” via the integer path, pl its float grammar with the negword, rm a TypeError) override this to serve it natively instead of leaning on a Python fallback.

Source

fn inf_result(&self, _negative: bool, _to: &str) -> Result<String>

str_to_number produced Decimal('Infinity') / -Infinity. Base’s integer path does int(Decimal('Infinity')) → OverflowError. The many self-contained converters that feed the raw token to int("Infinity") get ValueError instead and override this. to is the requested mode.

Source

fn nan_result(&self, _to: &str) -> Result<String>

str_to_number produced Decimal('NaN'). Base’s int(NaN) raises ValueError (caught into the float path, which raises ValueError again). Languages whose parse raises decimal.InvalidOperation first override.

Source

fn python_maxval(&self) -> Option<BigInt>

Python’s getattr(converter, "MAXVAL", None) — the maxval() API. Engine languages get it from their card table (Base sets MAXVAL = 1000 * top_card); self-contained ones mostly lack the attribute (None). The zero sentinel in maxval() means “unset”.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl Lang for LangAf

Source§

impl Lang for LangAm

Source§

impl Lang for LangAr

Source§

impl Lang for LangAs

Source§

impl Lang for LangAz

Source§

impl Lang for LangBa

Source§

impl Lang for LangBan

Source§

impl Lang for LangBe

Source§

impl Lang for LangBg

Source§

impl Lang for LangBm

Source§

impl Lang for LangBn

Source§

impl Lang for LangBo

Source§

impl Lang for LangBr

Source§

impl Lang for LangBs

Source§

impl Lang for LangCa

Source§

impl Lang for LangCe

Source§

impl Lang for LangCeb

Source§

impl Lang for LangCkb

Source§

impl Lang for LangCnh

Source§

impl Lang for LangCs

Source§

impl Lang for LangCy

Source§

impl Lang for LangDa

Source§

impl Lang for LangDe

Source§

impl Lang for LangDv

Source§

impl Lang for LangEl

Source§

impl Lang for LangEn

Source§

impl Lang for LangEnAero

Source§

impl Lang for LangEnAeroFaa

Source§

impl Lang for LangEnAeroNato

Source§

impl Lang for LangEnAeroUsArmy

Source§

impl Lang for LangEnAeroUsn

Source§

impl Lang for LangEnIn

Source§

impl Lang for LangEnNe

Source§

impl Lang for LangEnNg

Source§

impl Lang for LangEnNp

Source§

impl Lang for LangEo

Source§

impl Lang for LangEs

Source§

impl Lang for LangEsCo

Source§

impl Lang for LangEsCr

Source§

impl Lang for LangEsGt

Source§

impl Lang for LangEsHn

Source§

impl Lang for LangEsNi

Source§

impl Lang for LangEsVe

Source§

impl Lang for LangEt

Source§

impl Lang for LangEu

Source§

impl Lang for LangFa

Source§

impl Lang for LangFf

Source§

impl Lang for LangFi

Source§

impl Lang for LangFil

Source§

impl Lang for LangFo

Source§

impl Lang for LangFr

Source§

impl Lang for LangFrBe

Source§

impl Lang for LangFrCh

Source§

impl Lang for LangFrDz

Source§

impl Lang for LangGl

Source§

impl Lang for LangGu

Source§

impl Lang for LangHa

Source§

impl Lang for LangHaw

Source§

impl Lang for LangHe

Source§

impl Lang for LangHi

Source§

impl Lang for LangHmn

Source§

impl Lang for LangHr

Source§

impl Lang for LangHt

Source§

impl Lang for LangHu

Source§

impl Lang for LangHy

Source§

impl Lang for LangId

Source§

impl Lang for LangIs

Source§

impl Lang for LangIt

Source§

impl Lang for LangJa

Source§

impl Lang for LangJv

Source§

impl Lang for LangKa

Source§

impl Lang for LangKi

Source§

impl Lang for LangKk

Source§

impl Lang for LangKm

Source§

impl Lang for LangKn

Source§

impl Lang for LangKo

Source§

impl Lang for LangKok

Source§

impl Lang for LangKsw

Source§

impl Lang for LangKu

Source§

impl Lang for LangKy

Source§

impl Lang for LangKz

Source§

impl Lang for LangLa

Source§

impl Lang for LangLb

Source§

impl Lang for LangLg

Source§

impl Lang for LangLij

Source§

impl Lang for LangLn

Source§

impl Lang for LangLo

Source§

impl Lang for LangLt

Source§

impl Lang for LangLus

Source§

impl Lang for LangLv

Source§

impl Lang for LangMg

Source§

impl Lang for LangMi

Source§

impl Lang for LangMk

Source§

impl Lang for LangMl

Source§

impl Lang for LangMn

Source§

impl Lang for LangMr

Source§

impl Lang for LangMs

Source§

impl Lang for LangMt

Source§

impl Lang for LangMy

Source§

impl Lang for LangNb

Source§

impl Lang for LangNe

Source§

impl Lang for LangNl

Source§

impl Lang for LangNn

Source§

impl Lang for LangOc

Source§

impl Lang for LangOm

Source§

impl Lang for LangOr

Source§

impl Lang for LangPa

Source§

impl Lang for LangPap

Source§

impl Lang for LangPl

Source§

impl Lang for LangPli

Source§

impl Lang for LangPs

Source§

impl Lang for LangPt

Source§

impl Lang for LangPtBr

Source§

impl Lang for LangRm

Source§

impl Lang for LangRmPuter

Source§

impl Lang for LangRmSurmiran

Source§

impl Lang for LangRmSursilv

Source§

impl Lang for LangRmSutsilv

Source§

impl Lang for LangRmVallader

Source§

impl Lang for LangRo

Source§

impl Lang for LangRu

Source§

impl Lang for LangRw

Source§

impl Lang for LangSa

Source§

impl Lang for LangSd

Source§

impl Lang for LangSi

Source§

impl Lang for LangSk

Source§

impl Lang for LangSl

Source§

impl Lang for LangSn

Source§

impl Lang for LangSo

Source§

impl Lang for LangSq

Source§

impl Lang for LangSr

Source§

impl Lang for LangSrLatn

Source§

impl Lang for LangSu

Source§

impl Lang for LangSv

Source§

impl Lang for LangSw

Source§

impl Lang for LangTa

Source§

impl Lang for LangTe

Source§

impl Lang for LangTet

Source§

impl Lang for LangTg

Source§

impl Lang for LangTh

Source§

impl Lang for LangTi

Source§

impl Lang for LangTk

Source§

impl Lang for LangTl

Source§

impl Lang for LangTr

Source§

impl Lang for LangTt

Source§

impl Lang for LangUk

Source§

impl Lang for LangUr

Source§

impl Lang for LangUz

Source§

impl Lang for LangUzCyr

Source§

impl Lang for LangVi

Source§

impl Lang for LangWo

Source§

impl Lang for LangXh

Source§

impl Lang for LangYi

Source§

impl Lang for LangYo

Source§

impl Lang for LangZh

Source§

impl Lang for LangZhHk

Source§

impl Lang for LangZhTw

Source§

impl Lang for LangZu