CampTix: format EUR amounts via locale-aware NumberFormatter - #1767
Open
alexandrebuffet wants to merge 1 commit into
Open
CampTix: format EUR amounts via locale-aware NumberFormatter#1767alexandrebuffet wants to merge 1 commit into
alexandrebuffet wants to merge 1 commit into
Conversation
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
|
+1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
EURwas defined with a hard-coded'€ %s'format string and (unlikeGBP/en_GBorAUD/en_AU) had nolocale, so it never went throughNumberFormatter.What this changes
inc/class-camptix-currencies.php—EURnow gets a'locale' => get_locale()so it renders through the existingNumberFormatterbranch, 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 theintlextension.camptix.php— theNumberFormatterbranch now usesformatCurrency( $amount, $currency_key )instead offormat( $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:
fr_FR,de_DE,es_ES,it_IT40,00 €nl_NL€ 40,00en_IE€40.00en_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()andformatCurrency()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.00instead of the expected40,00 €.How to test the changes in this Pull Request:
fr_FR), set Tickets → Setup → Currency toEuro (EUR).40) and view any place that renders it (ticket/registration form).40,00 €(symbol after, comma decimal) instead of€ 40.00.en_US) and confirm the price shows as€40.00— with the euro sign, not$40.00.GBP,USD,AUD) are unchanged.Automated:
tests/test-camptix-admin.phpaddstest_append_currency_eur_places_symbol_after_amount_for_french_localeandtest_append_currency_eur_uses_euro_symbol_on_english_locale(both skip whenintlis unavailable and avoid asserting exact ICU strings).