Index: safari/ext/common.js |
=================================================================== |
--- a/safari/ext/common.js |
+++ b/safari/ext/common.js |
@@ -85,17 +85,16 @@ |
var candidates = []; |
var defaultLocale = "en_US"; |
- var bits, i; |
- for (i = (bits = navigator.language.split("-")).length; i > 0; i--) |
- { |
- var locale = bits.slice(0, i).join("_"); |
- candidates.push(locale); |
+ var match = navigator.language.match(/(.*?)(?:-(.*))?$/); |
+ var language = match[1]; |
+ var region = match[2]; |
Wladimir Palant
2014/04/10 08:05:34
It seems that you are still trying to split the st
Sebastian Noack
2014/04/10 08:55:52
Done, but I used ES6 array unpacking for better re
|
- if (locale == defaultLocale) |
- return candidates; |
- } |
+ if (region) |
+ candidates.push(language + "_" + region.toUpperCase()); |
- candidates.push(defaultLocale); |
+ candidates.push(language, defaultLocale); |
+ candidates.splice(candidates.indexOf(defaultLocale) + 1); |
Wladimir Palant
2014/04/10 08:05:34
I had some trouble understanding the purpose of th
Sebastian Noack
2014/04/10 08:55:52
Done, but I used candidates.indexOf(defaultLocale)
|
+ |
return candidates; |
}; |