Internationalisation LC_NUMERIC

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Internationalisation LC_NUMERIC

Post 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').
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
Post Reply