Created
February 4, 2020 21:06
-
-
Save SparK-Cruz/332a22dfb2c6a935803825f6e8d0f952 to your computer and use it in GitHub Desktop.
Locale detector and organizer for using with i18n property of vue root object using the vue-i18n plugin
This file contains hidden or 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
import en from './en'; | |
import pt from './pt'; | |
import es from './es'; | |
const Locale = { | |
sharedMessages: { | |
en, | |
pt, | |
es | |
} | |
}; | |
Object.defineProperty(Locale, 'locale', { | |
get: function() { | |
for (let lang of navigator.languages) { | |
if (!this.sharedMessages.hasOwnProperty(lang)) | |
continue; | |
return lang; | |
} | |
return 'en'; // default | |
} | |
}) | |
export default Locale |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment