Skip to content

Commit

Permalink
Merge branch 'master' into gt-currency
Browse files Browse the repository at this point in the history
  • Loading branch information
monroy95 authored Apr 6, 2023
2 parents 02a04c9 + d098627 commit d81f9be
Show file tree
Hide file tree
Showing 4 changed files with 184 additions and 2 deletions.
3 changes: 2 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ In code there's only one function to use::
>>> num2words(42, lang='fr')
quarante-deux

Besides the numerical argument, there are two main optional arguments.
Besides the numerical argument, there are two main optional arguments, ``to:`` and ``lang:``

**to:** The converter to use. Supported values are:

Expand All @@ -84,6 +84,7 @@ Besides the numerical argument, there are two main optional arguments.
* ``dk`` (Danish)
* ``en_GB`` (English - Great Britain)
* ``en_IN`` (English - India)
* ``en_NG`` (English - Nigeria)
* ``es`` (Spanish)
* ``es_CO`` (Spanish - Colombia)
* ``es_VE`` (Spanish - Venezuela)
Expand Down
3 changes: 2 additions & 1 deletion num2words/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from __future__ import unicode_literals

from . import (lang_AM, lang_AR, lang_AZ, lang_CZ, lang_DE, lang_DK, lang_EN,
lang_EN_IN, lang_EO, lang_ES, lang_ES_CO, lang_ES_GT,
lang_EN_IN, lang_EN_NG, lang_EO, lang_ES, lang_ES_CO, 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,
Expand All @@ -33,6 +33,7 @@
'cz': lang_CZ.Num2Word_CZ(),
'en': lang_EN.Num2Word_EN(),
'en_IN': lang_EN_IN.Num2Word_EN_IN(),
'en_NG': lang_EN_NG.Num2Word_EN_NG(),
'fa': lang_FA.Num2Word_FA(),
'fr': lang_FR.Num2Word_FR(),
'fr_CH': lang_FR_CH.Num2Word_FR_CH(),
Expand Down
37 changes: 37 additions & 0 deletions num2words/lang_EN_NG.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.

# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301 USA

from __future__ import unicode_literals

from . import lang_EN


class Num2Word_EN_NG(lang_EN.Num2Word_EN):

CURRENCY_FORMS = {'NGN': (('naira', 'naira'), ('kobo', 'kobo'))}

CURRENCY_ADJECTIVES = {'NGN': 'Nigerian'}

def to_currency(
self, val, currency='NGN',
kobo=True, separator=',',
adjective=False
):
result = super(Num2Word_EN_NG, self).to_currency(
val, currency=currency, cents=kobo, separator=separator,
adjective=adjective)
return result
143 changes: 143 additions & 0 deletions tests/test_en_ng.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.

# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301 USA

from unittest import TestCase

from num2words import num2words


class Num2WordsENNGTest(TestCase):

# only the test for currency is writen as other
# functions in the Class remains the
# same and have been properly tested in the
# test test_en which tests the parent class
# upon which this class inherits

def test_to_currency(self):

language = 'en_NG'
separator = ' and'

self.assertEqual(
num2words(
'38.4',
lang=language,
to='currency',
separator=separator,
kobo=False
),
"thirty-eight naira and 40 kobo"
)
self.assertEqual(
num2words(
'0',
lang=language,
to='currency',
separator=separator,
kobo=False
),
"zero naira and 00 kobo"
)

self.assertEqual(
num2words(
'1.01',
lang=language,
to='currency',
separator=separator,
kobo=True
),
"one naira and one kobo"
)

self.assertEqual(
num2words(
'4778.00',
lang=language,
to='currency',
separator=separator,
kobo=True, adjective=True
),
'four thousand, seven hundred and seventy-eight Nigerian naira'
' and zero kobo')

self.assertEqual(
num2words(
'4778.00',
lang=language,
to='currency',
separator=separator,
kobo=True
),
'four thousand, seven hundred and seventy-eight naira and'
' zero kobo')

self.assertEqual(
num2words(
'1.1',
lang=language,
to='currency',
separator=separator,
kobo=True
),
"one naira and ten kobo"
)

self.assertEqual(
num2words(
'158.3',
lang=language,
to='currency',
separator=separator,
kobo=True
),
"one hundred and fifty-eight naira and thirty kobo"
)

self.assertEqual(
num2words(
'2000.00',
lang=language,
to='currency',
separator=separator,
kobo=True
),
"two thousand naira and zero kobo"
)

self.assertEqual(
num2words(
'4.01',
lang=language,
to='currency',
separator=separator,
kobo=True
),
"four naira and one kobo"
)

self.assertEqual(
num2words(
'2000.00',
lang=language,
to='currency',
separator=separator,
kobo=True
),
"two thousand naira and zero kobo"
)

0 comments on commit d81f9be

Please sign in to comment.