[development] code proposal: localization of currency, ...
Hans Salvisberg
drupal at salvisberg.com
Wed Oct 17 15:47:09 UTC 2007
Forget about currency. Currency is completely unrelated to the user's
language, and it certainly shouldn't change, just because a user changes
their language.
A monetary amount is a number, possibly formatted in some special way,
and a currency symbol/code placed somewhere. If a website wants to sell
stuff in US$ they rarely want to get paid in any other currency -- well,
they rarely support any language but English either... OTOH, if they
sell stuff in Swiss Francs, they'll probably support at least German,
French, and Italian (but Germany, France, and Italy have the Euro --
French Canada has the Canadian Dollar!). That Swiss site may support
English as well, and they may also accept Euros, but the Euro amount
won't be the same as the Swiss Franc amount, of course. And the UK does
NOT use the Euro, but the Pound Sterling. Are there any English-speaking
countries that do not use the Pound Sterling?
This is much more complex than you think, and automating it would
require a completely different approach. Essentially, a currency field
would have to take the amount and the currency code (see
http://en.wikipedia.org/wiki/ISO_4217), probably from a configurable
list (which might have only one item), and format the number
accordingly, with or without a currency symbol or code, at the user's
option.
Hans
Ivan Sergio Borgonovo wrote:
> - write functions like:
>
> i18n_currency_format($number, $symbol='') {
> $tmp=i18n_number_format(abs($number),
> variable_get('currency_decimal',2)
> );
> if($number<0) { $sign="-"; }
> $tmp=str_replace('d',$tmp,
> variable_get('currency_format','sd c'):
> $tmp=str_replace('c',$simbol,$tmp);
> $tmp=str_replace('s',$sign,$tmp);
> return $tmp;
> );
> }
>
More information about the development
mailing list