diff --git a/src/i18n/index.ts b/src/i18n/index.ts index ec7048f..0e62670 100644 --- a/src/i18n/index.ts +++ b/src/i18n/index.ts @@ -1,4 +1,6 @@ +import isNodeJs from 'detect-node' + import en from './en' import es from './es' @@ -24,8 +26,17 @@ const locales = ( (l: L) // detect browser language const lang = (() => { + let userLangs: readonly string[] + if (!isNodeJs) { + userLangs = navigator.languages + } else { + const env = process.env + const l = env.LC_ALL || env.LC_MESSAGES || env.LANG || env.LANGUAGE || '' + userLangs = [l.slice(0, 2)] + } + const names = Object.keys(locales) - const _lang = navigator.languages.find(l => { + const _lang = userLangs.find(l => { // find the first occurrence of valid languages return names.includes(l) })