python-currencies icon indicating copy to clipboard operation
python-currencies copied to clipboard

Adding the currency Name

Open mame98 opened this issue 5 years ago • 4 comments

It would be really great if the library would know the full name of the currency. For example:

>>> Currency('USD').get_name()
"United States dollar"

or

>>> Currency('EUR').get_name()
"Euro"

I think english names would be a good starting point, but I think there should be a way to translate the names? I thought of JSON files for each language that contains the name for each currency. The library could then choose the correct file automatically.

mame98 avatar Dec 27 '20 11:12 mame98

Yeah, that seems be good idea.

I guess for translation, it could be 2 options, either using .po files using gettext lib which is a more proper standard, in any case JSON would work as well.

Feel free to make a pull request ;)

Alir3z4 avatar Dec 27 '20 22:12 Alir3z4

I will try to make a pull request in the next few days, I will look at gettext, as it seems to be the "correct" way

mame98 avatar Dec 28 '20 19:12 mame98

While working with gettext mentioned on https://docs.python.org/3/library/i18n.html seems to be a good idea, it's gives pretty low level (basic?) integration.

I've heard good things about http://babel.pocoo.org/en/latest/index.html but have not used it myself and not sure for such small lib as python-currencies, it would be a good option or an overkill.

Many projects I've seen, the build simple wrappers around gettext functionality provided by Python directly, which would be text extraction etc.

Since python-currencies is pretty small, I don't think there would be a need for full fledges text extraction features and other fancy stuff comes out of the Babel.

Worth noting, xgettext does text extraction out of the box with no problem.

I think by making some small functions around gettext it should get the the job done without having to install other dependencies.

I myself don't have the experience with Python i18n out of Django, Flask and some others since they have all the tools and utilities included.

I did some quick searches and skimmed through several articles and so far I found https://simpleit.rocks/python/how-to-translate-a-python-project-with-gettext-the-easy-way/ to be the good start with clear explanations.

Alir3z4 avatar Dec 28 '20 19:12 Alir3z4

Hiya guys, Newbie here - I'm looking to help out open source projects for Python practice and this Issue/feature request looks like a good starting point.

I agreed with all the above, but for starters I think a nice and simple translation to English (done via a JSON file) will suffice - at least to get basic functionality. This can then later be extended for other languages/alternative names

I'm part way through creating the JSON file (too short of a job to automate, but still tedious). I'll create a fork and wire up the .get_name() method in the main class after as well.

Example of the JSON file so far:

{ "AED" : "United Arab Emirates dirham", "AFN" : "Afghan afghani", "ALL" : "Albanian Lek", "AMD" : "Armenian Dram", "ANG" : "Netherlands Antillean guilder", "AOA" : "Angolan kwanza", "ARS" : "Argentine peso", "AUD" : "Australian Dollar", "AWG" : "Aruban florin", "AZN" : "Azerbaijani manat", "BAM" : "Bosnia and Herzegovina convertible mark", "BBD" : "Barbados Dollar", "BDT" : "Bangladeshi taka", "BGN" : "Bulgarian lev", "BHD" : "Bahraini dinar", "BND" : "Brunei dollar", "BOB" : "Bolivian Boliviano", "BRL" : "Brazilian real", "BSD" : "Bahamian dollar", "BTN" : "Bhutanese ngultrum", "BWP" : "Botswana pula", "BYR" : "Belarusian ruble", "BZD" : "Belize dollar", "CAD" : "Canadian dollar", "CHF" : "Swiss franc", "" }

Any tips/advice are welcome :)

con-dev123 avatar Aug 12 '21 15:08 con-dev123