You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/guide/advanced/composition.md
+66Lines changed: 66 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -468,6 +468,72 @@ If you do not want to inherit the locale from the global scope, the `inheritLoca
468
468
Changes to the `locale` at the local scope have **no effect on the global scope locale, but only within the local scope**.
469
469
:::
470
470
471
+
## Isolated scope
472
+
473
+
The isolated scope creates an independent Composer instance that is **not tied to the component**. This is useful when you want to use `useI18n` inside a composable with its own translation messages, without conflicting with the component's local scope.
474
+
475
+
### Why isolated scope?
476
+
477
+
When a component and a composable both call `useI18n` with local scope, the second call conflicts with the first because only one local scope per component is allowed. The isolated scope solves this by creating a Composer that:
478
+
479
+
- Is **not registered** with the component's uid (no duplicate detection)
480
+
- Does **not propagate** to child components via `provide`
481
+
- Does **not merge** SFC i18n custom blocks
482
+
-**Inherits locale** from the parent/global scope (by default)
483
+
-**Falls back** to the parent/global scope for missing translation keys
import { useProjectStatus } from './useProjectStatus'
514
+
515
+
// Local scope for the component
516
+
const { t } = useI18n({
517
+
messages: {
518
+
en: { title: 'Project Dashboard' },
519
+
ja: { title: 'プロジェクトダッシュボード' }
520
+
}
521
+
})
522
+
523
+
// Composable with isolated scope — no conflict!
524
+
const status = useProjectStatus(project)
525
+
</script>
526
+
527
+
<template>
528
+
<h1>{{ t('title') }}</h1>
529
+
<p>{{ status }}</p>
530
+
</template>
531
+
```
532
+
533
+
:::tip NOTE
534
+
The isolated scope inherits locale from the global scope by default. When the global locale changes, the isolated scope's locale is automatically updated. You can disable this behavior by setting `inheritLocale: false`.
535
+
:::
536
+
471
537
## Mapping from VueI18n to Composer
472
538
473
539
If you are migrating from v11 or earlier, see the [v12 Breaking Changes](../migration/breaking12#drop-legacy-api-mode) for a detailed mapping between the VueI18n instance (Legacy API) and the Composer instance (Composition API).
0 commit comments