From 282f72dd2ff226bc14ca6c4234b661eaac7ed8aa Mon Sep 17 00:00:00 2001 From: Rochdi Bazine Date: Mon, 16 Dec 2024 17:19:57 +0100 Subject: [PATCH] Added support for Tunisian Dinar (#593) * 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> --- num2words/lang_AR.py | 11 ++++++++++- tests/test_ar.py | 6 ++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/num2words/lang_AR.py b/num2words/lang_AR.py index 7195dd47..7813d3aa 100644 --- a/num2words/lang_AR.py +++ b/num2words/lang_AR.py @@ -31,6 +31,8 @@ ("قرش", "قرشان", "قروش", "قرش")] CURRENCY_KWD = [("دينار", "ديناران", "دينارات", "ديناراً"), ("فلس", "فلسان", "فلس", "فلس")] +CURRENCY_TND = [("دينار", "ديناران", "دينارات", "ديناراً"), + ("مليماً", "ميلمان", "مليمات", "مليم")] ARABIC_ONES = [ "", "واحد", "اثنان", "ثلاثة", "أربعة", "خمسة", "ستة", "سبعة", "ثمانية", @@ -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) diff --git a/tests/test_ar.py b/tests/test_ar.py index 91e648a6..5781db52 100644 --- a/tests/test_ar.py +++ b/tests/test_ar.py @@ -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):