Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Delta's like temperature are standard issue to resolve in globalization. Another fun one are complex units that are a combination of more base units like luminance (nits = candela / m*2 or mph.

I worked on a package to globalize a consumer-oriented fintech reporting product. With ESG reporting this has become increasingly important to get the unit conversions and Delta's right. You end up mapping the data source units to locale targets.

In Python, the Pint framework plus Babel locales are excellent.



How do frameworks deal with the miles/gallon -> liters/100km conversion? I've always found that one particularly interesting as one that requires inverting the units also.


Which gallon? There are two different ones (and for even more fun Canada and us don’t use the same)



It’s even worse, the US has different gallons from the rest of the world.


To be fair, imperial gallons are based on 10 lbs of water (with very specific atmospheric conditions), which while a nice round number, isn’t as easy to recreate as the U.S. gallon, which is 231 cubic inches.

Of course, liters make way more sense than either of these.


Out of curiosity, how dit it end up being that weird 231 number? Why not 230? Or a nice 200?


Wikipedia says it was defined as cylinder of d=6” and h=7”, and they later redefined it to use the approximation of pi as 22/7. 22/7 * 7” * (7”/2)^2 = 231 in^3. Not approximately equal, precisely equal. It’s an interesting math oddity that I hope someone else will explain.

Also, I’ve no idea if that history is true, but it sounds plausible.


In Pint you can define custom units in a unit registry. So you make your complex unit out of predefined units and the underlying unit conversion is built-in. Pint also works with pandas/numpy so you you get vectorized operations too for performance.


Well, I get how mathematically you do it, I'm talking about how to make it contextually aware like the OP. A sentence like "The latest generation doubled MPG from 15 MPG to 30 MPG" should be localized to "The latest generation halved L/100km from 16 L/100km to 7.8 L/100km".


The unit registry maps units to locales (eg EN_US, DE_DE, NL_BE) you pass the configured locale to your getter call for the unit. If you need unit strings, you can pass the locale to the string formatter.


I feel like we're talking cross purposes. A sentence like "MPG increased by 20%" should be translated to "L/100km decreased by 16.6%", a sentence like "MPG increase by 5" is untranslatable without more context.

I understand if you are getting a human to translate each sentence you can just point them to the right phrases but my understanding is that you're translating text in bulk via machine translation. For scales in which the conversion is linear and the starting point is zero, this task is relatively trivial. For scales like temp where the zero points are different, you need to treat deltas different from absolute values. For scales where one is the inverse of the other, there's a lot of very tricky edge cases that make machine translation hard.




Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: