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) {
try {
return new Intl.DisplayNames(navigator.languages, {
import mem from './mem';
const IntlDN = new Intl.DisplayNames(navigator.languages, {
type: 'language',
}).of(code);
});
function _localeCode2Text(code) {
try {
return IntlDN.of(code);
} catch (e) {
console.error(e);
return null;
}
}
export default mem(_localeCode2Text);