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

雨燕双飞 提交于 2020-01-03 21:00:03

问题


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.

  • Is this a good way to deal with this?
  • Which standar should I follow?
  • Do you know any already existent, decoupled php libraries to do this?

回答1:


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.




回答2:


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




回答3:


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.



来源:https://stackoverflow.com/questions/4259735/how-to-deal-with-localization-is-there-a-standard-i-should-follow

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!