mathesar
mathesar copied to clipboard
Convert the currency_info dataset to align with Money type Display options
Problem
#1205 Introduces display options for the Mathesar_Money
type. Money type has display options like currency symbol
, number_format
etc. We are able to infer the currency symbol from the imported data. Often currencies tend to follow the number formats of their country or have a predefined format which is followed when representing them, so we should set the default values for other display options based on the standard representation format of the inferred currency.
Proposed solution
We have a dataset (currency_info.json
) extracted from locale files, it contains currency symbols and the standards for that currency symbol, this information can be converted into values that align with our display options which could then be used to set predefined display option values.
Additional context
- Blocked by #1205
- Money Display options API spec and related discussion #1243
- Helpful links to get human readable locale name
- https://gist.github.com/jacobbubu/1836273
- https://gist.github.com/SergLam/a4ed0463cce5c5b32339bb351f8b7815
- Rough Code to get currency codes mapped to currency symbol with the same data
import json
with open("currency_info.json", "r") as f:
currency_info = json.loads(f.read())
duplicates_map = {}
for currency_code, currency_details in currency_info.items():
if currency_details['currency_symbol'] in duplicates_map:
not_exist = True
for code, details in duplicates_map[currency_details['currency_symbol']].items():
if details['data'] == currency_details:
not_exist = False
duplicates_map[currency_details['currency_symbol']][code]['codes'].append(currency_code)
if not_exist:
duplicates_map[currency_details['currency_symbol']][currency_code] = {
'codes': [currency_code], 'data': currency_details
}
else:
duplicates_map[currency_details['currency_symbol']] = {
currency_code: {'codes': [currency_code], 'data': currency_details}
}
print(duplicates_map)
@silentninja can I work on this?
Sure @ratika-12. I have assigned the issue to you. Since the issue depends on #1205, please use mathesar-1105-money-display-option
as your base branch. Thanks for the help!
@ratika-12 are you still working on this?
@silentninja is this even still relevant?
@kgodey If this issue is still relevant, you may assign this to me.
Go ahead @shivams
The issue is still relevant, @silentninja made some updates to the description and the latest issue description should be accurate.
I've looked into this issue. The following rough code extracts the information from currency_info.json
and returns the display options as defined in https://github.com/centerofci/mathesar/issues/1105:
import json
currency = getCurrency() #some arbitrary function that infers the currency's ISO code, e.g. 'en_US.ISO8859-1'
with open("currency_info.json", "r") as info_file:
currency_info = json.load(info_file)
display = dict()
display['symbol'] = currency_info[currency]['currency_symbol']
display['symbol_location'] = 1 if currency_info[currency]['p_cs_precedes'] else -1
display['decimal_symbol'] = currency_info[currency]['mon_decimal_point']
display['digit_symbol'] = currency_info[currency]['mon_thousands_sep']
display['digit_grouping'] = currency_info[currency]['mon_grouping']
return display
I see that the issue is easy. However, I still have a few doubts:
- Where should I integrate the logic? Should it go into
mathesar/api/display_options.py
? Or, should I create a new json which contains the information extracted fromcurrency_info.json
in our desired display option format? - What do we expect as the input? Do we expect the currency symbol (e.g.
$
) or do we expect the currency ISO code as the input (e.g.en_US.ISO8859-1
)? I see that we're inferring the currency symbol. However, a single currency symbol has multiple ISO codes associated with it. Which ISO code should I choose then? - The
digit_grouping
part needs some more clarifications. I see that we're abiding by the .NET standard for this. In thecurrency_info.json
file, however, which standard is being followed for interpreting thisgrouping
array? It seems to me, it is this standard, however its interpretation isn't compatible with the arrays given in the json file. I am a little confused regarding this.
@shivams https://github.com/centerofci/mathesar/discussions/1243#discussioncomment-2519195 has the display options spec for MathesarMoney
type. We need to be able to pre-fill those display options(currency_symbol_location and number_format) with the correct value.
We infer the currency data in this line https://github.com/centerofci/mathesar/blob/b2467dcf63de786c0e8063821ff317ef608ec3a6/mathesar/utils/display_options_inference.py#L35
As you can see, we are able to infer the currency symbol but symbol_location
and number_format
values are hardcoded, rather they should be replaced with the correct values based on the currency symbol.
Current currency_info.json does not contain any of the possible values rather it has information useful to derive the values we need, so we need to rework the currency_info.json
file. For example
"en_US.ISO8859-1": {
"int_curr_symbol": "USD ",
"currency_symbol": "$",
"mon_decimal_point": ".",
"mon_thousands_sep": ",",
"mon_grouping": [
3,
3,
0
],
"positive_sign": "",
"negative_sign": "-",
"int_frac_digits": 2,
"frac_digits": 2,
"p_cs_precedes": 1,
"p_sep_by_space": 0,
"n_cs_precedes": 1,
"n_sep_by_space": 0,
"p_sign_posn": 1,
"n_sign_posn": 1,
"decimal_point": ".",
"thousands_sep": ",",
"grouping": [
3,
3,
0
]
},
should be replaced with
{"currency_symbol": "$",
"number_format": 'english',
"currency_symbol_location": 'after-minus'
}
Other information can be discarded.
I would like to take up this issue if possible.
Go ahead @abhishak3. :)
@abhishak3 are you still working on this?
I am unable to wrap my head around this issue. You can unassign me for the time being.
Thanks @abhishak3. Let me know if you'd like an issue that's better specced out to work on.
This issue has not been updated in 90 days and is being marked as stale.
Closing this, too old, requirements are likely out of date. We can create a new issue if we need this functionality in the future.