Skip to content
This repository has been archived by the owner on Mar 17, 2022. It is now read-only.

Price Localization

Jonathan Moore edited this page Jun 17, 2017 · 8 revisions

Price localisation should based on currency and locale: users in different places expect to see different currency strings.

For example, let's take an amount in Euros: $amount = '12345.678'; $currency = 'EUR';

How users expect to see this depends on their locale: their location and language convention:

     Country  Locale  Format
     UK:      en_GB: €12,345.68
     Germany: de_DE: 12.345,68 €
     France:  fr_FR: 12 345,68 €

In PHP this is implemented by built-in libraries, as eg:

     formatter = new NumberFormatter($locale,  NumberFormatter::CURRENCY);
     echo $locale. ': ' . $formatter->formatCurrency($amount, $currency);

The approach taken by the plugin option Features, 'Use locale number formats' (since v1.0.2) is to use the configured language locale in Polylang to do the formatting.

Note that the decimal separator and thousands separator formatting is applied to other numeric values where possible as part of the localisation solution.

The price formatting has some limitations, for example you may only configure one language for "English" however, different English-speaking countries use different symbols for the same country.

For example, in Australia, the Australian dollar symbol is "$", so the US Dollar is referred to explicitly as USD. Conversely if an American is being shown "$", it is expected to be US Dollar, so an Australian dollar price should be explicitly marked as eg "A$". The same goes for Singapore Dollar, Hong Kong Dollar which all should be presented as $ in their local markets.

Hence this feature can be turned off, for example you may have a localisation solution based on user country information obtained from geolocation or other means. Please feel free to use the code structure in LocaleNumbers to create your own solution.

Clone this wiki locally