How to convert string in Arabic for Print Format

Is there any utility function to convert amount in words (in Arabic)?

In print format I want to convert currency field into amount in words (in English) for that I am using frappe.utils.money_in_words(doc.amount, 'SAR')

Now my requirement is to print this (amount in words) in Arabic also.

Thanks.

@umarless Please check this frappe utility function use in print format or py file you can access

from frappe.utils import money_in_words

money_in_words(900) # 'INR Nine Hundred and Fifty Paisa only.'
money_in_words(900.50) # 'INR Nine Hundred and Fifty Paisa only.'
money_in_words(900.50, 'USD') # 'USD Nine Hundred and Fifty Centavo only.'
money_in_words(900.50, 'USD', 'Cents') # 'USD Nine Hundred and Fifty Cents only.'

I want fields like below in print format.
Amount : 1001.10
Amount in Words (English) : SAR One Thousand And One and Ten Halala only.
Amount in Words (Arabic) : ألف وواحد وعشرة هللة فقط

please check Currency doctype and add any currency id and check it

amount_in_words = frappe.utils.money_in_words(1001.10, ‘add_currency_name’)

or other wise check this documentation

https://frappeframework.com/docs/user/en/api/jinja

Thanks for your reply.
@Meet I think you are not understanding my requirement or issue.

btw, I solved this issue using num2words

I created one custom field amount_in_words in my doctype.

class DoctypeTest(Document):
    def before_save(self):
        if self.amount:
            self.amount_in_words = convert_in_arabic(self.amount)

def convert_in_arabic(number):
    try:
        return num2words(number, lang='ar') + " فقط"
    except NotImplementedError:
        return num2words(number, lang='en')

and then in custom print format getting amount in words (in Arabic) using {{ doc.amount_in_words }}

1 Like