Migrate to lingui
Switch to "lingui" for better DX. Tried to persist existing languages as much as possible. Removed "vite-plugin-node-polyfills" because it's incompatible with "lingui"
This commit is contained in:
@@ -6,12 +6,12 @@
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import ListItemButton from '@mui/material/ListItemButton';
|
||||
import Chip from '@mui/material/Chip';
|
||||
import ListItemAvatar from '@mui/material/ListItemAvatar';
|
||||
import ListItemSecondaryAction from '@mui/material/ListItemSecondaryAction';
|
||||
import ListItemText from '@mui/material/ListItemText';
|
||||
import { useLingui } from '@lingui/react/macro';
|
||||
import { makeToast } from '@/base/utils/Toast.ts';
|
||||
import { requestManager } from '@/lib/requests/RequestManager.ts';
|
||||
import { Trackers } from '@/features/tracker/services/Trackers.ts';
|
||||
@@ -21,7 +21,7 @@ import { AvatarSpinner } from '@/base/components/AvatarSpinner.tsx';
|
||||
import { CredentialsLogin } from '@/base/components/modals/LoginDialog.tsx';
|
||||
|
||||
export const SettingsTrackerCard = ({ tracker }: { tracker: TTrackerSearch }) => {
|
||||
const { t } = useTranslation();
|
||||
const { t } = useLingui();
|
||||
|
||||
const isOAuthLogin = !tracker.isLoggedIn && !!tracker.authUrl;
|
||||
|
||||
@@ -29,7 +29,7 @@ export const SettingsTrackerCard = ({ tracker }: { tracker: TTrackerSearch }) =>
|
||||
try {
|
||||
await requestManager.logoutFromTracker(tracker.id).response;
|
||||
} catch (e) {
|
||||
makeToast(t('tracking.action.logout.label.failure', { name: tracker.name }), 'error', getErrorMessage(e));
|
||||
makeToast(t`Could not log out from ${tracker.name}`, 'error', getErrorMessage(e));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -49,7 +49,7 @@ export const SettingsTrackerCard = ({ tracker }: { tracker: TTrackerSearch }) =>
|
||||
try {
|
||||
await requestManager.loginTrackerCredentials(tracker.id, username, password).response;
|
||||
} catch (e) {
|
||||
makeToast(t('tracking.action.login.label.failure', { name: tracker.name }), 'error', getErrorMessage(e));
|
||||
makeToast(t`Could not log in to ${tracker.name}`, 'error', getErrorMessage(e));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -68,12 +68,7 @@ export const SettingsTrackerCard = ({ tracker }: { tracker: TTrackerSearch }) =>
|
||||
|
||||
const controlled = CredentialsLogin.showControlled(
|
||||
{
|
||||
title: t(
|
||||
Trackers.isLoggedIn(tracker)
|
||||
? 'tracking.settings.dialog.title.log_out'
|
||||
: 'tracking.settings.dialog.title.log_in',
|
||||
{ name: tracker.name },
|
||||
),
|
||||
title: Trackers.isLoggedIn(tracker) ? t`Log out from ${tracker.name}` : t`Log in to ${tracker.name}`,
|
||||
isLoading: false,
|
||||
isLoggedIn: Trackers.isLoggedIn(tracker),
|
||||
username: initialUsername,
|
||||
@@ -90,11 +85,7 @@ export const SettingsTrackerCard = ({ tracker }: { tracker: TTrackerSearch }) =>
|
||||
|
||||
controlled.submit();
|
||||
} catch (e) {
|
||||
makeToast(
|
||||
t('tracking.action.logout.label.failure', { name: tracker.name }),
|
||||
'error',
|
||||
getErrorMessage(e),
|
||||
);
|
||||
makeToast(t`Could not log out from ${tracker.name}`, 'error', getErrorMessage(e));
|
||||
}
|
||||
|
||||
return;
|
||||
@@ -105,11 +96,7 @@ export const SettingsTrackerCard = ({ tracker }: { tracker: TTrackerSearch }) =>
|
||||
|
||||
controlled.submit();
|
||||
} catch (e) {
|
||||
makeToast(
|
||||
t('tracking.action.login.label.failure', { name: tracker.name }),
|
||||
'error',
|
||||
getErrorMessage(e),
|
||||
);
|
||||
makeToast(t`Could not log in to ${tracker.name}`, 'error', getErrorMessage(e));
|
||||
|
||||
const RETRY_KEY = '__retry__';
|
||||
const retry = await Promise.race([controlled.promise, Promise.resolve(RETRY_KEY)]);
|
||||
@@ -145,7 +132,7 @@ export const SettingsTrackerCard = ({ tracker }: { tracker: TTrackerSearch }) =>
|
||||
<ListItemText primary={tracker.name} />
|
||||
{Trackers.isLoggedIn(tracker) && (
|
||||
<ListItemSecondaryAction>
|
||||
<Chip label={t('global.label.logged_in')} color="success" />
|
||||
<Chip label={t`Logged in`} color="success" />
|
||||
</ListItemSecondaryAction>
|
||||
)}
|
||||
</ListItemButton>
|
||||
|
||||
Reference in New Issue
Block a user