Skip to content

Commit a4bb7e2

Browse files
authored
fix(i18n): expose numericGroupSeparator from locale adapter (#372) (#373)
1 parent 7d83f75 commit a4bb7e2

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

  • packages/vuetify-nuxt-module/src/runtime/plugins

packages/vuetify-nuxt-module/src/runtime/plugins/i18n.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ function inferDecimalSeparator (n: ReturnType<typeof useI18n>['n']) {
99
return n(0.1).includes(',') ? ',' : '.'
1010
}
1111

12+
function inferNumericGroupSeparator (n: ReturnType<typeof useI18n>['n']) {
13+
// Vuetify's own adapter uses `n(10000, { part: true }).find(...)`, but vue-i18n's
14+
// `n` does not honour `part` in every Nuxt i18n setup (it returns a string, not
15+
// parts), so derive the separator from the grouped output instead — same string
16+
// approach as inferDecimalSeparator above.
17+
return n(10_000, { useGrouping: true }).replace(/\p{Nd}/gu, '') || ' '
18+
}
19+
1220
export function createAdapter (vuetifyOptions: VuetifyOptions) {
1321
vuetifyOptions.locale = {}
1422
const nuxtApp = useNuxtApp()
@@ -42,6 +50,7 @@ export function createAdapter (vuetifyOptions: VuetifyOptions) {
4250
n: i18n.n,
4351
provide: createProvideFunction({ current: currentLocale, fallback, messages }),
4452
decimalSeparator: toRef(() => inferDecimalSeparator(i18n.n)),
53+
numericGroupSeparator: toRef(() => inferNumericGroupSeparator(i18n.n)),
4554
}
4655
}
4756

@@ -81,6 +90,7 @@ function createProvideFunction (data: {
8190
t,
8291
n,
8392
decimalSeparator: toRef(() => props.decimalSeparator ?? inferDecimalSeparator(n)),
93+
numericGroupSeparator: toRef(() => inferNumericGroupSeparator(n)),
8494
provide: createProvideFunction({ current: currentLocale, fallback: data.fallback, messages: data.messages }),
8595
}
8696
}

0 commit comments

Comments
 (0)