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

I am trying to create a set of classes to handle localization (mainly the currency part, but also the language).

I can imagine how logic can be, but I don’t know which names to use for different languages ​​and currencies. I saw that for this there are many ISO standards that I have to choose?

In any case, the logic I was thinking about can help you with this:

I will have the Money class, indicating the quantity and currency. When creating an object, it receives the amount and currency (perhaps the object provided by the localization class?). You can add or multiply the amount. The add method takes a different monetary object as a parameter, and if it has a different currency, the conversion is automatic. Somewhere, the array is stored with all standard names, such as en_US and USD, matching them accordingly, and also tying them to the equivalent in US dollars as a scalar value. Money objects should be able to print amounts in different formats, for example, $ 1000 or U $ s, etc.

  • Is this a good way to handle this?
  • What basis should I stick to?
  • Do you know any existing, unbound php libraries for this?
+3
source share
3 answers

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

+4
source

Take a look at the Zend Framework component Zend_Locale . It does all the work for you, without requiring you to write your own class.

+1
source

.Net, , . , .

iGoogle, , ..

0

Source: https://habr.com/ru/post/1776534/


All Articles