2016-08-01 00:26:52 +02:00
|
|
|
export function getBrowserLocales () {
|
2016-08-05 00:00:25 +02:00
|
|
|
let langs;
|
2016-07-28 01:22:48 +02:00
|
|
|
|
|
|
|
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
|
2016-08-01 00:26:52 +02:00
|
|
|
langs = navigator.languages;
|
2016-07-28 01:22:48 +02:00
|
|
|
} else if (navigator.userLanguage) {
|
|
|
|
// IE only
|
2016-08-01 00:26:52 +02:00
|
|
|
langs = [navigator.userLanguage];
|
2016-07-28 01:22:48 +02:00
|
|
|
} else {
|
|
|
|
// as of this writing the latest version of firefox + safari set this correctly
|
2016-08-01 00:26:52 +02:00
|
|
|
langs = [navigator.language];
|
2016-07-28 01:22:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Some browsers does not return uppercase for second part
|
2016-08-05 00:00:25 +02:00
|
|
|
let locales = langs.map(function (lang) {
|
|
|
|
let locale = lang.split("-");
|
2016-08-01 00:26:52 +02:00
|
|
|
return locale[1] ? `${locale[0]}-${locale[1].toUpperCase()}` : lang;
|
|
|
|
});
|
2016-07-28 01:22:48 +02:00
|
|
|
|
2016-08-01 00:26:52 +02:00
|
|
|
return locales;
|
2016-07-28 01:22:48 +02:00
|
|
|
}
|
2016-07-28 23:14:52 +02:00
|
|
|
|
|
|
|
export function messagesMap(messagesDescriptorsArray) {
|
2016-08-05 00:00:25 +02:00
|
|
|
let messagesDescriptorsMap = {};
|
2016-07-28 23:14:52 +02:00
|
|
|
|
|
|
|
messagesDescriptorsArray.forEach(function (item) {
|
|
|
|
messagesDescriptorsMap[item.id] = item;
|
|
|
|
});
|
|
|
|
|
|
|
|
return messagesDescriptorsMap;
|
|
|
|
}
|