Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I know the measurement units corresponding to a given locale?

I'd like to display length in a locale-dependent way, i.e.: show the length in the correct measurement unit for the current locale. I know LC_MEASUREMENT is what I need to use, however how do I use it?

GNU gettext does not give me anything to work with LC_MEASUREMENT. I looked at the source of some weather applets and they all require you to manually enter your unit (Kelvin, Fahrenheit or Celsius) in the preferences window.

It seems to me that that environment variable is never used by anyone, however I'd really like to use it to give a better user experience. Perhaps, is there a free (as in freedom) database that maps locale names to the corresponding measurement units?

FYI: my application is written in C.

like image 388
user16538 Avatar asked Nov 04 '22 07:11

user16538


1 Answers

As far as I know, the C standards and GNU gettext do not offer any way to know the measurement units used in a country, there are no third party libraries that do the job and there are no ready to used databases (free or proprietary).

However, according to CIA - The World Factbook:

At this time, only three countries - Burma, Liberia, and the US - have not adopted the International System of Units (SI, or metric system) as their official system of weights and measures.

So it is fairly easy to write your own code, even without a database or third party libraries. You just have to special case three LC_MEASUREMENT values (or, better, three patterns, as some of these countries have more than a language):

  • Burma (language code pattern: *_MM) uses the Burmese system;
  • Liberia (language code pattern: *_LR) uses the Imperial system;
  • United States (language code pattern: *_US) use a customary system similar to the Imperial one.
  • all other countries use the International System of Units.

UPDATE: all of these countries are in the (slow) process of converting to the metric system (SI). This is probably an another reason why nobody has bothered writing some libraries, code snippets or databases.

like image 102
Andrea Corbellini Avatar answered Nov 15 '22 06:11

Andrea Corbellini