Skip to content

Commit

Permalink
Added support for Tunisian Dinar (#593)
Browse files Browse the repository at this point in the history
* Added support for Tunisian Dinar

* Added tests for TND currency

* Set parPrecision for other AR currencies

---------

Co-authored-by: Marlon Rodriguez Garcia <47992153+mrodriguezg1991@users.noreply.github.com>
  • Loading branch information
rochdi80tn and mrodriguezg1991 authored Dec 16, 2024
1 parent 0df2a0e commit 282f72d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
11 changes: 10 additions & 1 deletion num2words/lang_AR.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
("قرش", "قرشان", "قروش", "قرش")]
CURRENCY_KWD = [("دينار", "ديناران", "دينارات", "ديناراً"),
("فلس", "فلسان", "فلس", "فلس")]
CURRENCY_TND = [("دينار", "ديناران", "دينارات", "ديناراً"),
("مليماً", "ميلمان", "مليمات", "مليم")]

ARABIC_ONES = [
"", "واحد", "اثنان", "ثلاثة", "أربعة", "خمسة", "ستة", "سبعة", "ثمانية",
Expand Down Expand Up @@ -352,15 +354,22 @@ def validate_number(self, number):
return number

def set_currency_prefer(self, currency):
if currency == 'EGP':
if currency == 'TND':
self.currency_unit = CURRENCY_TND[0]
self.currency_subunit = CURRENCY_TND[1]
self.partPrecision = 3
elif currency == 'EGP':
self.currency_unit = CURRENCY_EGP[0]
self.currency_subunit = CURRENCY_EGP[1]
self.partPrecision = 2
elif currency == 'KWD':
self.currency_unit = CURRENCY_KWD[0]
self.currency_subunit = CURRENCY_KWD[1]
self.partPrecision = 2
else:
self.currency_unit = CURRENCY_SR[0]
self.currency_subunit = CURRENCY_SR[1]
self.partPrecision = 2

def to_currency(self, value, currency='SR', prefix='', suffix=''):
self.set_currency_prefer(currency)
Expand Down
6 changes: 6 additions & 0 deletions tests/test_ar.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ def test_currency_parm(self):
self.assertEqual(
num2words(1000000.99, to='currency', lang='ar', currency="KWD"),
'مليون دينار و تسع و تسعون فلس')
self.assertEqual(
num2words(1000.42, to='currency', lang='ar', currency="TND"),
'ألف دينار و أربعمائة و عشرون مليم')
self.assertEqual(
num2words(123.21, to='currency', lang='ar', currency="TND"),
'مائة و ثلاثة و عشرون ديناراً و مئتان و عشر مليمات')

def test_ordinal(self):

Expand Down

0 comments on commit 282f72d

Please sign in to comment.