如何处理本地化?我应该遵循一个标准吗? [英] 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).
我可以想象逻辑如何,但是我不知道用于不同语言和货币的名称.我已经看到有很多ISO标准,应该选择哪一个?
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:
我将有一个Money类,其中包含金额和货币属性.在创建时,对象接收金额和货币(由本地化类提供的对象可能是?).您可以将金额相加或相乘. add方法将另一个货币对象作为参数,并且如果其货币不同,则会自动进行转换. 存储所有标准名称(例如en_US和USD)的数组的某个位置,将它们适当地关联起来,并且还将它们与美元等价的标量值关联起来. Money对象应该能够以不同的格式打印金额,例如$ 1000或U $ s等.
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.
- 这是解决这个问题的好方法吗?
- 我应该遵循哪个标准?
- 您知道已经存在的,已解耦的php库可以执行此操作吗?
推荐答案
使用新的 intl
模块.尽管整个 ICU
库不是一个标准,但它的组件却是标准.并且与C,C ++和Java兼容.
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.
这篇关于如何处理本地化?我应该遵循一个标准吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!