Skip to content

Commit

Permalink
Add option to only detect language on root url nuxt-modules#761
Browse files Browse the repository at this point in the history
  • Loading branch information
ems1985 committed Jun 18, 2020
1 parent 088b1f1 commit 6228014
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/helpers/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ exports.DEFAULT_OPTIONS = {
cookieDomain: null,
cookieKey: 'i18n_redirected',
alwaysRedirect: false,
fallbackLocale: ''
fallbackLocale: '',
onlyRedirectFromRoot: false
},
differentDomains: false,
seo: false,
Expand Down
4 changes: 3 additions & 1 deletion src/templates/plugin.main.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,14 @@ export default async (context) => {
return false
}

const { alwaysRedirect, fallbackLocale } = detectBrowserLanguage
const { alwaysRedirect, fallbackLocale, onlyRedirectFromRoot } = detectBrowserLanguage

let matchedLocale

if (useCookie && (matchedLocale = app.i18n.getLocaleCookie())) {
// Get preferred language from cookie if present and enabled
} else if (onlyRedirectFromRoot && route.path !== '/') {
// Skip detection if not in root path
} else if (process.client && typeof navigator !== 'undefined' && navigator.languages) {
// Get browser language either from navigator if running on client side, or from the headers
matchedLocale = matchBrowserLocale(localeCodes, navigator.languages)
Expand Down

0 comments on commit 6228014

Please sign in to comment.