Skip to content

CampTix: format EUR amounts via locale-aware NumberFormatter - #1767

Open
alexandrebuffet wants to merge 1 commit into
WordPress:productionfrom
alexandrebuffet:fix/camptix-eur-currency-format
Open

CampTix: format EUR amounts via locale-aware NumberFormatter#1767
alexandrebuffet wants to merge 1 commit into
WordPress:productionfrom
alexandrebuffet:fix/camptix-eur-currency-format

Conversation

@alexandrebuffet

Copy link
Copy Markdown
Contributor

When an event uses the Euro (EUR) as its ticket currency, CampTix rendered prices as € 40.00 — the euro sign before the amount with a dot decimal separator — regardless of the site/event locale. In most Eurozone countries the convention is the symbol after the amount with a comma decimal (40,00 €).

Both defects came from the same root cause: EUR was defined with a hard-coded '€ %s' format string and (unlike GBP/en_GB or AUD/en_AU) had no locale, so it never went through NumberFormatter.

What this changes

  • inc/class-camptix-currencies.phpEUR now gets a 'locale' => get_locale() so it renders through the existing NumberFormatter branch, following the site/event locale for both symbol placement and decimal/thousands separators. The '€ %s' string is kept only as a fallback for environments without the intl extension.
  • camptix.php — the NumberFormatter branch now uses formatCurrency( $amount, $currency_key ) instead of format( $amount ). format() falls back to the locale's default currency, which would render a euro price with a $ on an English-language (en_US) site. formatCurrency() forces the correct ISO currency symbol.

Rendering now follows the locale for every euro-using country, including the legitimate exceptions:

Locale Result
fr_FR, de_DE, es_ES, it_IT 40,00 €
nl_NL € 40,00
en_IE €40.00
en_US €40.00 (was $40.00)

Output for all existing locale-based currencies is unchanged — each one's locale-default currency already equals its ISO code, so format() and formatCurrency() produce byte-identical results (verified across all 18 of them against ICU 77).

Fixes #1766

Screenshots

Live example of the current (incorrect) behavior: https://bretagne.wordcamp.org/2026/billetterie/ shows € 40.00 instead of the expected 40,00 €.

How to test the changes in this Pull Request:

  1. On a site whose language is a Eurozone locale (e.g. French — fr_FR), set Tickets → Setup → Currency to Euro (EUR).
  2. Create a ticket with a price (e.g. 40) and view any place that renders it (ticket/registration form).
  3. Confirm the price shows as 40,00 € (symbol after, comma decimal) instead of € 40.00.
  4. Switch the site language to English (en_US) and confirm the price shows as €40.00 — with the euro sign, not $40.00.
  5. Confirm non-euro currencies (e.g. GBP, USD, AUD) are unchanged.

Automated: tests/test-camptix-admin.php adds test_append_currency_eur_places_symbol_after_amount_for_french_locale and test_append_currency_eur_uses_euro_symbol_on_english_locale (both skip when intl is unavailable and avoid asserting exact ICU strings).

The EUR currency was rendered from a hard-coded '€ %s' format string, so
prices showed the euro sign before the amount with a dot decimal separator
(e.g. "€ 40.00") regardless of the site/event locale. Most Eurozone locales
place the symbol after the amount and use a comma decimal ("40,00 €").

Give EUR a 'locale' derived from get_locale() so it flows through the
existing NumberFormatter branch, and switch that branch from format() to
formatCurrency() with the explicit ISO code. formatCurrency() forces the euro
symbol instead of falling back to the locale's default currency, which fixes
euro prices rendering with a '$' on English-language (en_US) sites. The
'€ %s' format string is kept as a fallback for environments without intl.

Output for all existing locale-based currencies is unchanged (each one's
locale default already equals its ISO code). Adds tests covering symbol
placement for fr_FR and the euro-symbol regression on en_US.

Fixes WordPress#1766
@ePascalC

Copy link
Copy Markdown

+1
This seems perfect!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tickets: EUR currency renders the € symbol before the amount (€ 25) instead of after (25 €)

2 participants