Active locale: {{ locale }}
``` Read `locale.value` in ordinary script expressions. Components, computed values, and render effects that read the ref update after a reactive locale switch finishes. ## Build a language switcher [#switcher] [`useSetLocale()`](/docs/vue/reference/composables/use-set-locale) returns an async setter. Await it so the interface can represent a pending load or handle a rejection: ```vue title="src/components/LocaleSwitcher.vue" ``` With a [`createGT()`](/docs/vue/reference/functions/create-gt) plugin, the setter loads an uncached catalog before changing the locale. Successful results are cached. If requests overlap, only the latest request changes the active locale. An empty catalog is a successful load: the locale changes and source content renders as the fallback. A rejected loader leaves the active locale and its cookie unchanged. ## Persist the locale [#persistence] In a browser, the active locale is stored in a path-wide session cookie named `generaltranslation.locale`. When `locale` is omitted from [`createGT()`](/docs/vue/reference/functions/create-gt), that cookie wins over `defaultLocale`. Set `localeCookieName` when the app must share another cookie with a router or server: ```ts createGT({ defaultLocale: 'en', localeCookieName: 'my-app.locale', loadTranslations, }); ``` Use [`useSetLocale()`](/docs/vue/reference/composables/use-set-locale) rather than writing the cookie directly. Browsers do not emit a reactive event for cookie changes, so an external write does not schedule a Vue render by itself. ## Choose reactive or reload-based switching [#runtime-mode] The initialization mode determines what happens after the cookie changes: - [`createGT()`](/docs/vue/reference/functions/create-gt) loads the catalog and updates reactive consumers without reloading the page. - [`initializeGTSPA()`](/docs/vue/reference/functions/initialize-gt-spa) writes the cookie and reloads the document so module-level [`t()`](/docs/vue/reference/functions/t) calls execute again after preloading the new locale. The SPA initializer accepts `locales` and falls back to `defaultLocale` when a saved or requested locale is unsupported. Follow [Developing with SPA translations](/docs/vue/guides/developing-spa-translations) when module-level translation requires that behavior. For server rendering, resolve the request locale on the server and pass it explicitly to [`createGT()`](/docs/vue/reference/functions/create-gt). The explicit value overrides a stale browser cookie and keeps the server render and hydration locale aligned. ## Next steps - /docs/vue/guides/configuring - /docs/vue/guides/storing-translations - /docs/vue/guides/developing-spa-translations - /docs/vue/guides/translating-content