Domanda

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.

È stato utile?

Soluzione

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):

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top