Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New languages: Welsh (Celtic) and Chechen (Nakho-Dagestanian) #543

Merged
merged 11 commits into from
Mar 28, 2024
2 changes: 2 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ Besides the numerical argument, there are two main optional arguments, ``to:`` a
* ``ar`` (Arabic)
* ``az`` (Azerbaijani)
* ``by`` (Belarusian)
* ``ce`` (Chechen)
* ``cy`` (Welsh)
* ``cz`` (Czech)
* ``de`` (German)
* ``dk`` (Danish)
Expand Down
70 changes: 70 additions & 0 deletions num2words/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Add new language

for each new language you must create a file `lang_NN.py` where `NN` is the
ISO 639-1 or ISO 639-3 [language code](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes).

This class must be a subclass of `Num2Word_EU` and implement at least the following methods

```
to_cardinal(self, number)
to_ordinal(self, number)
``

To integrate your language into the `num2words` module, add the name of your file
to the import list in [num2words/__init__.py](num2words/__init__.py) (top of the file),
and `'nn': lang_NN.Num2Word_NN()` to the `CONVERTER_CLASSES` list in the same file.
Do not forget to remplace `NN` by the appropriate ISO 639 language code.

The following is a template for a new language class

```
from .lang_EU import Num2Word_EU

class Num2Word_CY(Num2Word_EU):
def setup(self):
Num2Word_EU.setup(self)

def __init__(self):
pass

def to_ordinal(self, number):
# implement here your code. number is the integer to be transformed into an ordinal
# as a word (str)
# which is returned
return "NOT IMPLEMENTED"

def to_cardinal(self, number):
# implement here your code. number is the integer to be transformed into an cardinal
# as a word (str)
# which is returned
return "NOT IMPLEMENTED"
```

You can use as manu auxiliary methods as you need to make your code efficient and readable.
If you need further options like Gender, Formal/Informal, add those parameters to the methods,
e.g.

```
def to_ordinal(self, number, gender="fem", informal=True)
# your code
pass
```

More inspiration can be found in existing `num2words/lang_NN.py` files

## Code validation

In order to get your contribution merged into the main project, your code must test the validation tests.
For this install the packages needed to test

```
pip install -r requirements-test.txt
```

run `tox` and `coverage` to check that the code is well formated and all parts of the code are tested

```
tox
python3 -m coverage report -m
```

19 changes: 11 additions & 8 deletions num2words/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,23 @@

from __future__ import unicode_literals

from . import (lang_AM, lang_AR, lang_AZ, lang_BY, lang_CZ, lang_DE, lang_DK,
lang_EN, lang_EN_IN, lang_EN_NG, lang_EO, lang_ES, lang_ES_CO,
lang_ES_CR, lang_ES_GT, lang_ES_NI, lang_ES_VE, lang_FA,
lang_FI, lang_FR, lang_FR_BE, lang_FR_CH, lang_FR_DZ, lang_HE,
lang_HU, lang_ID, lang_IS, lang_IT, lang_JA, lang_KN, lang_KO,
lang_KZ, lang_LT, lang_LV, lang_NL, lang_NO, lang_PL, lang_PT,
lang_PT_BR, lang_RO, lang_RU, lang_SK, lang_SL, lang_SR,
lang_SV, lang_TE, lang_TG, lang_TH, lang_TR, lang_UK, lang_VI)
from . import (lang_AM, lang_AR, lang_AZ, lang_BY, lang_CE, lang_CY, lang_CZ,
lang_DE, lang_DK, lang_EN, lang_EN_IN, lang_EN_NG, lang_EO,
lang_ES, lang_ES_CO, lang_ES_CR, lang_ES_GT, lang_ES_NI,
lang_ES_VE, lang_FA, lang_FI, lang_FR, lang_FR_BE, lang_FR_CH,
lang_FR_DZ, lang_HE, lang_HU, lang_ID, lang_IS, lang_IT,
lang_JA, lang_KN, lang_KO, lang_KZ, lang_LT, lang_LV, lang_NL,
lang_NO, lang_PL, lang_PT, lang_PT_BR, lang_RO, lang_RU,
lang_SK, lang_SL, lang_SR, lang_SV, lang_TE, lang_TG, lang_TH,
lang_TR, lang_UK, lang_VI)

CONVERTER_CLASSES = {
'am': lang_AM.Num2Word_AM(),
'ar': lang_AR.Num2Word_AR(),
'az': lang_AZ.Num2Word_AZ(),
'by': lang_BY.Num2Word_BY(),
'ce': lang_CE.Num2Word_CE(),
'cy': lang_CY.Num2Word_CY(),
'cz': lang_CZ.Num2Word_CZ(),
'en': lang_EN.Num2Word_EN(),
'en_IN': lang_EN_IN.Num2Word_EN_IN(),
Expand Down
Loading
Loading