Description
Problem
Currently, it is not possible to support parsing both Area.Parse("1 km²")
and Area.Parse("1 km^2")
due to a limitation in the JSON structure for prefix units (kilo, mega etc.) and how we parse it in powershell script.
Background
We support defining multiple abbreviations for a unit in JSON on the Abbreviations
property, but many units add prefixes such as kilo, mega etc to generate those extra units by simply adding k
and M
prefix to the unit abbreviation. However, this design currently has two limitations:
-
Only the first abbreviation in
Abbreviations
is used when creating abbreviations for prefix units. Ex: Area may have"Abbreviations": [ "m²", "m^2" ]
and"Prefixes": [ "Kilo" ]
, but it only generateskm²
for the square kilometer unit. -
If
AbbreviationsWithPrefixes
is defined, then this should be used instead of addingk
andM
prefixes. This is a list of abbreviations fully typed out and each position in the array matches the arrayPrefixes
. This is useful for languages such as Russian where a different character should be used or where it's not as simple as prefixing a string. However, currently this is an array of strings and thus only supports 1 abbreviation per prefix. I propose to extend this to support an array of a mix of strings and arrays of strings.
Proposal
Support defining multiple strings per prefix unit in JSON, but keep it backwards compatible so we can either define an array of strings (as we already do) or an array of arrays of strings.
The following (silly) example would create the following abbreviations: m², m^2, km², km^2, Mm²
I think in most cases it would be either an array of string OR an array of arrays of strings - and not a mix as in this example, but implementing it this way makes it flexible and should be a matter of checking each item in AbbreviationsWithPrefixes
whether it is a string or an array.
"Localization": [
{
"Culture": "en-US",
"Abbreviations": [ "m²", "m^2" ],
"Prefixes": [ "Kilo", "Mega" ],
"AbbreviationsWithPrefixes": [ ["km²", "km^2"], "Mm²" ] // contrived example
}
]