MCPcopy Index your code
hub / github.com/csev/py4e / chooseLocale

Function chooseLocale

code/gmane/Chart.bundle.js:1834–1856  ·  view source on GitHub ↗
(names)

Source from the content-addressed store, hash-verified

1832 // try ['en-au', 'en-gb'] as 'en-au', 'en-gb', 'en', as in move through the list trying each
1833 // substring from most specific to least, but move to the next array item if it's a more specific variant than the current root
1834 function chooseLocale(names) {
1835 var i = 0, j, next, locale, split;
1836
1837 while (i < names.length) {
1838 split = normalizeLocale(names[i]).split('-');
1839 j = split.length;
1840 next = normalizeLocale(names[i + 1]);
1841 next = next ? next.split('-') : null;
1842 while (j > 0) {
1843 locale = loadLocale(split.slice(0, j).join('-'));
1844 if (locale) {
1845 return locale;
1846 }
1847 if (next && next.length >= j && compareArrays(split, next, true) >= j - 1) {
1848 //the next array item is better than a shallower substring of this one
1849 break;
1850 }
1851 j--;
1852 }
1853 i++;
1854 }
1855 return null;
1856 }
1857
1858 function loadLocale(name) {
1859 var oldLocale = null;

Callers 1

Calls 5

normalizeLocaleFunction · 0.85
loadLocaleFunction · 0.85
compareArraysFunction · 0.85
splitMethod · 0.80
sliceMethod · 0.80

Tested by

no test coverage detected