Skip to content

fix(locale): respect currency in numberFormatOptions#940

Merged
shaharkazaz merged 1 commit into
jsverse:masterfrom
munzzyy:fix/currency-pipe-numberformatoptions
Jul 18, 2026
Merged

fix(locale): respect currency in numberFormatOptions#940
shaharkazaz merged 1 commit into
jsverse:masterfrom
munzzyy:fix/currency-pipe-numberformatoptions

Conversation

@munzzyy

@munzzyy munzzyy commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

Fixes #934

TranslocoCurrencyPipe ignores the currency field on numberFormatOptions. Calling it like this while the active locale is en:

translocoCurrencyPipe.transform(10, 'symbol', { currency: 'EUR' });

returns $10.00 instead of €10.00, because the pipe always builds its options with:

currency: currencyCode || this.localeService._resolveCurrencyCode(),

That line runs after ...numberFormatOptions is spread into the same object, so it overwrites whatever currency the caller passed in, even though currency is a documented, typed field on NumberFormatOptions. The only way to actually set a currency was the separate currencyCode positional argument, which doesn't match what the type suggests should work.

The fix falls back to numberFormatOptions.currency before resolving the locale default, while still letting the currencyCode argument win if both are given, so nothing that currently relies on currencyCode changes behavior:

currency:
  currencyCode ||
  numberFormatOptions.currency ||
  this.localeService._resolveCurrencyCode(),

Added two spec cases to transloco-currency.pipe.spec.ts: one confirming numberFormatOptions.currency is now honored, and one confirming currencyCode still takes precedence when both are passed. Ran nx test transloco-locale locally (51/51 passing, including the new cases) and nx lint transloco-locale (clean). I also reverted the pipe change on its own and reran the suite to confirm the new test actually fails without the fix, so it's a real regression test and not a false positive.

Summary by CodeRabbit

  • Bug Fixes
    • Currency formatting now respects a configured currency value when no explicit currency is passed, while still prioritizing an explicitly provided currency argument.
    • Added test coverage to confirm the expected currency selection behavior in both fallback and override cases.

TranslocoCurrencyPipe always overwrote the currency option with the
currencyCode argument or the locale's resolved default, even when the
caller passed currency directly on numberFormatOptions. That field is
documented and typed on NumberFormatOptions, so passing
{currency: 'EUR'} silently produced USD-formatted output instead.

numberFormatOptions.currency is now used when no explicit currencyCode
argument is given, falling back to the locale default as before. The
currencyCode argument still wins if both are set, so existing usage is
unaffected.
@coderabbitai

coderabbitai Bot commented Jul 5, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 4027e9bf-2235-437d-9725-1ddf4554e8d2

📥 Commits

Reviewing files that changed from the base of the PR and between 2fb89fb and 306339a.

📒 Files selected for processing (2)
  • libs/transloco-locale/src/lib/pipes/transloco-currency.pipe.ts
  • libs/transloco-locale/src/lib/tests/pipes/transloco-currency.pipe.spec.ts

📝 Walkthrough

Walkthrough

The TranslocoCurrencyPipe transform method's currency resolution now checks numberFormatOptions.currency as an intermediate fallback between the explicit currencyCode argument and the locale service's default resolution. Two tests were added covering this new precedence behavior.

Changes

Currency Resolution Fix

Layer / File(s) Summary
Currency precedence logic and tests
libs/transloco-locale/src/lib/pipes/transloco-currency.pipe.ts, libs/transloco-locale/src/lib/tests/pipes/transloco-currency.pipe.spec.ts
options.currency resolution now falls back to numberFormatOptions.currency before _resolveCurrencyCode(), with currencyCode argument still taking top priority; tests verify both the fallback and precedence cases.

Sequence Diagram(s)

Not applicable — this is a small, localized logic fix best illustrated by the flowchart in the hidden review stack above.

Related Issues: #934 — Fixes currency pipe ignoring the currency value set in NumberFormatOptions, ensuring it's used when currencyCode argument is omitted.

Suggested Labels: bug, locale

Suggested Reviewers: shaharkazaz, IdoBendetKfir

Fun i18n fact: the word for "currency" in Japanese is 通貨 (tsūka) — and Japan's Yen (¥) has no subunits in practice, since 1 yen is already the smallest denomination used, unlike the cents this pipe is busy juggling! 🪙

🐰 A rabbit hopped through currency code,
Chasing symbols down each locale road,
"Which euro, which dollar, which yen shall we show?"
Now numberFormatOptions gets its due glow,
Precedence fixed — onward the tests go! 🎉

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately summarizes the main change to TranslocoCurrencyPipe.
Description check ✅ Passed The PR description covers the bug, fix, tests, and current/new behavior, matching the template closely.
Linked Issues check ✅ Passed The code and tests directly address #934 by honoring numberFormatOptions.currency while keeping currencyCode precedence.
Out of Scope Changes check ✅ Passed The changes are limited to the currency pipe and its tests, with no unrelated scope added.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pkg-pr-new

pkg-pr-new Bot commented Jul 5, 2026

Copy link
Copy Markdown

Open in StackBlitz

@jsverse/transloco

npm i https://pkg.pr.new/jsverse/transloco/@jsverse/transloco@940

@jsverse/transloco-locale

npm i https://pkg.pr.new/jsverse/transloco/@jsverse/transloco-locale@940

@jsverse/transloco-messageformat

npm i https://pkg.pr.new/jsverse/transloco/@jsverse/transloco-messageformat@940

@jsverse/transloco-optimize

npm i https://pkg.pr.new/jsverse/transloco/@jsverse/transloco-optimize@940

@jsverse/transloco-persist-lang

npm i https://pkg.pr.new/jsverse/transloco/@jsverse/transloco-persist-lang@940

@jsverse/transloco-persist-translations

npm i https://pkg.pr.new/jsverse/transloco/@jsverse/transloco-persist-translations@940

@jsverse/transloco-preload-langs

npm i https://pkg.pr.new/jsverse/transloco/@jsverse/transloco-preload-langs@940

@jsverse/transloco-schematics

npm i https://pkg.pr.new/jsverse/transloco/@jsverse/transloco-schematics@940

@jsverse/transloco-scoped-libs

npm i https://pkg.pr.new/jsverse/transloco/@jsverse/transloco-scoped-libs@940

@jsverse/transloco-utils

npm i https://pkg.pr.new/jsverse/transloco/@jsverse/transloco-utils@940

@jsverse/transloco-validator

npm i https://pkg.pr.new/jsverse/transloco/@jsverse/transloco-validator@940

commit: 306339a

@shaharkazaz
shaharkazaz merged commit 04f9c11 into jsverse:master Jul 18, 2026
9 checks passed
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.

Bug(locale): currency pipe ignores currency argument in NumberFormatOptions

2 participants