Skip to content

Commit

Permalink
refactor: initialize some variable at runtime to allow overrides (#1150)
Browse files Browse the repository at this point in the history
  • Loading branch information
tatarysh authored Apr 16, 2021
1 parent c7488b2 commit a1d926d
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions src/templates/plugin.main.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,6 @@ import { klona } from '~i18n-klona'

Vue.use(VueI18n)

const detectBrowserLanguage = /** @type {Required<import('../../types').DetectBrowserLanguageOptions>} */(options.detectBrowserLanguage)
const { alwaysRedirect, onlyOnNoPrefix, onlyOnRoot, fallbackLocale } = detectBrowserLanguage
const getLocaleFromRoute = createLocaleFromRouteGetter(options.localeCodes, {
routesNameSeparator: options.routesNameSeparator,
defaultLocaleRouteNameSuffix: options.defaultLocaleRouteNameSuffix
})

/** @type {import('@nuxt/types').Plugin} */
export default async (context) => {
const { app, route, store, req, res, redirect } = context
Expand Down Expand Up @@ -58,7 +51,17 @@ export default async (context) => {
})
}

const { useCookie, cookieKey, cookieDomain, cookieSecure, cookieCrossOrigin } = detectBrowserLanguage
const {
alwaysRedirect,
fallbackLocale,
onlyOnNoPrefix,
onlyOnRoot,
useCookie,
cookieKey,
cookieDomain,
cookieSecure,
cookieCrossOrigin
} = /** @type {Required<import('../../types').DetectBrowserLanguageOptions>} */(options.detectBrowserLanguage)

/**
* @param {string | undefined} newLocale
Expand Down Expand Up @@ -143,6 +146,11 @@ export default async (context) => {
}
}

const getLocaleFromRoute = createLocaleFromRouteGetter(options.localeCodes, {
routesNameSeparator: options.routesNameSeparator,
defaultLocaleRouteNameSuffix: options.defaultLocaleRouteNameSuffix
})

/**
* Gets the redirect path for locale.
*
Expand Down

0 comments on commit a1d926d

Please sign in to comment.