This issue continues the discussion started in #1367630-6: Classes.

I checked Commerce and Ubercart and the classes added in #1367630: Classes already cover the features either webshop offers, except that Ubercart also stores currencies' numeric ISO codes.

I've been thinking (which I know I shouldn't) and reading (which I know I can't) and came up with this: instead of CurrencyLanguage objects we have CurrencyLocale objects that configure a locale based on language AND country. Currency.module can ship with several predefined configurations and will default to en-US if no matching 'override' can be found, just like with string translation. It would be great if we can let user enter a configuration that allows a to convert a float to any display. Something like ¤-#,##0.00 would allow for flexibility, but this would also be hard to understand for novices, if only because the ¤ character is not common on many keyboards. We can do something token-like, such as [sign] [units].[subunits] [code], but then we'd have to come up with something that allows a grouping separator and a group length to be configured, keeping in mind that some notations have a first group that is one digit longer than the others.

Comments

xano’s picture

Issue summary: View changes

Typofix.

amateescu’s picture

Version: 7.x-1.x-dev » 7.x-2.x-dev

I agree that CurrencyLocale makes much more sense than CurrencyLanguage for our purposes.

Also, have we thought about using PHP's intl extension? http://www.php.net/manual/en/numberformatter.formatcurrency.php

Even if we decide against it because of it's requirements (php 5.3 / php 5.2 as a pecl extension), we can still use it by default if it's enabled and switch to our implementation if not, that should save some cpu cycles :)

Edit: In order to be as performant as possible (e.g. don't include our implementation class on each page load) we could use ctools plugins for this task. Ctools is already a dependency for the currency exportability feature.

alan d.’s picture

Version: 7.x-2.x-dev » 7.x-1.x-dev

The LDML spec of interest is: http://www.unicode.org/reports/tr35/#Currencies

Question from the previous thread: "but how does one display the euro to an Argentine audience?"

Great question. And it is not one I can answer! This is a common currency, so you would get away with using the standard symbol ;) An Asian or Arabic symbol would be completely foreign here though. Should we just insert the native symbol in the native format, the native symbol with the format in the users locale, or convert to a format in the users locale....

My gut feel is to just to create an English format for the string and symbol. Then make this translatable via the i18n module. So each currency has a base, and this is translatable via i18n. I would think that it would be easy to script the money_format() function to get a base list of formats. This function actually drops the symbol for an abbreviation of the currency.

"iso3","name","plural","symbol","format","minor_unit_precision"
"CAD","Canadian dollar","Canadian dollars","$","-¤#,##0.00","2"

A French translation could specify the alternative format, an Arabic translation could specify both a different format / symbol.

Firstly, decide if you want to cover the finer details discussed here. If so, then ping Gábor Hojtsy or Florian Weber (webflo) for advice on the best way forward.

In regards to the format, it is an unusual character, but it is the international symbol for this task. However, I think that I only parsed about 17 distinct formats from the XML dumps from www.unicode.org. So maybe it is an option to collect up all of the distinct formats, extend these with a few extras, like corresponding minus and bracket pairs, [-¤#,##0.00 and (¤#,##0.00)] and actually provide a finite list of formats to choose from via a select list. When displaying the list, these could be parsed into a real number, like date formats, with say -1234567.890 as the base.

$options = array(
  '-¤#,##0' => '-$1,234,567',
  '-¤#,##0.00' => '-$1,234,567.89',
  '-¤#,##0.000' => '-$1,234,567.890',
  '(¤#,##0)' => '($1,234,567)'
  '(¤#,##0.00)' => '($1,234,567.89)'
  '(¤#,##0.000)' => '($1,234,567.890)'
);
amateescu’s picture

Version: 7.x-1.x-dev » 7.x-2.x-dev

Cross-post :)

xano’s picture

1) I'm not sure whether we need subunit/minor unit precision. AFAICS we can do with a "number of
subunits" property and use that to calculate the number of decimals needed to display an amount.

2) Let's see if we can come up with some code to use patterns like ¤#,##0.000 as templates in #1531058: Include bartfeenstra/cldr to parse Unicode CLDR number patterns.

3) Decide which locale contexts to use for amount display. So far we have language, country, and currency. Are there more? Also, how do we implement delegation? (i.e. How do we construct the entire locale, consisting of these contexts?)

xano’s picture

I've been doing some thinking last weekend:
- Money formatting is country- and language-specific (and currency-specific, but when formatting money, we'll have both amount and currency anyway), so we'll need locale config that covers countries and languages.
- Drupal's locale system only covers the current user's language, but not his country. We need a way to find the user's country.
- Currency locale configurations can be configured for multiple countries and/or multiple languages, and they have a weight.
- Based on the user's country and language a suitable currency locale configuration is selected.
- If that fails, we default to Drupal's default locale, which is en_US.

xano’s picture

Just talked to @amateescu and a possible solution to the country problem is to use a default country and a global/static (yes, I just said that) to let custom modules set the user's country for a specific request. Because it's likely a lot of websites will not have a user-specific country available, we might want to delegate based on language and then on country rather than the other way around.

xano’s picture

Status: Active » Closed (won't fix)

- Unicode CLDR number pattern parsing was added in #1531058: Include bartfeenstra/cldr to parse Unicode CLDR number patterns.
- Getting the correct pattern for a locale is being worked on in #1848030: Add locale-based currency formatting.

xano’s picture

Issue summary: View changes

Fixed link.