Problem

The currency code's first letter always appears in front of the currency symbol in an entity's display.
How do you stop this so it only displays the currency symbol?

screenshot

screenshot

Comments

the_glitch created an issue. See original summary.

bojanz’s picture

A$ is the currency symbol for AUD (Australian Dollar) in the "en" locale, according to CLDR. It's not a random letter being added.

To show AUD as "$" you need to ensure your locale is set to "en-AU". That will also show USD as "US$".

Locales are set via LocaleResolvers and the default one uses "$currentLanguage-$currentCountry", where $currentCountry defaults to the country from your store address. So make sure your store has an australian address set.

the_glitch’s picture

Are you saying if my Locale is set to Australia, the A shouldn't be appearing if AUD is the selected currency for that field?
If so, the site's Locale and the Admin User's Locale are already set to Australia and Sydney but the A is appearing anyway.

Only local images are allowed.

the_glitch’s picture

👆?

jsacksick’s picture

Status: Active » Fixed

\Drupal\commerce_price\CurrencyFormatter passes the locale to the Commerce Guys INTL currency formatter from the constructor:

  /**
   * Constructs a new CurrencyFormatter object.
   *
   * @param \CommerceGuys\Intl\NumberFormat\NumberFormatRepositoryInterface $number_format_repository
   *   The number format repository.
   * @param \Drupal\commerce_price\Repository\CurrencyRepositoryInterface $currency_repository
   *   The currency repository.
   * @param \Drupal\commerce\CurrentLocaleInterface $current_locale
   *   The current locale.
   */
  public function __construct(NumberFormatRepositoryInterface $number_format_repository, CurrencyRepositoryInterface $currency_repository, CurrentLocaleInterface $current_locale) {
    $default_options = [
      'locale' => $current_locale->getLocale()->getLocaleCode(),
      // Show prices as-is. All digits (storage max is 6), non-rounded.
      'maximum_fraction_digits' => 6,
      'rounding_mode' => 'none',
    ];

    parent::__construct($number_format_repository, $currency_repository, $default_options);
  }

You should double check what is your current locale.
Also, you could potentially swap the CurrencyFormatter with your own and hardcode the passed locale to the desired one.

Now that this issue is closed, please review the contribution record.

As a contributor, attribute any organization helped you, or if you volunteered your own time.

Maintainers, please credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.