Skip to content

Instantly share code, notes, and snippets.

@SparK-Cruz
Created February 4, 2020 21:06
Show Gist options
  • Save SparK-Cruz/332a22dfb2c6a935803825f6e8d0f952 to your computer and use it in GitHub Desktop.
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
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