2016-08-01 00:26:52 +02:00
|
|
|
export function getBrowserLocales () {
|
|
|
|
var 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-01 00:26:52 +02:00
|
|
|
var locales = langs.map(function (lang) {
|
|
|
|
var locale = lang.split("-");
|
|
|
|
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) {
|
|
|
|
var messagesDescriptorsMap = {};
|
|
|
|
|
|
|
|
messagesDescriptorsArray.forEach(function (item) {
|
|
|
|
messagesDescriptorsMap[item.id] = item;
|
|
|
|
});
|
|
|
|
|
|
|
|
return messagesDescriptorsMap;
|
|
|
|
}
|