ampache_react/app/utils/locale.js
Phyks (Lucas Verney) 945b218504 Translations improved
* Translation system in place
* French translations available
2016-07-28 23:20:11 +02:00

32 lines
1010 B
JavaScript

export function getBrowserLocale () {
var lang;
if (navigator.languages) {
// chrome does not currently set navigator.language correctly https://code.google.com/p/chromium/issues/detail?id=101138
// but it does set the first element of navigator.languages correctly
lang = navigator.languages[0];
} else if (navigator.userLanguage) {
// IE only
lang = navigator.userLanguage;
} else {
// as of this writing the latest version of firefox + safari set this correctly
lang = navigator.language;
}
// Some browsers does not return uppercase for second part
var locale = lang.split("-");
locale = locale[1] ? `${locale[0]}-${locale[1].toUpperCase()}` : lang;
return locale;
}
export function messagesMap(messagesDescriptorsArray) {
var messagesDescriptorsMap = {};
messagesDescriptorsArray.forEach(function (item) {
messagesDescriptorsMap[item.id] = item;
});
return messagesDescriptorsMap;
}