Skip to content

Commit

Permalink
feat: re-use the store locale on the client if set on server (nuxt-mo…
Browse files Browse the repository at this point in the history
…dules#593)

If `vuex.syncLocale` is true, then any locale determined on the
server during SSR should be used as initial value by the client.

This also allows
- Not to determine the language twice when a page is loaded (once on
  the server, then again in the client)
- Other plugins (e.g. user session in a universal app) to alter the
  locale during bootstrap (`await app.i18n.setLocale('xx')`) and make
  sure that that locale is re-used on the client.
  • Loading branch information
matthieusieben authored Apr 3, 2020
1 parent e263850 commit c8b05b1
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/plugins/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,9 @@ export default async (context) => {

let locale = app.i18n.defaultLocale || null

if (app.i18n.differentDomains) {
if (vuex && vuex.syncLocale && store && store.state[vuex.moduleName].locale !== '') {
locale = store.state[vuex.moduleName].locale
} else if (app.i18n.differentDomains) {
const domainLocale = getLocaleDomain(app.i18n, req)
locale = domainLocale || locale
} else if (strategy !== STRATEGIES.NO_PREFIX) {
Expand Down

0 comments on commit c8b05b1

Please sign in to comment.