Add to_ordinal() and to_year() for Croatian#1
Merged
Jetman80 merged 1 commit intoMay 4, 2026
Conversation
PR savoirfairelinux#643 implements cardinals + currency for Croatian but leaves to_ordinal raising NotImplementedError, and to_year falls through to to_cardinal via the base class default. This commit: - Implements masculine-nominative-singular ordinals (prvi, drugi, ..., šesti, dvadeseti, stoti, tisućiti) via last-cardinal-word substitution. - Implements to_year() with feminine-genitive ending (the form actually used before 'godine' in Croatian: 1986 → tisuću devetsto osamdeset šeste). Collapses 'jedna tisuća' → 'tisuću' for years 1000-1999. - Adds ~25 ordinal tests + 5 year tests covering ones (regular and irregular), tens, twenties, hundreds, exact powers of 10, and full 4-digit year forms.
Member
|
@tihomirjauk hvala! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to your Croatian language implementation in this fork (PR savoirfairelinux#643 upstream at savoirfairelinux/num2words).
Per your suggestion in savoirfairelinux#643 (comment) — submitting this against your fork so the implementation is more complete when/if upstream picks it up.
What this adds
Tests
Quick verification
```python
from num2words import num2words
num2words(1986, lang='hr', to='ordinal') # 'jedna tisuća devetsto osamdeset šesti'
num2words(1986, lang='hr', to='year') # 'tisuću devetsto osamdeset šeste'
num2words(2024, lang='hr', to='year') # 'dvije tisuće dvadeset četvrte'
num2words(17, lang='hr', to='ordinal') # 'sedamnaesti'
num2words(1000, lang='hr', to='ordinal') # 'tisućiti'
```
Linguistic note
Croatian ordinals decline by gender, case, and number. This patch only handles masculine nominative singular (the unmarked default form), enough for the most common "X-th" use cases. Full case coverage like Russian's `to_ordinal(case=…, gender=…, plural=…)` is a future enhancement.
`to_year()` returns the feminine genitive form because that's what matches the most common Croatian context: "X. godine" (in the year X). The last word changes ending (-i → -e for ordinals, e.g. "šesti" → "šeste"), and "jedna tisuća" collapses to "tisuću" for years 1000-1999.
Happy to revise per any feedback.