HappyDeveloper
HappyDeveloper

Reputation: 12805

How to deal with localization? Is there a standard I should follow?

I'm trying to make a set of classes to deal with localization (mostly the currency part, but also language).

I can imagine how the logic could be, but I don't know what names to use for the different languages and currencies. I have seen there are many ISO standards for this, which one should I pick?

Anyway here's the logic I was thinking of in case you can help with this too:

I would have a Money class, with amount and currency attributes. On creation, the object receives the amount and the currency (an object provided by the localization class maybe?). You can add to or multiply the amount. The add method takes another money object as parameter, and if it has a different currency, a convertion is made automatically. Somewhere an array is stored with all the standard names such as en_US and USD, relating them appropiately, and also relating them to the equivalent in USD as a scalar value. Money objects should be able to print the amounts in different formats, such as $ 1000, or U$s, etc.

Upvotes: 3

Views: 611

Answers (3)

bcosca
bcosca

Reputation: 17555

Use the new intl module. Although the ICU library as a whole is not a standard, its components are. And it's compatible with C, C++ and Java.

Upvotes: 4

Yeroon
Yeroon

Reputation: 3243

Take a look at Zend Framework's component Zend_Locale. It does all the work for you without needing to write your own class(es).

Upvotes: 1

DampeS8N
DampeS8N

Reputation: 3621

Normally I wouldn't suggest mirroring .Net, but check out the way they do localization. It is easily one of the best small-scale implementations of it I've seen.

Not great for highly dynamic applications along the lines of iGoogle, but fantastic for the headings on static forms, currency, and the like.

Upvotes: 0

Related Questions