mirror of
https://github.com/cheeaun/phanpy.git
synced 2024-11-21 16:55:25 +03:00
Try/catch all intl stuff
This commit is contained in:
parent
5bf81b2269
commit
2db909d7af
4 changed files with 31 additions and 14 deletions
|
@ -10,12 +10,16 @@ import states from '../utils/states';
|
|||
import Avatar from './avatar';
|
||||
import EmojiText from './emoji-text';
|
||||
|
||||
const nameCollator = mem(
|
||||
(locale) =>
|
||||
new Intl.Collator(locale || undefined, {
|
||||
sensitivity: 'base',
|
||||
}),
|
||||
);
|
||||
const nameCollator = mem((locale) => {
|
||||
const options = {
|
||||
sensitivity: 'base',
|
||||
};
|
||||
try {
|
||||
return new Intl.Collator(locale || undefined, options);
|
||||
} catch (e) {
|
||||
return new Intl.Collator(undefined, options);
|
||||
}
|
||||
});
|
||||
|
||||
function NameText({
|
||||
account,
|
||||
|
|
|
@ -20,8 +20,12 @@ i18n.on('change', () => {
|
|||
// lang
|
||||
document.documentElement.lang = lang;
|
||||
// LTR or RTL
|
||||
const { direction } = new Locale(lang).textInfo;
|
||||
document.documentElement.dir = direction;
|
||||
try {
|
||||
const { direction } = new Locale(lang).textInfo;
|
||||
document.documentElement.dir = direction;
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ const _DateTimeFormat = (opts) => {
|
|||
const { locale, dateYear, hideTime, formatOpts } = opts || {};
|
||||
const loc = locale && !/pseudo/i.test(locale) ? locale : defaultLocale;
|
||||
const currentYear = new Date().getFullYear();
|
||||
return Intl.DateTimeFormat(loc, {
|
||||
const options = {
|
||||
// Show year if not current year
|
||||
year: dateYear === currentYear ? undefined : 'numeric',
|
||||
month: 'short',
|
||||
|
@ -17,7 +17,12 @@ const _DateTimeFormat = (opts) => {
|
|||
hour: hideTime ? undefined : 'numeric',
|
||||
minute: hideTime ? undefined : 'numeric',
|
||||
...formatOpts,
|
||||
});
|
||||
};
|
||||
try {
|
||||
return Intl.DateTimeFormat(loc, opts);
|
||||
} catch (e) {
|
||||
return Intl.DateTimeFormat(undefined, opts);
|
||||
}
|
||||
};
|
||||
const DateTimeFormat = mem(_DateTimeFormat);
|
||||
|
||||
|
|
|
@ -1,8 +1,12 @@
|
|||
import { i18n } from '@lingui/core';
|
||||
|
||||
export default function shortenNumber(num) {
|
||||
return i18n.number(num, {
|
||||
notation: 'compact',
|
||||
roundingMode: 'floor',
|
||||
});
|
||||
try {
|
||||
return i18n.number(num, {
|
||||
notation: 'compact',
|
||||
roundingMode: 'floor',
|
||||
});
|
||||
} catch (e) {
|
||||
return num;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue