This repository has been archived by the owner on Mar 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6b5ffdb
commit b70a4ee
Showing
6 changed files
with
15,581 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
export default { | ||
name: 'browser', | ||
|
||
lookup(options) { | ||
// options -> are passed in options | ||
var userLang = navigator.language || navigator.userLanguage; | ||
return userLang; | ||
}, | ||
|
||
cacheUserLanguage(lng, options) { | ||
// options -> are passed in options | ||
// lng -> current language, will be called after init and on changeLanguage | ||
|
||
// store it | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import i18n from "i18next"; | ||
import { initReactI18next } from "react-i18next"; | ||
import LanguageDetector from 'i18next-browser-languagedetector'; | ||
import browserDetector from './browserDetector' | ||
|
||
import en_us from './en-us' | ||
import zh_cn from './zh-cn' | ||
|
||
const languageDetector = new LanguageDetector(); | ||
languageDetector.addDetector(browserDetector); | ||
|
||
|
||
|
||
// the translations | ||
// (tip move them in a JSON file and import them) | ||
const resources = { | ||
en: { | ||
...en_us | ||
}, | ||
zh: { | ||
...zh_cn | ||
} | ||
}; | ||
|
||
i18n | ||
.use(initReactI18next) // passes i18n down to react-i18next | ||
.use(languageDetector) | ||
.init({ | ||
resources, | ||
// lng: localStorage.getItem("lng") || 'en-us', | ||
detection:{ | ||
// order and from where user language should be detected | ||
order: ['querystring', 'cookie', 'localStorage','browser', 'navigator', 'path', 'subdomain'], | ||
|
||
// keys or params to lookup language from | ||
lookupQuerystring: 'lng', | ||
lookupCookie: 'i18next', | ||
lookupLocalStorage: 'i18nextLng', | ||
lookupFromPathIndex: 0, | ||
lookupFromSubdomainIndex: 0, | ||
|
||
// cache user language on | ||
caches: ['localStorage', 'cookie'], | ||
|
||
// optional htmlTag with lang attribute, the default is: | ||
}, | ||
fallbackLng: "en", | ||
keySeparator: false, // we do not use keys in form messages.welcome | ||
|
||
interpolation: { | ||
escapeValue: false // react already safes from xss | ||
} | ||
}); | ||
|
||
export default i18n; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |