Anything Intl always need to extract out

and memoized
pull/475/head
Lim Chee Aun 2024-04-03 19:48:18 +08:00
rodzic d77ba19308
commit 708976a9e9
1 zmienionych plików z 10 dodań i 4 usunięć

Wyświetl plik

@ -1,10 +1,16 @@
export default function localeCode2Text(code) {
import mem from './mem';
const IntlDN = new Intl.DisplayNames(navigator.languages, {
type: 'language',
});
function _localeCode2Text(code) {
try {
return new Intl.DisplayNames(navigator.languages, {
type: 'language',
}).of(code);
return IntlDN.of(code);
} catch (e) {
console.error(e);
return null;
}
}
export default mem(_localeCode2Text);