Skip to content

[v9.8.0] Suppressing automatic locale fallback with ! breaks n/$n number formatting #1641

Open
@shengslogar

Description

@shengslogar

Reporting a bug?

The docs describe adding an exclamation mark to locale to prevent vue-i18n from falling back to language parts when a regional/dialect match isn't found (e.g. en from en-US). While this is supported by the standard t/$t translator, it breaks the numeric n/$n formatter entirely, apparently due to passing the configured locale directly to new Intl.NumberFormat(locale, ...).

vue-i18n.js?v=01aa3a84:3153 Uncaught RangeError: Incorrect locale information provided
      at new NumberFormat (<anonymous>)
      at number (vue-i18n.js?v=01aa3a84:3153:12)
      at vue-i18n.js?v=01aa3a84:3825:46
      at wrapWithDeps (vue-i18n.js?v=01aa3a84:3773:13)
      at Proxy.n (vue-i18n.js?v=01aa3a84:3825:12)
      at Proxy._sfc_render (App.vue:9:6)
      at renderComponentRoot (chunk-FVTSMHLH.js?v=28e50421:2226:17)
      at ReactiveEffect.componentUpdateFn [as fn] (chunk-FVTSMHLH.js?v=28e50421:7162:46)
      at ReactiveEffect.run (chunk-FVTSMHLH.js?v=28e50421:422:19)
      at instance.update (chunk-FVTSMHLH.js?v=28e50421:7275:52)

Expected behavior

n/$n should behave the same as t/$t, and no error should occur.

Reproduction

https://stackblitz.com/edit/vitejs-vite-uyzmvt?file=src%2Fmain.ts,src%2FApp.vue

System Info

System:
    OS: macOS 14.1.1
    CPU: (10) arm64 Apple M1 Max
    Memory: 1.12 GB / 64.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 21.2.0 - /opt/homebrew/bin/node
    Yarn: 4.0.0 - /opt/homebrew/bin/yarn
    npm: 10.2.3 - /opt/homebrew/bin/npm
  Browsers:
    Chrome: 119.0.6045.159
    Safari: 17.1

Screenshot

No response

Additional context

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions