Page 1 of 1

Internationalisation LC_NUMERIC

Posted: Tue Jun 13, 2006 10:13 am
by CoderGoblin
Not sure if this should be in the Advanced Theory Section or not...

For the project I am doing at present we are looking at internationlization. We have a functions for translation of general text accessing a database and caching information where necessary. We then started looking at dates (from the Postgres DB) and setlocale using LC_TIME simplifies things a lot.

Then I started looking at the other options such as LC_NUMERIC. When entering infomation in Germany a comma is used as the decimal separator and full stop is used as the thousands separator. In Engand and the US the opposite is true. When saving information to the database we need to use the full stop as the decimal.

Is there any benefit to using LC_NUMERIC as, what I would classify, necessary functions don't seem to use the information and we would have to convert the number anyway to store them into the DB.

Previously we have worked around this numbering with conversion routines, especially on input validation. This still seems the way to do things or am I missing something important/useful ?

The method I am thinking of now is to set the LC_NUMERIC first and use localeconv to determine the decimal character and cache it for use in number_format, input validation etc. This would only be performed on the first page load or when the user changes their locale. Using a validation function like this also has the advantage we can potentially filter out common errors. E.g. We sometimes get people (especially old book keeping people) using 'o' instead of 0 for numbers (legacy from typewriter days as 0 was considered 'weak').

Posted: Tue Jun 13, 2006 10:17 am
by feyd
sounds like you'll have to do conversions and "error correction" at any rate, so it doesn't really matter, now does it? :P

Posted: Tue Jun 13, 2006 10:20 am
by CoderGoblin
That's what I thought... So why would someone use setlocale(LC_NUMERIC,$locale) or is just because everything else does ?

The extra validation is simply an additional "feature", not a requirement.

Posted: Tue Jun 13, 2006 10:22 am
by feyd
Well, if they don't need to handle input, or people are expected to know how to actually enter input data, they could be used without any problem.