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
@@ -3,33 +3,33 @@ import { useMessages, useNavigation } from '@/components/hooks';
|
||||
import { Settings2, UserCircle, Users } from '@/components/icons';
|
||||
|
||||
export function SettingsNav({ onItemClick }: { onItemClick?: () => void }) {
|
||||
const { formatMessage, labels } = useMessages();
|
||||
const { t, labels } = useMessages();
|
||||
const { renderUrl, pathname } = useNavigation();
|
||||
|
||||
const items = [
|
||||
{
|
||||
label: formatMessage(labels.application),
|
||||
label: t(labels.application),
|
||||
items: [
|
||||
{
|
||||
id: 'preferences',
|
||||
label: formatMessage(labels.preferences),
|
||||
label: t(labels.preferences),
|
||||
path: renderUrl('/settings/preferences'),
|
||||
icon: <Settings2 />,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
label: formatMessage(labels.account),
|
||||
label: t(labels.account),
|
||||
items: [
|
||||
{
|
||||
id: 'profile',
|
||||
label: formatMessage(labels.profile),
|
||||
label: t(labels.profile),
|
||||
path: renderUrl('/settings/profile'),
|
||||
icon: <UserCircle />,
|
||||
},
|
||||
{
|
||||
id: 'teams',
|
||||
label: formatMessage(labels.teams),
|
||||
label: t(labels.teams),
|
||||
path: renderUrl('/settings/teams'),
|
||||
icon: <Users />,
|
||||
},
|
||||
@@ -44,7 +44,7 @@ export function SettingsNav({ onItemClick }: { onItemClick?: () => void }) {
|
||||
return (
|
||||
<NavMenu
|
||||
items={items}
|
||||
title={formatMessage(labels.settings)}
|
||||
title={t(labels.settings)}
|
||||
selectedKey={selectedKey}
|
||||
allowMinimize={false}
|
||||
onItemClick={onItemClick}
|
||||
|
||||
@@ -6,7 +6,7 @@ import { DATE_RANGE_CONFIG, DEFAULT_DATE_RANGE_VALUE } from '@/lib/constants';
|
||||
import { getItem, setItem } from '@/lib/storage';
|
||||
|
||||
export function DateRangeSetting() {
|
||||
const { formatMessage, labels } = useMessages();
|
||||
const { t, labels } = useMessages();
|
||||
const [date, setDate] = useState(getItem(DATE_RANGE_CONFIG) || DEFAULT_DATE_RANGE_VALUE);
|
||||
|
||||
const handleChange = (value: string) => {
|
||||
@@ -27,7 +27,7 @@ export function DateRangeSetting() {
|
||||
placement="bottom start"
|
||||
style={{ minWidth: '250px' }}
|
||||
/>
|
||||
<Button onPress={handleReset}>{formatMessage(labels.reset)}</Button>
|
||||
<Button onPress={handleReset}>{t(labels.reset)}</Button>
|
||||
</Row>
|
||||
);
|
||||
}
|
||||
@@ -6,7 +6,7 @@ import { languages } from '@/lib/lang';
|
||||
|
||||
export function LanguageSetting() {
|
||||
const [search, setSearch] = useState('');
|
||||
const { formatMessage, labels } = useMessages();
|
||||
const { t, labels } = useMessages();
|
||||
const { locale, saveLocale } = useLocale();
|
||||
const items = search
|
||||
? Object.keys(languages).filter(n => {
|
||||
@@ -43,7 +43,7 @@ export function LanguageSetting() {
|
||||
))}
|
||||
{!items.length && <ListItem></ListItem>}
|
||||
</Select>
|
||||
<Button onPress={handleReset}>{formatMessage(labels.reset)}</Button>
|
||||
<Button onPress={handleReset}>{t(labels.reset)}</Button>
|
||||
</Row>
|
||||
);
|
||||
}
|
||||
@@ -8,7 +8,7 @@ import { VersionSetting } from './VersionSetting';
|
||||
|
||||
export function PreferenceSettings() {
|
||||
const { user } = useLoginQuery();
|
||||
const { formatMessage, labels } = useMessages();
|
||||
const { t, labels } = useMessages();
|
||||
|
||||
if (!user) {
|
||||
return null;
|
||||
@@ -17,23 +17,23 @@ export function PreferenceSettings() {
|
||||
return (
|
||||
<Column gap="6">
|
||||
<Column>
|
||||
<Label>{formatMessage(labels.defaultDateRange)}</Label>
|
||||
<Label>{t(labels.defaultDateRange)}</Label>
|
||||
<DateRangeSetting />
|
||||
</Column>
|
||||
<Column>
|
||||
<Label>{formatMessage(labels.timezone)}</Label>
|
||||
<Label>{t(labels.timezone)}</Label>
|
||||
<TimezoneSetting />
|
||||
</Column>
|
||||
<Column>
|
||||
<Label>{formatMessage(labels.language)}</Label>
|
||||
<Label>{t(labels.language)}</Label>
|
||||
<LanguageSetting />
|
||||
</Column>
|
||||
<Column>
|
||||
<Label>{formatMessage(labels.theme)}</Label>
|
||||
<Label>{t(labels.theme)}</Label>
|
||||
<ThemeSetting />
|
||||
</Column>
|
||||
<Column>
|
||||
<Label>{formatMessage(labels.version)}</Label>
|
||||
<Label>{t(labels.version)}</Label>
|
||||
<VersionSetting />
|
||||
</Column>
|
||||
</Column>
|
||||
|
||||
@@ -7,12 +7,12 @@ import { useMessages } from '@/components/hooks';
|
||||
import { PreferenceSettings } from './PreferenceSettings';
|
||||
|
||||
export function PreferencesPage() {
|
||||
const { formatMessage, labels } = useMessages();
|
||||
const { t, labels } = useMessages();
|
||||
|
||||
return (
|
||||
<PageBody>
|
||||
<Column gap="6">
|
||||
<PageHeader title={formatMessage(labels.preferences)} />
|
||||
<PageHeader title={t(labels.preferences)} />
|
||||
<Panel>
|
||||
<PreferenceSettings />
|
||||
</Panel>
|
||||
|
||||
@@ -7,7 +7,7 @@ const timezones = Intl.supportedValuesOf('timeZone');
|
||||
|
||||
export function TimezoneSetting() {
|
||||
const [search, setSearch] = useState('');
|
||||
const { formatMessage, labels } = useMessages();
|
||||
const { t, labels } = useMessages();
|
||||
const { timezone, saveTimezone } = useTimezone();
|
||||
const items = search
|
||||
? timezones.filter(n => n.toLowerCase().includes(search.toLowerCase()))
|
||||
@@ -39,7 +39,7 @@ export function TimezoneSetting() {
|
||||
))}
|
||||
{!items.length && <ListItem></ListItem>}
|
||||
</Select>
|
||||
<Button onPress={handleReset}>{formatMessage(labels.reset)}</Button>
|
||||
<Button onPress={handleReset}>{t(labels.reset)}</Button>
|
||||
</Row>
|
||||
);
|
||||
}
|
||||
@@ -4,11 +4,11 @@ import { LockKeyhole } from '@/components/icons';
|
||||
import { PasswordEditForm } from './PasswordEditForm';
|
||||
|
||||
export function PasswordChangeButton() {
|
||||
const { formatMessage, labels, messages } = useMessages();
|
||||
const { t, labels, messages } = useMessages();
|
||||
const { toast } = useToast();
|
||||
|
||||
const handleSave = () => {
|
||||
toast(formatMessage(messages.saved));
|
||||
toast(t(messages.saved));
|
||||
};
|
||||
|
||||
return (
|
||||
@@ -17,10 +17,10 @@ export function PasswordChangeButton() {
|
||||
<Icon>
|
||||
<LockKeyhole />
|
||||
</Icon>
|
||||
<Text>{formatMessage(labels.changePassword)}</Text>
|
||||
<Text>{t(labels.changePassword)}</Text>
|
||||
</Button>
|
||||
<Modal>
|
||||
<Dialog title={formatMessage(labels.changePassword)} style={{ width: 400 }}>
|
||||
<Dialog title={t(labels.changePassword)} style={{ width: 400 }}>
|
||||
{({ close }) => <PasswordEditForm onSave={handleSave} onClose={close} />}
|
||||
</Dialog>
|
||||
</Modal>
|
||||
|
||||
@@ -9,7 +9,7 @@ import {
|
||||
import { useMessages, useUpdateQuery } from '@/components/hooks';
|
||||
|
||||
export function PasswordEditForm({ onSave, onClose }) {
|
||||
const { formatMessage, labels, messages, getErrorMessage } = useMessages();
|
||||
const { t, labels, messages, getErrorMessage } = useMessages();
|
||||
const { mutateAsync, error, isPending } = useUpdateQuery('/me/password');
|
||||
|
||||
const handleSubmit = async (data: any) => {
|
||||
@@ -23,7 +23,7 @@ export function PasswordEditForm({ onSave, onClose }) {
|
||||
|
||||
const samePassword = (value: string, values: Record<string, any>) => {
|
||||
if (value !== values.newPassword) {
|
||||
return formatMessage(messages.noMatchPassword);
|
||||
return t(messages.noMatchPassword);
|
||||
}
|
||||
return true;
|
||||
};
|
||||
@@ -31,7 +31,7 @@ export function PasswordEditForm({ onSave, onClose }) {
|
||||
return (
|
||||
<Form onSubmit={handleSubmit} error={getErrorMessage(error)}>
|
||||
<FormField
|
||||
label={formatMessage(labels.currentPassword)}
|
||||
label={t(labels.currentPassword)}
|
||||
name="currentPassword"
|
||||
rules={{ required: 'Required' }}
|
||||
>
|
||||
@@ -39,28 +39,28 @@ export function PasswordEditForm({ onSave, onClose }) {
|
||||
</FormField>
|
||||
<FormField
|
||||
name="newPassword"
|
||||
label={formatMessage(labels.newPassword)}
|
||||
label={t(labels.newPassword)}
|
||||
rules={{
|
||||
required: 'Required',
|
||||
minLength: { value: 8, message: formatMessage(messages.minPasswordLength, { n: '8' }) },
|
||||
minLength: { value: 8, message: t(messages.minPasswordLength, { n: '8' }) },
|
||||
}}
|
||||
>
|
||||
<PasswordField autoComplete="new-password" />
|
||||
</FormField>
|
||||
<FormField
|
||||
name="confirmPassword"
|
||||
label={formatMessage(labels.confirmPassword)}
|
||||
label={t(labels.confirmPassword)}
|
||||
rules={{
|
||||
required: formatMessage(labels.required),
|
||||
minLength: { value: 8, message: formatMessage(messages.minPasswordLength, { n: '8' }) },
|
||||
required: t(labels.required),
|
||||
minLength: { value: 8, message: t(messages.minPasswordLength, { n: '8' }) },
|
||||
validate: samePassword,
|
||||
}}
|
||||
>
|
||||
<PasswordField autoComplete="confirm-password" />
|
||||
</FormField>
|
||||
<FormButtons>
|
||||
<Button onPress={onClose}>{formatMessage(labels.cancel)}</Button>
|
||||
<FormSubmitButton isDisabled={isPending}>{formatMessage(labels.save)}</FormSubmitButton>
|
||||
<Button onPress={onClose}>{t(labels.cancel)}</Button>
|
||||
<FormSubmitButton isDisabled={isPending}>{t(labels.save)}</FormSubmitButton>
|
||||
</FormButtons>
|
||||
</Form>
|
||||
);
|
||||
|
||||
@@ -2,7 +2,7 @@ import { SectionHeader } from '@/components/common/SectionHeader';
|
||||
import { useMessages } from '@/components/hooks';
|
||||
|
||||
export function ProfileHeader() {
|
||||
const { formatMessage, labels } = useMessages();
|
||||
const { t, labels } = useMessages();
|
||||
|
||||
return <SectionHeader title={formatMessage(labels.profile)}></SectionHeader>;
|
||||
return <SectionHeader title={t(labels.profile)}></SectionHeader>;
|
||||
}
|
||||
@@ -7,12 +7,12 @@ import { useMessages } from '@/components/hooks';
|
||||
import { ProfileSettings } from './ProfileSettings';
|
||||
|
||||
export function ProfilePage() {
|
||||
const { formatMessage, labels } = useMessages();
|
||||
const { t, labels } = useMessages();
|
||||
|
||||
return (
|
||||
<PageBody>
|
||||
<Column gap="6">
|
||||
<PageHeader title={formatMessage(labels.profile)} />
|
||||
<PageHeader title={t(labels.profile)} />
|
||||
<Panel>
|
||||
<ProfileSettings />
|
||||
</Panel>
|
||||
|
||||
@@ -5,7 +5,7 @@ import { PasswordChangeButton } from './PasswordChangeButton';
|
||||
|
||||
export function ProfileSettings() {
|
||||
const { user } = useLoginQuery();
|
||||
const { formatMessage, labels } = useMessages();
|
||||
const { t, labels } = useMessages();
|
||||
const { cloudMode } = useConfig();
|
||||
|
||||
if (!user) {
|
||||
@@ -16,31 +16,31 @@ export function ProfileSettings() {
|
||||
|
||||
const renderRole = (value: string) => {
|
||||
if (value === ROLES.user) {
|
||||
return formatMessage(labels.user);
|
||||
return t(labels.user);
|
||||
}
|
||||
if (value === ROLES.admin) {
|
||||
return formatMessage(labels.admin);
|
||||
return t(labels.admin);
|
||||
}
|
||||
if (value === ROLES.viewOnly) {
|
||||
return formatMessage(labels.viewOnly);
|
||||
return t(labels.viewOnly);
|
||||
}
|
||||
|
||||
return formatMessage(labels.unknown);
|
||||
return t(labels.unknown);
|
||||
};
|
||||
|
||||
return (
|
||||
<Column gap="6">
|
||||
<Column>
|
||||
<Label>{formatMessage(labels.username)}</Label>
|
||||
<Label>{t(labels.username)}</Label>
|
||||
{username}
|
||||
</Column>
|
||||
<Column>
|
||||
<Label>{formatMessage(labels.role)}</Label>
|
||||
<Label>{t(labels.role)}</Label>
|
||||
{renderRole(role)}
|
||||
</Column>
|
||||
{!cloudMode && (
|
||||
<Column>
|
||||
<Label>{formatMessage(labels.password)}</Label>
|
||||
<Label>{t(labels.password)}</Label>
|
||||
<Row>
|
||||
<PasswordChangeButton />
|
||||
</Row>
|
||||
|
||||
@@ -5,11 +5,11 @@ import { SectionHeader } from '@/components/common/SectionHeader';
|
||||
import { useMessages } from '@/components/hooks';
|
||||
|
||||
export function WebsitesSettingsPage({ teamId }: { teamId: string }) {
|
||||
const { formatMessage, labels } = useMessages();
|
||||
const { t, labels } = useMessages();
|
||||
|
||||
return (
|
||||
<Column gap>
|
||||
<SectionHeader title={formatMessage(labels.websites)} />
|
||||
<SectionHeader title={t(labels.websites)} />
|
||||
<WebsitesDataTable teamId={teamId} />
|
||||
</Column>
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user