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:
- Engine languages supply
cards+mergeand let the defaultto_cardinaldrivesplitnum/clean(asNum2Word_Basedoes). - Self-contained languages override
to_cardinaloutright 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§
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]
Sourcefn merge(&self, _l: (&str, &BigInt), _r: (&str, &BigInt)) -> (String, BigInt)
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.
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>
Sourcefn currency_forms(&self, _code: &str) -> Option<&CurrencyForms>
fn currency_forms(&self, _code: &str) -> Option<&CurrencyForms>
CURRENCY_FORMS[code]. None -> NotImplementedError, as in Python.
Sourcefn currency_adjective(&self, _code: &str) -> Option<&str>
fn currency_adjective(&self, _code: &str) -> Option<&str>
CURRENCY_ADJECTIVES[code].
Sourcefn currency_precision(&self, _code: &str) -> i64
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.
Sourcefn pluralize(&self, _n: &BigInt, _forms: &[String]) -> Result<String>
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.
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>
Sourcefn to_cardinal_float(
&self,
value: &FloatValue,
precision_override: Option<u32>,
) -> Result<String>
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).
Sourcefn cardinal_from_decimal(&self, value: &BigDecimal) -> Result<String>
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.
Sourcefn to_currency(
&self,
val: &CurrencyValue,
currency: &str,
cents: bool,
separator: Option<&str>,
adjective: bool,
) -> Result<String>
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.
Sourcefn default_separator(&self) -> &str
fn default_separator(&self) -> &str
This language’s own separator= default. Base’s is “,”.
Sourcefn default_adjective(&self) -> bool
fn default_adjective(&self) -> bool
This language’s own to_currency(adjective=...) default. Base’s is
False; only Mongolian defaults to True.
Sourcefn default_currency(&self) -> &str
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.
fn to_cheque(&self, val: &BigDecimal, currency: &str) -> Result<String>
Sourcefn to_fraction(
&self,
numerator: &BigInt,
denominator: &BigInt,
) -> Result<String>
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).
Sourcefn cardinal_float_entry(
&self,
value: &FloatValue,
precision_override: Option<u32>,
) -> Result<String>
fn cardinal_float_entry( &self, value: &FloatValue, precision_override: Option<u32>, ) -> Result<String>
to_cardinal(float/Decimal) — the full entry, whole values included.
Sourcefn ordinal_float_entry(&self, value: &FloatValue) -> Result<String>
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.
Sourcefn ordinal_num_float_entry(
&self,
_value: &FloatValue,
repr_str: &str,
) -> Result<String>
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.
Sourcefn year_float_entry(&self, value: &FloatValue) -> Result<String>
fn year_float_entry(&self, value: &FloatValue) -> Result<String>
to_year(float/Decimal). Base’s to_year is to_cardinal.
Sourcefn str_to_number(&self, s: &str) -> Result<ParsedNumber>
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.
Sourcefn cardinal_with_pointword(
&self,
_value: &FloatValue,
_pointword: &str,
_precision_override: Option<u32>,
) -> Result<String>
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.
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>
Sourcefn es_currency_ordinal_fires(&self) -> bool
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).
Sourcefn neg_zero_decimal(&self, _to: &str) -> Option<Result<String>>
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.
Sourcefn inf_result(&self, _negative: bool, _to: &str) -> Result<String>
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.
Sourcefn nan_result(&self, _to: &str) -> Result<String>
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.
Sourcefn python_maxval(&self) -> Option<BigInt>
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".