Simplify i18n: remove old react-intl artifacts, rename formatMessage to t, replace FormattedMessage with t.rich().
- Rewrite messages.ts to plain string key maps (remove MessageDescriptor) - Rewrite useMessages hook to expose t from useTranslations() directly - Rename formatMessage → t across 193 consumer files - Replace custom FormattedMessage component with next-intl t.rich() - Update 52 language files to use rich text tags (<b>, <a>) - Remove all direct imports from @/components/messages in favor of useMessages() Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
80cad6ea65
commit
50edb71687
247 files changed
+1660
-2194
No files matched your search
@@ -12,7 +12,7 @@ export function ActiveUsers({
|
||||
value?: number;
|
||||
refetchInterval?: number;
|
||||
}) {
|
||||
const { formatMessage, labels } = useMessages();
|
||||
const { t, labels } = useMessages();
|
||||
const { data } = useActyiveUsersQuery(websiteId, { refetchInterval });
|
||||
|
||||
const count = useMemo(() => {
|
||||
@@ -31,7 +31,7 @@ export function ActiveUsers({
|
||||
<LinkButton href={`/websites/${websiteId}/realtime`} variant="quiet">
|
||||
<StatusLight variant="success">
|
||||
<Text size="sm" weight="medium">
|
||||
{count} {formatMessage(labels.online)}
|
||||
{count} {t(labels.online)}
|
||||
</Text>
|
||||
</StatusLight>
|
||||
</LinkButton>
|
||||
|
||||
@@ -20,7 +20,7 @@ export function DatePickerForm({
|
||||
const [date, setDate] = useState(defaultStartDate || new Date());
|
||||
const [startDate, setStartDate] = useState(defaultStartDate || new Date());
|
||||
const [endDate, setEndDate] = useState(defaultEndDate || new Date());
|
||||
const { formatMessage, labels } = useMessages();
|
||||
const { t, labels } = useMessages();
|
||||
|
||||
const disabled = selected.includes(FILTER_DAY)
|
||||
? isAfter(minDate, date) && isBefore(maxDate, date)
|
||||
@@ -38,8 +38,8 @@ export function DatePickerForm({
|
||||
<Column gap>
|
||||
<Row justifyContent="center">
|
||||
<ToggleGroup disallowEmptySelection value={selected} onChange={setSelected}>
|
||||
<ToggleGroupItem id={FILTER_DAY}>{formatMessage(labels.singleDay)}</ToggleGroupItem>
|
||||
<ToggleGroupItem id={FILTER_RANGE}>{formatMessage(labels.dateRange)}</ToggleGroupItem>
|
||||
<ToggleGroupItem id={FILTER_DAY}>{t(labels.singleDay)}</ToggleGroupItem>
|
||||
<ToggleGroupItem id={FILTER_RANGE}>{t(labels.dateRange)}</ToggleGroupItem>
|
||||
</ToggleGroup>
|
||||
</Row>
|
||||
<Column>
|
||||
@@ -64,9 +64,9 @@ export function DatePickerForm({
|
||||
)}
|
||||
</Column>
|
||||
<Row justifyContent="end" gap>
|
||||
<Button onPress={onClose}>{formatMessage(labels.cancel)}</Button>
|
||||
<Button onPress={onClose}>{t(labels.cancel)}</Button>
|
||||
<Button variant="primary" onPress={handleSave} isDisabled={disabled}>
|
||||
{formatMessage(labels.apply)}
|
||||
{t(labels.apply)}
|
||||
</Button>
|
||||
</Row>
|
||||
</Column>
|
||||
|
||||
@@ -41,7 +41,7 @@ export function ListTable({
|
||||
itemCount = 10,
|
||||
currency,
|
||||
}: ListTableProps) {
|
||||
const { formatMessage, labels } = useMessages();
|
||||
const { t, labels } = useMessages();
|
||||
const { isPhone } = useMobile();
|
||||
|
||||
const getRow = (row: ListData, index: number) => {
|
||||
@@ -50,7 +50,7 @@ export function ListTable({
|
||||
return (
|
||||
<AnimatedRow
|
||||
key={`${label}${index}`}
|
||||
label={renderLabel ? renderLabel(row, index) : (label ?? formatMessage(labels.unknown))}
|
||||
label={renderLabel ? renderLabel(row, index) : (label ?? t(labels.unknown))}
|
||||
value={count}
|
||||
percent={percent}
|
||||
animate={animate && !virtualize}
|
||||
|
||||
@@ -18,7 +18,7 @@ export interface MetricLabelProps {
|
||||
}
|
||||
|
||||
export function MetricLabel({ type, data }: MetricLabelProps) {
|
||||
const { formatMessage, labels } = useMessages();
|
||||
const { t, labels } = useMessages();
|
||||
const { formatValue, formatCity } = useFormat();
|
||||
const { locale } = useLocale();
|
||||
const { countryNames } = useCountryNames(locale);
|
||||
@@ -39,7 +39,7 @@ export function MetricLabel({ type, data }: MetricLabelProps) {
|
||||
);
|
||||
|
||||
case 'channel':
|
||||
return formatMessage(labels[label]);
|
||||
return t(labels[label]);
|
||||
|
||||
case 'city':
|
||||
return (
|
||||
@@ -87,7 +87,7 @@ export function MetricLabel({ type, data }: MetricLabelProps) {
|
||||
<FilterLink
|
||||
type={type === 'entry' || type === 'exit' ? 'path' : type}
|
||||
value={label}
|
||||
label={!label && formatMessage(labels.none)}
|
||||
label={!label && t(labels.none)}
|
||||
externalUrl={
|
||||
domain ? `${domain?.startsWith('http') ? domain : `https://${domain}`}${label}` : null
|
||||
}
|
||||
@@ -110,14 +110,14 @@ export function MetricLabel({ type, data }: MetricLabelProps) {
|
||||
type="referrer"
|
||||
value={label}
|
||||
externalUrl={`https://${label}`}
|
||||
label={!label && formatMessage(labels.none)}
|
||||
label={!label && t(labels.none)}
|
||||
icon={<Favicon domain={label} />}
|
||||
/>
|
||||
);
|
||||
|
||||
case 'domain':
|
||||
if (label === 'Other') {
|
||||
return `(${formatMessage(labels.other)})`;
|
||||
return `(${t(labels.other)})`;
|
||||
} else {
|
||||
const name = GROUPED_DOMAINS.find(({ domain }) => domain === label)?.name;
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ export function MetricsExpandedTable({
|
||||
children,
|
||||
}: MetricsExpandedTableProps) {
|
||||
const [search, setSearch] = useState('');
|
||||
const { formatMessage, labels } = useMessages();
|
||||
const { t, labels } = useMessages();
|
||||
const isType = ['browser', 'country', 'device', 'os'].includes(type);
|
||||
const showBounceDuration = SESSION_COLUMNS.includes(type);
|
||||
|
||||
@@ -79,35 +79,20 @@ export function MetricsExpandedTable({
|
||||
</Row>
|
||||
)}
|
||||
</DataColumn>
|
||||
<DataColumn
|
||||
id="visitors"
|
||||
label={formatMessage(labels.visitors)}
|
||||
align="end"
|
||||
width="120px"
|
||||
>
|
||||
<DataColumn id="visitors" label={t(labels.visitors)} align="end" width="120px">
|
||||
{row => row?.visitors?.toLocaleString()}
|
||||
</DataColumn>
|
||||
<DataColumn
|
||||
id="visits"
|
||||
label={formatMessage(labels.visits)}
|
||||
align="end"
|
||||
width="120px"
|
||||
>
|
||||
<DataColumn id="visits" label={t(labels.visits)} align="end" width="120px">
|
||||
{row => row?.visits?.toLocaleString()}
|
||||
</DataColumn>
|
||||
<DataColumn
|
||||
id="pageviews"
|
||||
label={formatMessage(labels.views)}
|
||||
align="end"
|
||||
width="120px"
|
||||
>
|
||||
<DataColumn id="pageviews" label={t(labels.views)} align="end" width="120px">
|
||||
{row => row?.pageviews?.toLocaleString()}
|
||||
</DataColumn>
|
||||
{showBounceDuration && [
|
||||
<DataColumn
|
||||
key="bounceRate"
|
||||
id="bounceRate"
|
||||
label={formatMessage(labels.bounceRate)}
|
||||
label={t(labels.bounceRate)}
|
||||
align="end"
|
||||
width="120px"
|
||||
>
|
||||
@@ -120,7 +105,7 @@ export function MetricsExpandedTable({
|
||||
<DataColumn
|
||||
key="visitDuration"
|
||||
id="visitDuration"
|
||||
label={formatMessage(labels.visitDuration)}
|
||||
label={t(labels.visitDuration)}
|
||||
align="end"
|
||||
width="120px"
|
||||
>
|
||||
|
||||
@@ -32,7 +32,7 @@ export function MetricsTable({
|
||||
...props
|
||||
}: MetricsTableProps) {
|
||||
const { updateParams } = useNavigation();
|
||||
const { formatMessage, labels } = useMessages();
|
||||
const { t, labels } = useMessages();
|
||||
const { data, isLoading, isFetching, error } = useWebsiteMetricsQuery(websiteId, {
|
||||
type,
|
||||
limit,
|
||||
@@ -83,7 +83,7 @@ export function MetricsTable({
|
||||
{showMore && limit && (
|
||||
<Row justifyContent="center" alignItems="flex-end" paddingTop="4">
|
||||
<LinkButton href={updateParams({ view: type })} variant="quiet">
|
||||
<IconLabel icon={<Maximize />}>{formatMessage(labels.more)}</IconLabel>
|
||||
<IconLabel icon={<Maximize />}>{t(labels.more)}</IconLabel>
|
||||
</LinkButton>
|
||||
</Row>
|
||||
)}
|
||||
|
||||
@@ -19,7 +19,7 @@ export interface PageviewsChartProps extends BarChartProps {
|
||||
}
|
||||
|
||||
export function PageviewsChart({ data, unit, minDate, maxDate, ...props }: PageviewsChartProps) {
|
||||
const { formatMessage, labels } = useMessages();
|
||||
const { t, labels } = useMessages();
|
||||
const { theme } = useTheme();
|
||||
const { locale, dateLocale } = useLocale();
|
||||
const { colors } = useMemo(() => getThemeColors(theme), [theme]);
|
||||
@@ -32,7 +32,7 @@ export function PageviewsChart({ data, unit, minDate, maxDate, ...props }: Pagev
|
||||
datasets: [
|
||||
{
|
||||
type: 'bar',
|
||||
label: formatMessage(labels.visitors),
|
||||
label: t(labels.visitors),
|
||||
data: generateTimeSeries(data.sessions, minDate, maxDate, unit, dateLocale),
|
||||
borderWidth: 1,
|
||||
barPercentage: 0.9,
|
||||
@@ -42,7 +42,7 @@ export function PageviewsChart({ data, unit, minDate, maxDate, ...props }: Pagev
|
||||
},
|
||||
{
|
||||
type: 'bar',
|
||||
label: formatMessage(labels.views),
|
||||
label: t(labels.views),
|
||||
data: generateTimeSeries(data.pageviews, minDate, maxDate, unit, dateLocale),
|
||||
barPercentage: 0.9,
|
||||
categoryPercentage: 0.9,
|
||||
@@ -54,7 +54,7 @@ export function PageviewsChart({ data, unit, minDate, maxDate, ...props }: Pagev
|
||||
? [
|
||||
{
|
||||
type: 'line',
|
||||
label: `${formatMessage(labels.views)} (${formatMessage(labels.previous)})`,
|
||||
label: `${t(labels.views)} (${t(labels.previous)})`,
|
||||
data: generateTimeSeries(
|
||||
data.compare.pageviews,
|
||||
minDate,
|
||||
@@ -69,7 +69,7 @@ export function PageviewsChart({ data, unit, minDate, maxDate, ...props }: Pagev
|
||||
},
|
||||
{
|
||||
type: 'line',
|
||||
label: `${formatMessage(labels.visitors)} (${formatMessage(labels.previous)})`,
|
||||
label: `${t(labels.visitors)} (${t(labels.previous)})`,
|
||||
data: generateTimeSeries(data.compare.sessions, minDate, maxDate, unit, dateLocale),
|
||||
borderWidth: 2,
|
||||
backgroundColor: '#f15bb5',
|
||||
|
||||
@@ -7,7 +7,7 @@ import { getDayOfWeekAsDate } from '@/lib/date';
|
||||
export function WeeklyTraffic({ websiteId }: { websiteId: string }) {
|
||||
const { data, isLoading, error } = useWeeklyTrafficQuery(websiteId);
|
||||
const { dateLocale } = useLocale();
|
||||
const { labels, formatMessage } = useMessages();
|
||||
const { labels, t } = useMessages();
|
||||
const { weekStartsOn } = dateLocale.options;
|
||||
const daysOfWeek = Array(7)
|
||||
.fill(weekStartsOn)
|
||||
@@ -96,7 +96,7 @@ export function WeeklyTraffic({ websiteId }: { websiteId: string }) {
|
||||
</Row>
|
||||
</Focusable>
|
||||
<Tooltip placement="right">
|
||||
<Text>{`${formatMessage(labels.visitors)}: ${count}`}</Text>
|
||||
<Text size="base">{`${t(labels.visitors)}: ${count}`}</Text>
|
||||
</Tooltip>
|
||||
</TooltipTrigger>
|
||||
);
|
||||
|
||||
@@ -23,10 +23,10 @@ export function WorldMap({ websiteId, data, ...props }: WorldMapProps) {
|
||||
const { theme } = useTheme();
|
||||
const { colors } = getThemeColors(theme);
|
||||
const { locale } = useLocale();
|
||||
const { formatMessage, labels } = useMessages();
|
||||
const { t, labels } = useMessages();
|
||||
const { countryNames } = useCountryNames(locale);
|
||||
const visitorsLabel = formatMessage(labels.visitors).toLocaleLowerCase(locale);
|
||||
const unknownLabel = formatMessage(labels.unknown);
|
||||
const visitorsLabel = t(labels.visitors).toLocaleLowerCase(locale);
|
||||
const unknownLabel = t(labels.unknown);
|
||||
|
||||
const { data: mapData } = useWebsiteMetricsQuery(websiteId, {
|
||||
type: 'country',
|
||||
|
||||
Reference in new issue
Block a user