Human-Readable
Human-Readable copied to clipboard
[Feedback wanted] Distances: auto-conversion
With the nice new addition of distances (#137), it's now possible to format a metric or imperial distance:
// Metric examples
HumanReadable.distance(value = 956, unit = DistanceUnit.Meter) // "956 m"
HumanReadable.distance(value = 1534, unit = DistanceUnit.Meter) // "1.5 km"
// Imperial examples
HumanReadable.distance(value = 5200, unit = DistanceUnit.Foot) // "5,200 ft"
HumanReadable.distance(value = 5350, unit = DistanceUnit.Foot) // "1.0 mi"
However, as this library localises other things, like number formatting, I think it would make sense to add a conversion option.
For example:
// Proposal examples
HumanReadable.distance(value = 5200, unit = DistanceUnit.Foot, conversion = DistanceConversion.None) // "5,200 ft"
HumanReadable.distance(value = 5200, unit = DistanceUnit.Foot, conversion = DistanceConversion.Imperial) // "5,200 ft"
HumanReadable.distance(value = 5200, unit = DistanceUnit.Foot, conversion = DistanceConversion.Metric) // "1.6 km"
Having a DistanceConversion.Automatic option that chooses metric/imperial based on user's locale would be even more useful:
// Proposal examples
HumanReadable.distance(value = 5200, unit = DistanceUnit.Foot, conversion = DistanceConversion.None) // "5,200 ft"
// SET LOCALE US
HumanReadable.distance(value = 5200, unit = DistanceUnit.Foot, conversion = DistanceConversion.Automatic) // "5,200 ft"
// SET LOCALE NL
HumanReadable.distance(value = 5200, unit = DistanceUnit.Foot, conversion = DistanceConversion.Automatic) // "1.6 km"
But the current localisation library (Libres) only supports setting a language, not region. Compose Multiplatform resources does support it (qualifiers overview) but that migration is still blocked by #139. The region will be a requirement to have a sensible automatic default here.
If you have feedback on this, please share 🙂