(names)
| 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; |
no test coverage detected