Anything Intl always need to extract out

and memoized
This commit is contained in:
Lim Chee Aun 2024-04-03 19:48:18 +08:00
parent d77ba19308
commit 708976a9e9

View file

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