MCPcopy Create free account
hub / github.com/scottrogowski/code2flow / chooseLocale

Function chooseLocale

tests/test_code/js/moment/moment.js:2047–2077  ·  view source on GitHub ↗
(names)

Source from the content-addressed store, hash-verified

2045 // try ['en-au', 'en-gb'] as 'en-au', 'en-gb', 'en', as in move through the list trying each
2046 // substring from most specific to least, but move to the next array item if it's a more specific variant than the current root
2047 function chooseLocale(names) {
2048 var i = 0,
2049 j,
2050 next,
2051 locale,
2052 split;
2053
2054 while (i < names.length) {
2055 split = normalizeLocale(names[i]).split('-');
2056 j = split.length;
2057 next = normalizeLocale(names[i + 1]);
2058 next = next ? next.split('-') : null;
2059 while (j > 0) {
2060 locale = loadLocale(split.slice(0, j).join('-'));
2061 if (locale) {
2062 return locale;
2063 }
2064 if (
2065 next &&
2066 next.length >= j &&
2067 commonPrefix(split, next) >= j - 1
2068 ) {
2069 //the next array item is better than a shallower substring of this one
2070 break;
2071 }
2072 j--;
2073 }
2074 i++;
2075 }
2076 return globalLocale;
2077 }
2078
2079 function loadLocale(name) {
2080 var oldLocale = null,

Callers 1

getLocaleFunction · 0.85

Calls 3

normalizeLocaleFunction · 0.85
loadLocaleFunction · 0.85
commonPrefixFunction · 0.85

Tested by

no test coverage detected