mirror of
https://github.com/cheeaun/phanpy.git
synced 2025-03-30 21:23:45 +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 Avatar from './avatar';
|
||||||
import EmojiText from './emoji-text';
|
import EmojiText from './emoji-text';
|
||||||
|
|
||||||
const nameCollator = mem(
|
const nameCollator = mem((locale) => {
|
||||||
(locale) =>
|
const options = {
|
||||||
new Intl.Collator(locale || undefined, {
|
sensitivity: 'base',
|
||||||
sensitivity: 'base',
|
};
|
||||||
}),
|
try {
|
||||||
);
|
return new Intl.Collator(locale || undefined, options);
|
||||||
|
} catch (e) {
|
||||||
|
return new Intl.Collator(undefined, options);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
function NameText({
|
function NameText({
|
||||||
account,
|
account,
|
||||||
|
|
|
@ -20,8 +20,12 @@ i18n.on('change', () => {
|
||||||
// lang
|
// lang
|
||||||
document.documentElement.lang = lang;
|
document.documentElement.lang = lang;
|
||||||
// LTR or RTL
|
// LTR or RTL
|
||||||
const { direction } = new Locale(lang).textInfo;
|
try {
|
||||||
document.documentElement.dir = direction;
|
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 { locale, dateYear, hideTime, formatOpts } = opts || {};
|
||||||
const loc = locale && !/pseudo/i.test(locale) ? locale : defaultLocale;
|
const loc = locale && !/pseudo/i.test(locale) ? locale : defaultLocale;
|
||||||
const currentYear = new Date().getFullYear();
|
const currentYear = new Date().getFullYear();
|
||||||
return Intl.DateTimeFormat(loc, {
|
const options = {
|
||||||
// Show year if not current year
|
// Show year if not current year
|
||||||
year: dateYear === currentYear ? undefined : 'numeric',
|
year: dateYear === currentYear ? undefined : 'numeric',
|
||||||
month: 'short',
|
month: 'short',
|
||||||
|
@ -17,7 +17,12 @@ const _DateTimeFormat = (opts) => {
|
||||||
hour: hideTime ? undefined : 'numeric',
|
hour: hideTime ? undefined : 'numeric',
|
||||||
minute: hideTime ? undefined : 'numeric',
|
minute: hideTime ? undefined : 'numeric',
|
||||||
...formatOpts,
|
...formatOpts,
|
||||||
});
|
};
|
||||||
|
try {
|
||||||
|
return Intl.DateTimeFormat(loc, opts);
|
||||||
|
} catch (e) {
|
||||||
|
return Intl.DateTimeFormat(undefined, opts);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
const DateTimeFormat = mem(_DateTimeFormat);
|
const DateTimeFormat = mem(_DateTimeFormat);
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,12 @@
|
||||||
import { i18n } from '@lingui/core';
|
import { i18n } from '@lingui/core';
|
||||||
|
|
||||||
export default function shortenNumber(num) {
|
export default function shortenNumber(num) {
|
||||||
return i18n.number(num, {
|
try {
|
||||||
notation: 'compact',
|
return i18n.number(num, {
|
||||||
roundingMode: 'floor',
|
notation: 'compact',
|
||||||
});
|
roundingMode: 'floor',
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
return num;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue