Skip to content

A local-first personal finance app

[AI] Move i18n usage outside of loot-core (#8027)

Matiss Janis Aboltins7f4a0e7d6b2f
diff --git a/packages/desktop-client/src/app/appSlice.ts b/packages/desktop-client/src/app/appSlice.ts
index 49730cb8bb..23dec32e37 100644
--- a/packages/desktop-client/src/app/appSlice.ts
+++ b/packages/desktop-client/src/app/appSlice.ts
@@ -1,5 +1,4 @@
import { send } from '@actual-app/core/platform/client/connection';
-import { getUploadError } from '@actual-app/core/shared/errors';
import type { AtLeastOne } from '@actual-app/core/types/util';
import { createAction, createSlice } from '@reduxjs/toolkit';
import type { PayloadAction } from '@reduxjs/toolkit';
@@ -7,6 +6,7 @@ import type { PayloadAction } from '@reduxjs/toolkit';
import { pushModal } from '#modals/modalsSlice';
import { loadPrefs } from '#prefs/prefsSlice';
import { createAppAsyncThunk } from '#redux';
+import { getUploadError } from '#util/error';
import { getIsOutdated, getLatestVersion } from '#util/versions';
const sliceName = 'app';
diff --git a/packages/desktop-client/src/budgetfiles/budgetfilesSlice.ts b/packages/desktop-client/src/budgetfiles/budgetfilesSlice.ts
index 42c73131ea..f52dea15b0 100644
--- a/packages/desktop-client/src/budgetfiles/budgetfilesSlice.ts
+++ b/packages/desktop-client/src/budgetfiles/budgetfilesSlice.ts
@@ -1,6 +1,5 @@
import { send } from '@actual-app/core/platform/client/connection';
import type { RemoteFile } from '@actual-app/core/server/cloud-storage';
-import { getDownloadError, getSyncError } from '@actual-app/core/shared/errors';
import type { Budget } from '@actual-app/core/types/budget';
import type { File } from '@actual-app/core/types/file';
import type { Handlers } from '@actual-app/core/types/handlers';
@@ -13,6 +12,7 @@ import { closeModal, pushModal } from '#modals/modalsSlice';
import { loadGlobalPrefs, loadPrefs } from '#prefs/prefsSlice';
import { createAppAsyncThunk } from '#redux';
import { signOut } from '#users/usersSlice';
+import { getDownloadError, getSyncError } from '#util/error';
const sliceName = 'budgetfiles';
diff --git a/packages/desktop-client/src/components/ManageRules.tsx b/packages/desktop-client/src/components/ManageRules.tsx
index 1bbbf56f0a..aa3cb4f31a 100644
--- a/packages/desktop-client/src/components/ManageRules.tsx
+++ b/packages/desktop-client/src/components/ManageRules.tsx
@@ -13,8 +13,6 @@ import { send } from '@actual-app/core/platform/client/connection';
import * as undo from '@actual-app/core/platform/client/undo';
import { getNormalisedString } from '@actual-app/core/shared/normalisation';
import { q } from '@actual-app/core/shared/query';
-import { friendlyOp, mapField } from '@actual-app/core/shared/rules';
-import { describeSchedule } from '@actual-app/core/shared/schedules';
import type {
NewRuleEntity,
RuleEntity,
@@ -28,6 +26,8 @@ import { useSchedules } from '#hooks/useSchedules';
import { SelectedProvider, useSelected } from '#hooks/useSelected';
import { pushModal } from '#modals/modalsSlice';
import { useDispatch } from '#redux';
+import { friendlyOp, mapField } from '#util/rule';
+import { describeSchedule } from '#util/schedule';
import { InfiniteScrollWrapper } from './common/InfiniteScrollWrapper';
import { Link } from './common/Link';
diff --git a/packages/desktop-client/src/components/admin/UserAccess/UserAccessRow.tsx b/packages/desktop-client/src/components/admin/UserAccess/UserAccessRow.tsx
index 732b53da34..3b2da18eef 100644
--- a/packages/desktop-client/src/components/admin/UserAccess/UserAccessRow.tsx
+++ b/packages/desktop-client/src/components/admin/UserAccess/UserAccessRow.tsx
@@ -5,7 +5,6 @@ import { useTranslation } from 'react-i18next';
import { theme } from '@actual-app/components/theme';
import { View } from '@actual-app/components/view';
import { send } from '@actual-app/core/platform/client/connection';
-import { getUserAccessErrors } from '@actual-app/core/shared/errors';
import type { UserAvailable } from '@actual-app/core/types/models';
import { Checkbox } from '#components/forms';
@@ -14,6 +13,7 @@ import { useMetadataPref } from '#hooks/useMetadataPref';
import { addNotification } from '#notifications/notificationsSlice';
import { useDispatch } from '#redux';
import { signOut } from '#users/usersSlice';
+import { getUserAccessErrors } from '#util/error';
type UserAccessProps = {
access: UserAvailable;
diff --git a/packages/desktop-client/src/components/banksync/AccountRow.tsx b/packages/desktop-client/src/components/banksync/AccountRow.tsx
index 8d5c7eb62f..1a5bfc5446 100644
--- a/packages/desktop-client/src/components/banksync/AccountRow.tsx
+++ b/packages/desktop-client/src/components/banksync/AccountRow.tsx
@@ -1,5 +1,5 @@
import React, { memo } from 'react';
-import { Trans } from 'react-i18next';
+import { Trans, useTranslation } from 'react-i18next';
import { Button } from '@actual-app/components/button';
import { styles } from '@actual-app/components/styles';
@@ -22,8 +22,14 @@ type AccountRowProps = {
export const AccountRow = memo(
({ account, hovered, onHover, onAction, locale }: AccountRowProps) => {
+ const { t } = useTranslation();
const backgroundFocus = hovered;
+ // The bank name is stored as null when the sync provider doesn't report an
+ // institution; show a localized fallback for linked accounts.
+ const bankName =
+ account.bank && !account.bankName ? t('Unknown') : account.bankName;
+
const lastSyncString = tsToRelativeTime(account.last_sync, locale, {
capitalize: true,
});
@@ -66,7 +72,7 @@ export const AccountRow = memo(
plain
style={{ color: theme.tableText, padding: '10px' }}
>
- {account.bankName}
+ {bankName}
</Cell>
{account.account_sync_source ? (
diff --git a/packages/desktop-client/src/components/filters/FilterExpression.tsx b/packages/desktop-client/src/components/filters/FilterExpression.tsx
index c1abffbe87..205490021e 100644
--- a/packages/desktop-client/src/components/filters/FilterExpression.tsx
+++ b/packages/desktop-client/src/components/filters/FilterExpression.tsx
@@ -8,10 +8,10 @@ import { Popover } from '@actual-app/components/popover';
import { Text } from '@actual-app/components/text';
import { theme } from '@actual-app/components/theme';
import { View } from '@actual-app/components/view';
-import { friendlyOp, mapField } from '@actual-app/core/shared/rules';
import type { RuleConditionEntity } from '@actual-app/core/types/models';
import { Value } from '#components/rules/Value';
+import { friendlyOp, mapField } from '#util/rule';
import { FilterEditor } from './FiltersMenu';
import { subfieldFromFilter } from './subfieldFromFilter';
diff --git a/packages/desktop-client/src/components/filters/FiltersMenu.tsx b/packages/desktop-client/src/components/filters/FiltersMenu.tsx
index 949cb47c7c..e8c511ad08 100644
--- a/packages/desktop-client/src/components/filters/FiltersMenu.tsx
+++ b/packages/desktop-client/src/components/filters/FiltersMenu.tsx
@@ -22,7 +22,6 @@ import {
FIELD_TYPES,
getFieldError,
getValidOps,
- mapField,
unparse,
} from '@actual-app/core/shared/rules';
import { titleFirst } from '@actual-app/core/shared/util';
@@ -42,6 +41,7 @@ import { useDateFormat } from '#hooks/useDateFormat';
import { useFormat } from '#hooks/useFormat';
import { usePayees } from '#hooks/usePayees';
import { useTransactionFilters } from '#hooks/useTransactionFilters';
+import { mapField } from '#util/rule';
import { CompactFiltersButton } from './CompactFiltersButton';
import { FiltersButton } from './FiltersButton';
diff --git a/packages/desktop-client/src/components/filters/OpButton.tsx b/packages/desktop-client/src/components/filters/OpButton.tsx
index 5ade69f64d..7bf95b0b2d 100644
--- a/packages/desktop-client/src/components/filters/OpButton.tsx
+++ b/packages/desktop-client/src/components/filters/OpButton.tsx
@@ -3,9 +3,10 @@ import type { CSSProperties } from 'react';
import { Button } from '@actual-app/components/button';
import { theme } from '@actual-app/components/theme';
-import { friendlyOp } from '@actual-app/core/shared/rules';
import { css } from '@emotion/css';
+import { friendlyOp } from '#util/rule';
+
type OpButtonProps = {
op: string;
isSelected: boolean;
diff --git a/packages/desktop-client/src/components/mobile/banksync/BankSyncAccountsListItem.tsx b/packages/desktop-client/src/components/mobile/banksync/BankSyncAccountsListItem.tsx
index eb5d3ac0dd..37898369bf 100644
--- a/packages/desktop-client/src/components/mobile/banksync/BankSyncAccountsListItem.tsx
+++ b/packages/desktop-client/src/components/mobile/banksync/BankSyncAccountsListItem.tsx
@@ -1,4 +1,4 @@
-import { Trans } from 'react-i18next';
+import { Trans, useTranslation } from 'react-i18next';
import { SpaceBetween } from '@actual-app/components/space-between';
import { Text } from '@actual-app/components/text';
@@ -20,6 +20,7 @@ export function BankSyncAccountsListItem({
onAction,
isLinked,
}: BankSyncAccountsListItemProps) {
+ const { t } = useTranslation();
const locale = useLocale();
const lastSyncString = isLinked
@@ -57,14 +58,14 @@ export function BankSyncAccountsListItem({
>
{account.name}
</Text>
- {isLinked && account.bankName && (
+ {isLinked && (
<Text
style={{
fontSize: 13,
color: theme.pageTextSubdued,
}}
>
- {account.bankName}
+ {account.bankName ?? t('Unknown')}
</Text>
)}
{isLinked && lastSyncString && (
diff --git a/packages/desktop-client/src/components/mobile/rules/RulesListItem.tsx b/packages/desktop-client/src/components/mobile/rules/RulesListItem.tsx
index 7c830447b8..247a0c7c6b 100644
--- a/packages/desktop-client/src/components/mobile/rules/RulesListItem.tsx
+++ b/packages/desktop-client/src/components/mobile/rules/RulesListItem.tsx
@@ -13,7 +13,7 @@ import type { WithRequired } from '@actual-app/core/types/util';
import { ActionableGridListItem } from '#components/mobile/ActionableGridListItem';
import { ActionExpression } from '#components/rules/ActionExpression';
import { ConditionExpression } from '#components/rules/ConditionExpression';
-import { groupActionsBySplitIndex } from '#util/ruleUtils';
+import { groupActionsBySplitIndex } from '#util/rule';
type RulesListItemProps = {
onDelete: () => void;
diff --git a/packages/desktop-client/src/components/mobile/transactions/TransactionEdit.tsx b/packages/desktop-client/src/components/mobile/transactions/TransactionEdit.tsx
index bc6c0a1276..4e85947d76 100644
--- a/packages/desktop-client/src/components/mobile/transactions/TransactionEdit.tsx
+++ b/packages/desktop-client/src/components/mobile/transactions/TransactionEdit.tsx
@@ -39,10 +39,7 @@ import { calculateDistance } from '@actual-app/core/shared/location-utils';
import * as monthUtils from '@actual-app/core/shared/months';
import * as Platform from '@actual-app/core/shared/platform';
import { q } from '@actual-app/core/shared/query';
-import {
- getStatusLabel,
- getUpcomingDays,
-} from '@actual-app/core/shared/schedules';
+import { getUpcomingDays } from '@actual-app/core/shared/schedules';
import {
addSplitTransaction,
deleteTransaction,
@@ -113,6 +110,7 @@ import { locationService } from '#payees/location';
import { aqlQuery } from '#queries/aqlQuery';
import { useDispatch, useSelector } from '#redux';
import { setLastTransaction } from '#transactions/transactionsSlice';
+import { getStatusLabel } from '#util/schedule';
import { FocusableAmountInput } from './FocusableAmountInput';
diff --git a/packages/desktop-client/src/components/modals/CreateEncryptionKeyModal.tsx b/packages/desktop-client/src/components/modals/CreateEncryptionKeyModal.tsx
index 84e60915d7..17560f4c54 100644
--- a/packages/desktop-client/src/components/modals/CreateEncryptionKeyModal.tsx
+++ b/packages/desktop-client/src/components/modals/CreateEncryptionKeyModal.tsx
@@ -13,7 +13,6 @@ import { Text } from '@actual-app/components/text';
import { theme } from '@actual-app/components/theme';
import { View } from '@actual-app/components/view';
import { send } from '@actual-app/core/platform/client/connection';
-import { getCreateKeyError } from '@actual-app/core/shared/errors';
import { css } from '@emotion/css';
import { sync } from '#app/appSlice';
@@ -28,6 +27,7 @@ import {
import type { Modal as ModalType } from '#modals/modalsSlice';
import { loadGlobalPrefs } from '#prefs/prefsSlice';
import { useDispatch } from '#redux';
+import { getCreateKeyError } from '#util/error';
type CreateEncryptionKeyModalProps = Extract<
ModalType,
diff --git a/packages/desktop-client/src/components/modals/EditAccess.tsx b/packages/desktop-client/src/components/modals/EditAccess.tsx
index 5f17e88853..ecb275d05d 100644
--- a/packages/desktop-client/src/components/modals/EditAccess.tsx
+++ b/packages/desktop-client/src/components/modals/EditAccess.tsx
@@ -9,7 +9,6 @@ import { Text } from '@actual-app/components/text';
import { theme } from '@actual-app/components/theme';
import { View } from '@actual-app/components/view';
import { send } from '@actual-app/core/platform/client/connection';
-import { getUserAccessErrors } from '@actual-app/core/shared/errors';
import { Modal, ModalCloseButton, ModalHeader } from '#components/common/Modal';
import { FormField, FormLabel } from '#components/forms';
@@ -18,6 +17,7 @@ import type { Modal as ModalType } from '#modals/modalsSlice';
import { addNotification } from '#notifications/notificationsSlice';
import { useDispatch } from '#redux';
import { signOut } from '#users/usersSlice';
+import { getUserAccessErrors } from '#util/error';
type EditUserAccessProps = Extract<
ModalType,
diff --git a/packages/desktop-client/src/components/modals/EnableBankingInitialiseModal.tsx b/packages/desktop-client/src/components/modals/EnableBankingInitialiseModal.tsx
index 2bf6d9d7d3..951395b3da 100644
--- a/packages/desktop-client/src/components/modals/EnableBankingInitialiseModal.tsx
+++ b/packages/desktop-client/src/components/modals/EnableBankingInitialiseModal.tsx
@@ -10,7 +10,6 @@ import { Text } from '@actual-app/components/text';
import { theme } from '@actual-app/components/theme';
import { View } from '@actual-app/components/view';
import { send } from '@actual-app/core/platform/client/connection';
-import { getSecretsError } from '@actual-app/core/shared/errors';
import { Error as ErrorAlert } from '#components/alerts';
import { Link } from '#components/common/Link';
@@ -22,6 +21,7 @@ import {
} from '#components/common/Modal';
import { FormField, FormLabel } from '#components/forms';
import type { Modal as ModalType } from '#modals/modalsSlice';
+import { getSecretsError } from '#util/error';
type EnableBankingInitialiseProps = Extract<
ModalType,
diff --git a/packages/desktop-client/src/components/modals/FixEncryptionKeyModal.tsx b/packages/desktop-client/src/components/modals/FixEncryptionKeyModal.tsx
index e2bb2e8293..11b0182b06 100644
--- a/packages/desktop-client/src/components/modals/FixEncryptionKeyModal.tsx
+++ b/packages/desktop-client/src/components/modals/FixEncryptionKeyModal.tsx
@@ -13,7 +13,6 @@ import { Text } from '@actual-app/components/text';
import { theme } from '@actual-app/components/theme';
import { View } from '@actual-app/components/view';
import { send } from '@actual-app/core/platform/client/connection';
-import { getTestKeyError } from '@actual-app/core/shared/errors';
import { Link } from '#components/common/Link';
import {
@@ -23,6 +22,7 @@ import {
ModalHeader,
} from '#components/common/Modal';
import type { Modal as ModalType } from '#modals/modalsSlice';
+import { getTestKeyError } from '#util/error';
type FixEncryptionKeyModalProps = Extract<
ModalType,
diff --git a/packages/desktop-client/src/components/modals/GoCardlessInitialiseModal.tsx b/packages/desktop-client/src/components/modals/GoCardlessInitialiseModal.tsx
index 25f6f156e7..62c34ae77a 100644
--- a/packages/desktop-client/src/components/modals/GoCardlessInitialiseModal.tsx
+++ b/packages/desktop-client/src/components/modals/GoCardlessInitialiseModal.tsx
@@ -8,7 +8,6 @@ import { Input } from '@actual-app/components/input';
import { Text } from '@actual-app/components/text';
import { View } from '@actual-app/components/view';
import { send } from '@actual-app/core/platform/client/connection';
-import { getSecretsError } from '@actual-app/core/shared/errors';
import { Error } from '#components/alerts';
import { Link } from '#components/common/Link';
@@ -20,6 +19,7 @@ import {
} from '#components/common/Modal';
import { FormField, FormLabel } from '#components/forms';
import type { Modal as ModalType } from '#modals/modalsSlice';
+import { getSecretsError } from '#util/error';
type GoCardlessInitialiseModalProps = Extract<
ModalType,
diff --git a/packages/desktop-client/src/components/modals/OpenIDEnableModal.tsx b/packages/desktop-client/src/components/modals/OpenIDEnableModal.tsx
index e914ad82d6..76abd292b3 100644
--- a/packages/desktop-client/src/components/modals/OpenIDEnableModal.tsx
+++ b/packages/desktop-client/src/components/modals/OpenIDEnableModal.tsx
@@ -8,7 +8,6 @@ import { theme } from '@actual-app/components/theme';
import { View } from '@actual-app/components/view';
import { send } from '@actual-app/core/platform/client/connection';
import * as asyncStorage from '@actual-app/core/platform/server/asyncStorage';
-import { getOpenIdErrors } from '@actual-app/core/shared/errors';
import type { OpenIdConfig } from '@actual-app/core/types/models';
import { closeBudget } from '#budgetfiles/budgetfilesSlice';
@@ -19,6 +18,7 @@ import { useRefreshLoginMethods } from '#components/ServerContext';
import { popModal } from '#modals/modalsSlice';
import type { Modal as ModalType } from '#modals/modalsSlice';
import { useDispatch } from '#redux';
+import { getOpenIdErrors } from '#util/error';
type OpenIDEnableModalProps = Extract<
ModalType,
diff --git a/packages/desktop-client/src/components/modals/PluggyAiInitialiseModal.tsx b/packages/desktop-client/src/components/modals/PluggyAiInitialiseModal.tsx
index 2feb99df92..bcc679a937 100644
--- a/packages/desktop-client/src/components/modals/PluggyAiInitialiseModal.tsx
+++ b/packages/desktop-client/src/components/modals/PluggyAiInitialiseModal.tsx
@@ -8,7 +8,6 @@ import { Input } from '@actual-app/components/input';
import { Text } from '@actual-app/components/text';
import { View } from '@actual-app/components/view';
import { send } from '@actual-app/core/platform/client/connection';
-import { getSecretsError } from '@actual-app/core/shared/errors';
import { Error } from '#components/alerts';
import { Link } from '#components/common/Link';
@@ -20,6 +19,7 @@ import {
} from '#components/common/Modal';
import { FormField, FormLabel } from '#components/forms';
import type { Modal as ModalType } from '#modals/modalsSlice';
+import { getSecretsError } from '#util/error';
type PluggyAiInitialiseProps = Extract<
ModalType,
diff --git a/packages/desktop-client/src/components/modals/SimpleFinInitialiseModal.tsx b/packages/desktop-client/src/components/modals/SimpleFinInitialiseModal.tsx
index 7d333f9f3d..6ab3a4efba 100644
--- a/packages/desktop-client/src/components/modals/SimpleFinInitialiseModal.tsx
+++ b/packages/desktop-client/src/components/modals/SimpleFinInitialiseModal.tsx
@@ -7,7 +7,6 @@ import { Input } from '@actual-app/components/input';
import { Text } from '@actual-app/components/text';
import { View } from '@actual-app/components/view';
import { send } from '@actual-app/core/platform/client/connection';
-import { getSecretsError } from '@actual-app/core/shared/errors';
import { Error } from '#components/alerts';
import { Link } from '#components/common/Link';
@@ -19,6 +18,7 @@ import {
} from '#components/common/Modal';
import { FormField, FormLabel } from '#components/forms';
import type { Modal as ModalType } from '#modals/modalsSlice';
+import { getSecretsError } from '#util/error';
type SimpleFinInitialiseModalProps = Extract<
ModalType,
diff --git a/packages/desktop-client/src/components/modals/TransferOwnership.tsx b/packages/desktop-client/src/components/modals/TransferOwnership.tsx
index 8cdd856a0c..01746365f8 100644
--- a/packages/desktop-client/src/components/modals/TransferOwnership.tsx
+++ b/packages/desktop-client/src/components/modals/TransferOwnership.tsx
@@ -9,7 +9,6 @@ import { Text } from '@actual-app/components/text';
import { theme } from '@actual-app/components/theme';
import { View } from '@actual-app/components/view';
import { send } from '@actual-app/core/platform/client/connection';
-import { getUserAccessErrors } from '@actual-app/core/shared/errors';
import type { Budget } from '@actual-app/core/types/budget';
import type { RemoteFile, SyncedLocalFile } from '@actual-app/core/types/file';
import type { Handlers } from '@actual-app/core/types/handlers';
@@ -22,6 +21,7 @@ import { popModal } from '#modals/modalsSlice';
import type { Modal as ModalType } from '#modals/modalsSlice';
import { addNotification } from '#notifications/notificationsSlice';
import { useDispatch, useSelector } from '#redux';
+import { getUserAccessErrors } from '#util/error';
type TransferOwnershipProps = Extract<
ModalType,
diff --git a/packages/desktop-client/src/components/reports/reports/Sankey.tsx b/packages/desktop-client/src/components/reports/reports/Sankey.tsx
index a1c75b3e5f..300d6853b5 100644
--- a/packages/desktop-client/src/components/reports/reports/Sankey.tsx
+++ b/packages/desktop-client/src/components/reports/reports/Sankey.tsx
@@ -20,7 +20,6 @@ import { theme } from '@actual-app/components/theme';
import { View } from '@actual-app/components/view';
import { send } from '@actual-app/core/platform/client/connection';
import * as monthUtils from '@actual-app/core/shared/months';
-import { mapField } from '@actual-app/core/shared/rules';
import type {
RuleConditionEntity,
SankeyWidget,
@@ -58,6 +57,7 @@ import { useRuleConditionFilters } from '#hooks/useRuleConditionFilters';
import { addNotification } from '#notifications/notificationsSlice';
import { useDispatch } from '#redux';
import { useUpdateDashboardWidgetMutation } from '#reports/mutations';
+import { mapField } from '#util/rule';
export function Sankey() {
const params = useParams();
diff --git a/packages/desktop-client/src/components/rules/ActionExpression.tsx b/packages/desktop-client/src/components/rules/ActionExpression.tsx
index 648f5094ba..f95fa8a558 100644
--- a/packages/desktop-client/src/components/rules/ActionExpression.tsx
+++ b/packages/desktop-client/src/components/rules/ActionExpression.tsx
@@ -5,11 +5,6 @@ import { useTranslation } from 'react-i18next';
import { Text } from '@actual-app/components/text';
import { theme } from '@actual-app/components/theme';
import { View } from '@actual-app/components/view';
-import {
- friendlyOp,
- getAllocationMethods,
- mapField,
-} from '@actual-app/core/shared/rules';
import type {
AppendNoteRuleActionEntity,
DeleteTransactionRuleActionEntity,
@@ -20,6 +15,8 @@ import type {
SetSplitAmountRuleActionEntity,
} from '@actual-app/core/types/models';
+import { friendlyOp, getAllocationMethods, mapField } from '#util/rule';
+
import { ScheduleValue } from './ScheduleValue';
import { Value } from './Value';
diff --git a/packages/desktop-client/src/components/rules/ConditionExpression.tsx b/packages/desktop-client/src/components/rules/ConditionExpression.tsx
index 0b054543b4..62798ebb3a 100644
--- a/packages/desktop-client/src/components/rules/ConditionExpression.tsx
+++ b/packages/desktop-client/src/components/rules/ConditionExpression.tsx
@@ -4,7 +4,8 @@ import type { CSSProperties } from 'react';
import { Text } from '@actual-app/components/text';
import { theme } from '@actual-app/components/theme';
import { View } from '@actual-app/components/view';
-import { friendlyOp, mapField } from '@actual-app/core/shared/rules';
+
+import { friendlyOp, mapField } from '#util/rule';
import { Value } from './Value';
diff --git a/packages/desktop-client/src/components/rules/RuleEditor.tsx b/packages/desktop-client/src/components/rules/RuleEditor.tsx
index aa1c369ad9..77bdc7ed1e 100644
--- a/packages/desktop-client/src/components/rules/RuleEditor.tsx
+++ b/packages/desktop-client/src/components/rules/RuleEditor.tsx
@@ -27,13 +27,10 @@ import * as monthUtils from '@actual-app/core/shared/months';
import { q } from '@actual-app/core/shared/query';
import {
FIELD_TYPES,
- friendlyOp,
- getAllocationMethods,
getFieldError,
getValidOps,
isValidOp,
makeValue,
- mapField,
parse,
unparse,
} from '@actual-app/core/shared/rules';
@@ -62,6 +59,7 @@ import { addNotification } from '#notifications/notificationsSlice';
import { aqlQuery } from '#queries/aqlQuery';
import { useDispatch } from '#redux';
import { disableUndo, enableUndo } from '#undo';
+import { friendlyOp, getAllocationMethods, mapField } from '#util/rule';
import { FormulaActionEditor } from './FormulaActionEditor';
diff --git a/packages/desktop-client/src/components/rules/RuleRow.tsx b/packages/desktop-client/src/components/rules/RuleRow.tsx
index 59fa363805..0484b2f6a6 100644
--- a/packages/desktop-client/src/components/rules/RuleRow.tsx
+++ b/packages/desktop-client/src/components/rules/RuleRow.tsx
@@ -11,13 +11,16 @@ import { styles } from '@actual-app/components/styles';
import { Text } from '@actual-app/components/text';
import { theme } from '@actual-app/components/theme';
import { View } from '@actual-app/components/view';
-import { friendlyOp, translateRuleStage } from '@actual-app/core/shared/rules';
import type { RuleEntity } from '@actual-app/core/types/models';
import { Cell, Field, Row, SelectCell } from '#components/table';
import { useContextMenu } from '#hooks/useContextMenu';
import { useSelectedDispatch } from '#hooks/useSelected';
-import { groupActionsBySplitIndex } from '#util/ruleUtils';
+import {
+ friendlyOp,
+ groupActionsBySplitIndex,
+ translateRuleStage,
+} from '#util/rule';
import { ActionExpression } from './ActionExpression';
import { ConditionExpression } from './ConditionExpression';
diff --git a/packages/desktop-client/src/components/rules/ScheduleValue.tsx b/packages/desktop-client/src/components/rules/ScheduleValue.tsx
index 21cb6692b6..84ff3313c7 100644
--- a/packages/desktop-client/src/components/rules/ScheduleValue.tsx
+++ b/packages/desktop-client/src/components/rules/ScheduleValue.tsx
@@ -4,11 +4,11 @@ import { useTranslation } from 'react-i18next';
import { AnimatedLoading } from '@actual-app/components/icons/AnimatedLoading';
import { View } from '@actual-app/components/view';
import { q } from '@actual-app/core/shared/query';
-import { describeSchedule } from '@actual-app/core/shared/schedules';
import type { ScheduleEntity } from '@actual-app/core/types/models';
import { usePayeesById } from '#hooks/usePayees';
import { useSchedules } from '#hooks/useSchedules';
+import { describeSchedule } from '#util/schedule';
import { Value } from './Value';
diff --git a/packages/desktop-client/src/components/rules/Value.tsx b/packages/desktop-client/src/components/rules/Value.tsx
index 9c4fd81bf4..90a4342e44 100644
--- a/packages/desktop-client/src/components/rules/Value.tsx
+++ b/packages/desktop-client/src/components/rules/Value.tsx
@@ -6,7 +6,6 @@ import { useTranslation } from 'react-i18next';
import { Text } from '@actual-app/components/text';
import { theme } from '@actual-app/components/theme';
import { getMonthYearFormat } from '@actual-app/core/shared/months';
-import { getRecurringDescription } from '@actual-app/core/shared/schedules';
import { format as formatDate, parseISO } from 'date-fns';
import { Link } from '#components/common/Link';
@@ -17,6 +16,7 @@ import { useDateFormat } from '#hooks/useDateFormat';
import { useFormat } from '#hooks/useFormat';
import { useLocale } from '#hooks/useLocale';
import { usePayees } from '#hooks/usePayees';
+import { getRecurringDescription } from '#util/schedule';
type ValueProps<T> = {
value: T;
diff --git a/packages/desktop-client/src/components/schedules/DiscoverSchedules.tsx b/packages/desktop-client/src/components/schedules/DiscoverSchedules.tsx
index b4023c59a1..924dcdff1d 100644
--- a/packages/desktop-client/src/components/schedules/DiscoverSchedules.tsx
+++ b/packages/desktop-client/src/components/schedules/DiscoverSchedules.tsx
@@ -10,7 +10,6 @@ import { theme } from '@actual-app/components/theme';
import { View } from '@actual-app/components/view';
import { send } from '@actual-app/core/platform/client/connection';
import { q } from '@actual-app/core/shared/query';
-import { getRecurringDescription } from '@actual-app/core/shared/schedules';
import type { DiscoverScheduleEntity } from '@actual-app/core/types/models';
import { Modal, ModalCloseButton, ModalHeader } from '#components/common/Modal';
@@ -26,6 +25,7 @@ import {
} from '#hooks/useSelected';
import { useSendPlatformRequest } from '#hooks/useSendPlatformRequest';
import { aqlQuery } from '#queries/aqlQuery';
+import { getRecurringDescription } from '#util/schedule';
import { ScheduleAmountCell } from './SchedulesTable';
diff --git a/packages/desktop-client/src/components/schedules/StatusBadge.tsx b/packages/desktop-client/src/components/schedules/StatusBadge.tsx
index 25f5a8e51f..4d4af14661 100644
--- a/packages/desktop-client/src/components/schedules/StatusBadge.tsx
+++ b/packages/desktop-client/src/components/schedules/StatusBadge.tsx
@@ -13,10 +13,11 @@ import {
import { Text } from '@actual-app/components/text';
import { theme } from '@actual-app/components/theme';
import { View } from '@actual-app/components/view';
-import { getStatusLabel } from '@actual-app/core/shared/schedules';
import type { ScheduleStatusType } from '@actual-app/core/shared/schedules';
import { titleFirst } from '@actual-app/core/shared/util';
+import { getStatusLabel } from '#util/schedule';
+
// Consists of Schedule Statuses + Transaction statuses
export type StatusTypes =
| ScheduleStatusType
diff --git a/packages/desktop-client/src/components/select/RecurringSchedulePicker.tsx b/packages/desktop-client/src/components/select/RecurringSchedulePicker.tsx
index 4e8231ed7b..37cd1ed9a0 100644
--- a/packages/desktop-client/src/components/select/RecurringSchedulePicker.tsx
+++ b/packages/desktop-client/src/components/select/RecurringSchedulePicker.tsx
@@ -16,7 +16,6 @@ import { theme } from '@actual-app/components/theme';
import { View } from '@actual-app/components/view';
import { sendCatch } from '@actual-app/core/platform/client/connection';
import * as monthUtils from '@actual-app/core/shared/months';
-import { getRecurringDescription } from '@actual-app/core/shared/schedules';
import type { RecurConfig, RecurPattern } from '@actual-app/core/types/models';
import type {
TransObjectLiteral,
@@ -27,6 +26,7 @@ import { Modal } from '#components/common/Modal';
import { Checkbox } from '#components/forms';
import { useDateFormat } from '#hooks/useDateFormat';
import { useLocale } from '#hooks/useLocale';
+import { getRecurringDescription } from '#util/schedule';
import { DateSelect } from './DateSelect';
diff --git a/packages/desktop-client/src/components/transactions/TransactionsTable.tsx b/packages/desktop-client/src/components/transactions/TransactionsTable.tsx
index 42a688b14c..84e7eeb278 100644
--- a/packages/desktop-client/src/components/transactions/TransactionsTable.tsx
+++ b/packages/desktop-client/src/components/transactions/TransactionsTable.tsx
@@ -47,7 +47,6 @@ import { Tooltip } from '@actual-app/components/tooltip';
import { View } from '@actual-app/components/view';
import * as monthUtils from '@actual-app/core/shared/months';
import { q } from '@actual-app/core/shared/query';
-import { getStatusLabel } from '@actual-app/core/shared/schedules';
import {
addSplitTransaction,
deleteTransaction,
@@ -134,6 +133,7 @@ import { addNotification } from '#notifications/notificationsSlice';
import { getPayeesById } from '#payees';
import { aqlQuery } from '#queries/aqlQuery';
import { useDispatch } from '#redux';
+import { getStatusLabel } from '#util/schedule';
import {
deserializeTransaction,
diff --git a/packages/desktop-client/src/global-events.ts b/packages/desktop-client/src/global-events.ts
index cda472f1c2..818991f373 100644
--- a/packages/desktop-client/src/global-events.ts
+++ b/packages/desktop-client/src/global-events.ts
@@ -2,6 +2,7 @@ import { listen } from '@actual-app/core/platform/client/connection';
import * as undo from '@actual-app/core/platform/client/undo';
// @ts-strict-ignore
import type { QueryClient } from '@tanstack/react-query';
+import { t } from 'i18next';
import { accountQueries } from './accounts';
import { setAppState } from './app/appSlice';
@@ -139,6 +140,14 @@ export function handleGlobalEvents(store: AppStore, queryClient: QueryClient) {
);
});
+ const unlistenIndexeddbQuotaError = listen('indexeddb-quota-error', () => {
+ alert(
+ t(
+ 'We hit a limit on the local storage available. Edits may not be saved. Please get in touch https://actualbudget.org/contact/ so we can help debug this.',
+ ),
+ );
+ });
+
const unlistenStartLoad = listen('start-load', () => {
void store.dispatch(closeBudgetUI());
store.dispatch(setAppState({ loadingText: '' }));
@@ -176,6 +185,7 @@ export function handleGlobalEvents(store: AppStore, queryClient: QueryClient) {
unlistenSync();
unlistenUndo();
unlistenFallbackWriteError();
+ unlistenIndexeddbQuotaError();
unlistenStartLoad();
unlistenFinishLoad();
unlistenStartImport();
diff --git a/packages/desktop-client/src/hooks/useSchedules.ts b/packages/desktop-client/src/hooks/useSchedules.ts
index a842884ffd..6b6d1089d4 100644
--- a/packages/desktop-client/src/hooks/useSchedules.ts
+++ b/packages/desktop-client/src/hooks/useSchedules.ts
@@ -5,7 +5,6 @@ import type { Query } from '@actual-app/core/shared/query';
import {
getHasTransactionsQuery,
getStatus,
- getStatusLabel,
} from '@actual-app/core/shared/schedules';
import type { ScheduleStatuses } from '@actual-app/core/shared/schedules';
import type {
@@ -17,6 +16,7 @@ import type {
import { accountFilter } from '#queries';
import { liveQuery } from '#queries/liveQuery';
import type { LiveQuery } from '#queries/liveQuery';
+import { getStatusLabel } from '#util/schedule';
import { useSyncedPref } from './useSyncedPref';
diff --git a/packages/desktop-client/src/util/error.ts b/packages/desktop-client/src/util/error.ts
new file mode 100644
index 0000000000..53afcd7fe7
--- /dev/null
+++ b/packages/desktop-client/src/util/error.ts
@@ -0,0 +1,212 @@
+import { t } from 'i18next';
+
+type ErrorWithMeta = {
+ reason: string;
+ meta?: unknown;
+};
+
+export function getUploadError({ reason, meta }: ErrorWithMeta) {
+ switch (reason) {
+ case 'unauthorized':
+ return t('You are not logged in.');
+ case 'encrypt-failure':
+ if (
+ meta != null &&
+ typeof meta === 'object' &&
+ 'isMissingKey' in meta &&
+ meta.isMissingKey
+ ) {
+ return t(
+ 'Encrypting your file failed because you are missing your encryption key. Create your key in the next step.',
+ );
+ }
+ return t(
+ 'Encrypting the file failed. You have the correct key so this is an internal bug. To fix this, generate a new key in the next step.',
+ );
+ case 'file-has-reset':
+ // Something really weird happened - during reset a sanity
+ // check on the server failed. The user just needs to
+ // restart the whole process.
+ return t(
+ 'Something went wrong while resetting your file. Please try again.',
+ );
+ case 'file-has-new-key':
+ return t(
+ 'Unable to encrypt your data because you are missing the key. Create the latest key in the next step.',
+ );
+ case 'network':
+ return t('Uploading the file failed. Check your network connection.');
+ default:
+ return t(
+ 'An internal error occurred, sorry! Visit https://actualbudget.org/contact/ for support. (ref: {{reason}})',
+ { reason },
+ );
+ }
+}
+
+function isDatabaseSchemaMismatch(meta?: unknown): boolean {
+ if (
+ meta &&
+ typeof meta === 'object' &&
+ 'error' in meta &&
+ meta.error &&
+ typeof meta.error === 'object' &&
+ 'message' in meta.error &&
+ typeof meta.error.message === 'string'
+ ) {
+ return /no such (column|table)/i.test(meta.error.message);
+ }
+ return false;
+}
+
+function getSchemaMismatchError() {
+ return t(
+ 'This budget could not be loaded because it uses a newer database schema than this version of Actual supports. Make sure you are using the latest version, then try again.',
+ );
+}
+
+export function getDownloadError({
+ reason,
+ meta,
+ fileName,
+}: {
+ reason: string;
+ meta?: unknown;
+ fileName?: string;
+}) {
+ if (reason === 'invalid-schema' && isDatabaseSchemaMismatch(meta)) {
+ return getSchemaMismatchError();
+ }
+
+ switch (reason) {
+ case 'network':
+ case 'download-failure':
+ return t('Downloading the file failed. Check your network connection.');
+ case 'not-zip-file':
+ case 'invalid-zip-file':
+ case 'invalid-meta-file':
+ return t(
+ 'Downloaded file is invalid, sorry! Visit https://actualbudget.org/contact/ for support.',
+ );
+ case 'decrypt-failure':
+ return t(
+ 'Unable to decrypt file {{fileName}}. To change your key, first download this file with the proper password.',
+ { fileName: fileName || t('(unknown)') },
+ );
+
+ case 'out-of-sync-migrations':
+ return t(
+ 'This budget cannot be loaded with this version of the app. Make sure the app is up-to-date.',
+ );
+
+ case 'clock-drift':
+ return t(
+ 'Failed to download the budget because your device time differs too much from the server. Please check your device time settings and ensure they are correct.',
+ );
+
+ default: {
+ const info =
+ meta && typeof meta === 'object' && 'fileId' in meta && meta.fileId
+ ? `, fileId: ${String(meta.fileId)}`
+ : '';
+ return t(
+ 'Something went wrong trying to download that file, sorry! Visit https://actualbudget.org/contact/ for support. reason: {{reason}}{{info}}',
+ { reason, info },
+ );
+ }
+ }
+}
+
+export function getCreateKeyError(error: ErrorWithMeta) {
+ return getUploadError(error);
+}
+
+export function getTestKeyError({ reason }: ErrorWithMeta) {
+ switch (reason) {
+ case 'network':
+ return t(
+ 'Unable to connect to the server. We need to access the server to get some information about your keys.',
+ );
+ case 'old-key-style':
+ return t(
+ 'This file is encrypted with an old unsupported key style. Recreate the key on a device where the file is available, or use an older version of Actual to download it.',
+ );
+ case 'decrypt-failure':
+ return t('Unable to decrypt file with this password. Please try again.');
+ default:
+ return t(
+ 'Something went wrong trying to create a key, sorry! Visit https://actualbudget.org/contact/ for support.',
+ );
+ }
+}
+
+export function getSyncError(error: string, id: string) {
+ if (error === 'out-of-sync-migrations' || error === 'out-of-sync-data') {
+ return t('This budget cannot be loaded with this version of the app.');
+ } else if (error === 'budget-not-found') {
+ return t(
+ 'Budget "{{id}}" not found. Check the ID of your budget in the Advanced section of the settings page.',
+ { id },
+ );
+ } else if (error === 'clock-drift') {
+ return t(
+ 'Failed to sync because your device time differs too much from the server. Please check your device time settings and ensure they are correct.',
+ );
+ } else {
+ return t('We had an unknown problem opening "{{id}}".', { id });
+ }
+}
+
+export function getUserAccessErrors(reason: string) {
+ switch (reason) {
+ case 'unauthorized':
+ return t('You are not logged in.');
+ case 'token-expired':
+ return t('Login expired, please log in again.');
+ case 'user-cant-be-empty':
+ return t('Please select a user.');
+ case 'invalid-file-id':
+ return t('This file is invalid.');
+ case 'file-denied':
+ return t('You don`t have permissions over this file.');
+ case 'user-already-have-access':
+ return t('User already has access.');
+ default:
+ return t(
+ 'An internal error occurred, sorry! Visit https://actualbudget.org/contact/ for support. (ref: {{reason}})',
+ { reason },
+ );
+ }
+}
+
+export function getSecretsError(error: string, reason: string) {
+ switch (reason) {
+ case 'unauthorized':
+ return t('You are not logged in.');
+ case 'not-admin':
+ return t('You have to be admin to set secrets');
+ default:
+ return t(
+ 'An error occurred while setting the secret. Please try again. (ref: {{error}})',
+ { error },
+ );
+ }
+}
+
+export function getOpenIdErrors(reason: string) {
+ switch (reason) {
+ case 'unauthorized':
+ return t('You are not logged in.');
+ case 'configuration-error':
+ return t('This configuration is not valid. Please check it again.');
+ case 'unable-to-change-file-config-enabled':
+ return t(
+ 'Unable to enable OpenID. Please update the config.json file in this case.',
+ );
+ default:
+ return t(
+ 'An internal error occurred, sorry! Visit https://actualbudget.org/contact/ for support. (ref: {{reason}})',
+ { reason },
+ );
+ }
+}
diff --git a/packages/desktop-client/src/util/rule.ts b/packages/desktop-client/src/util/rule.ts
new file mode 100644
index 0000000000..4b86faaefb
--- /dev/null
+++ b/packages/desktop-client/src/util/rule.ts
@@ -0,0 +1,161 @@
+// @ts-strict-ignore
+import type { RuleEntity } from '@actual-app/core/types/models';
+import { t } from 'i18next';
+import { v4 as uuidv4 } from 'uuid';
+
+export type ActionSplit = {
+ id: string;
+ actions: RuleEntity['actions'];
+};
+
+export function groupActionsBySplitIndex(
+ actions: RuleEntity['actions'],
+): ActionSplit[] {
+ return actions.reduce((acc, action) => {
+ const splitIndex =
+ 'options' in action ? (action.options?.splitIndex ?? 0) : 0;
+ acc[splitIndex] = acc[splitIndex] ?? {
+ id: uuidv4(),
+ actions: [],
+ };
+ acc[splitIndex].actions.push(action);
+ return acc;
+ }, [] as ActionSplit[]);
+}
+
+export function getAllocationMethods(hasFormulaMode = false) {
+ return {
+ 'fixed-amount': t('a fixed amount'),
+ 'fixed-percent': t('a fixed percent of the remainder'),
+ ...(hasFormulaMode && { formula: t('based on a formula') }),
+ remainder: t('an equal portion of the remainder'),
+ };
+}
+
+export function mapField(field, opts?) {
+ opts = opts || {};
+
+ switch (field) {
+ case 'imported_payee':
+ return t('imported payee');
+ case 'payee_name':
+ return t('payee (name)');
+ case 'amount':
+ if (opts.inflow) {
+ return t('amount (inflow)');
+ } else if (opts.outflow) {
+ return t('amount (outflow)');
+ }
+ return t('amount');
+ case 'amount-inflow':
+ return t('amount (inflow)');
+ case 'amount-outflow':
+ return t('amount (outflow)');
+ case 'account':
+ return t('account');
+ case 'date':
+ return t('date');
+ case 'category':
+ return t('category');
+ case 'category_group':
+ return t('category group');
+ case 'notes':
+ return t('notes');
+ case 'payee':
+ return t('payee');
+ case 'saved':
+ return t('saved');
+ case 'cleared':
+ return t('cleared');
+ case 'reconciled':
+ return t('reconciled');
+ case 'transfer':
+ return t('transfer');
+ default:
+ return field;
+ }
+}
+
+export function friendlyOp(op, type?) {
+ switch (op) {
+ case 'oneOf':
+ return t('one of');
+ case 'notOneOf':
+ return t('not one of');
+ case 'is':
+ return t('is');
+ case 'isNot':
+ return t('is not');
+ case 'isapprox':
+ return t('is approx');
+ case 'isbetween':
+ return t('is between');
+ case 'contains':
+ return t('contains');
+ case 'hasTags':
+ return t('has all tags');
+ case 'hasAnyTag':
+ return t('has any tag');
+ case 'matches':
+ return t('matches');
+ case 'doesNotContain':
+ return t('does not contain');
+ case 'gt':
+ if (type === 'date') {
+ return t('is after');
+ }
+ return t('is greater than');
+ case 'gte':
+ if (type === 'date') {
+ return t('is after or equals');
+ }
+ return t('is greater than or equals');
+ case 'lt':
+ if (type === 'date') {
+ return t('is before');
+ }
+ return t('is less than');
+ case 'lte':
+ if (type === 'date') {
+ return t('is before or equals');
+ }
+ return t('is less than or equals');
+ case 'true':
+ return t('is true');
+ case 'false':
+ return t('is false');
+ case 'set':
+ return t('set');
+ case 'set-split-amount':
+ return t('allocate');
+ case 'link-schedule':
+ return t('link schedule');
+ case 'prepend-notes':
+ return t('prepend to notes');
+ case 'append-notes':
+ return t('append to notes');
+ case 'and':
+ return t('and');
+ case 'or':
+ return t('or');
+ case 'onBudget':
+ return t('is on budget');
+ case 'offBudget':
+ return t('is off budget');
+ case 'delete-transaction':
+ return t('delete transaction');
+ default:
+ return '';
+ }
+}
+
+export function translateRuleStage(stage: string): string {
+ switch (stage) {
+ case 'pre':
+ return t('Pre');
+ case 'post':
+ return t('Post');
+ default:
+ return '';
+ }
+}
diff --git a/packages/desktop-client/src/util/ruleUtils.ts b/packages/desktop-client/src/util/ruleUtils.ts
deleted file mode 100644
index 31041d0dfa..0000000000
--- a/packages/desktop-client/src/util/ruleUtils.ts
+++ /dev/null
@@ -1,22 +0,0 @@
-import type { RuleEntity } from '@actual-app/core/types/models';
-import { v4 as uuidv4 } from 'uuid';
-
-export type ActionSplit = {
- id: string;
- actions: RuleEntity['actions'];
-};
-
-export function groupActionsBySplitIndex(
- actions: RuleEntity['actions'],
-): ActionSplit[] {
- return actions.reduce((acc, action) => {
- const splitIndex =
- 'options' in action ? (action.options?.splitIndex ?? 0) : 0;
- acc[splitIndex] = acc[splitIndex] ?? {
- id: uuidv4(),
- actions: [],
- };
- acc[splitIndex].actions.push(action);
- return acc;
- }, [] as ActionSplit[]);
-}
diff --git a/packages/desktop-client/src/util/schedule.test.ts b/packages/desktop-client/src/util/schedule.test.ts
new file mode 100644
index 0000000000..4fde1a36b5
--- /dev/null
+++ b/packages/desktop-client/src/util/schedule.test.ts
@@ -0,0 +1,350 @@
+import { enUS } from 'date-fns/locale';
+import i18next from 'i18next';
+
+import { getRecurringDescription } from '#util/schedule';
+
+// getRecurringDescription uses the full English sentence as the translation
+// key, so with no resources i18next echoes the key back with interpolation
+// applied — which is exactly what these assertions expect.
+void i18next.init({
+ lng: 'en',
+ interpolation: {
+ escapeValue: false,
+ },
+});
+
+describe('getRecurringDescription', () => {
+ it('describes weekly interval', () => {
+ expect(
+ getRecurringDescription(
+ { start: '2021-05-17', frequency: 'weekly' },
+ 'MM/dd/yyyy',
+ enUS,
+ ),
+ ).toBe('Every week on Monday');
+
+ expect(
+ getRecurringDescription(
+ {
+ start: '2021-05-17',
+ frequency: 'weekly',
+ interval: 2,
+ },
+ 'MM/dd/yyyy',
+ enUS,
+ ),
+ ).toBe('Every 2 weeks on Monday');
+ });
+
+ it('describes monthly interval', () => {
+ expect(
+ getRecurringDescription(
+ { start: '2021-04-25', frequency: 'monthly' },
+ 'MM/dd/yyyy',
+ enUS,
+ ),
+ ).toBe('Every month on the 25th');
+
+ expect(
+ getRecurringDescription(
+ {
+ start: '2021-04-25',
+ frequency: 'monthly',
+ interval: 2,
+ },
+ 'MM/dd/yyyy',
+ enUS,
+ ),
+ ).toBe('Every 2 months on the 25th');
+
+ expect(
+ getRecurringDescription(
+ {
+ start: '2021-04-25',
+ frequency: 'monthly',
+ patterns: [{ type: 'day', value: 25 }],
+ },
+ 'MM/dd/yyyy',
+ enUS,
+ ),
+ ).toBe('Every month on the 25th');
+
+ expect(
+ getRecurringDescription(
+ {
+ start: '2021-04-25',
+ frequency: 'monthly',
+ interval: 2,
+ patterns: [{ type: 'day', value: 25 }],
+ },
+ 'MM/dd/yyyy',
+ enUS,
+ ),
+ ).toBe('Every 2 months on the 25th');
+
+ // Last day should work
+ expect(
+ getRecurringDescription(
+ {
+ start: '2021-04-25',
+ frequency: 'monthly',
+ patterns: [{ type: 'day', value: 31 }],
+ },
+ 'MM/dd/yyyy',
+ enUS,
+ ),
+ ).toBe('Every month on the 31st');
+
+ // -1 should work, representing the last day
+ expect(
+ getRecurringDescription(
+ {
+ start: '2021-04-25',
+ frequency: 'monthly',
+ patterns: [{ type: 'day', value: -1 }],
+ },
+ 'MM/dd/yyyy',
+ enUS,
+ ),
+ ).toBe('Every month on the last day');
+
+ // Day names should work
+ expect(
+ getRecurringDescription(
+ {
+ start: '2021-04-25',
+ frequency: 'monthly',
+ patterns: [{ type: 'FR', value: 2 }],
+ },
+ 'MM/dd/yyyy',
+ enUS,
+ ),
+ ).toBe('Every month on the 2nd Friday');
+
+ expect(
+ getRecurringDescription(
+ {
+ start: '2021-04-25',
+ frequency: 'monthly',
+ patterns: [{ type: 'FR', value: -1 }],
+ },
+ 'MM/dd/yyyy',
+ enUS,
+ ),
+ ).toBe('Every month on the last Friday');
+ });
+
+ it('describes monthly interval with multiple days', () => {
+ // Note how order doesn't matter - the day should be sorted
+ expect(
+ getRecurringDescription(
+ {
+ start: '2021-04-25',
+ frequency: 'monthly',
+ patterns: [
+ { type: 'day', value: 15 },
+ { type: 'day', value: 3 },
+ { type: 'day', value: 20 },
+ ],
+ },
+ 'MM/dd/yyyy',
+ enUS,
+ ),
+ ).toBe('Every month on the 3rd, 15th, and 20th');
+
+ expect(
+ getRecurringDescription(
+ {
+ start: '2021-04-25',
+ frequency: 'monthly',
+ patterns: [
+ { type: 'day', value: 3 },
+ { type: 'day', value: -1 },
+ { type: 'day', value: 20 },
+ ],
+ },
+ 'MM/dd/yyyy',
+ enUS,
+ ),
+ ).toBe('Every month on the 3rd, 20th, and last day');
+
+ // Mix days and day names
+ expect(
+ getRecurringDescription(
+ {
+ start: '2021-04-25',
+ frequency: 'monthly',
+ patterns: [
+ { type: 'day', value: 3 },
+ { type: 'day', value: -1 },
+ { type: 'FR', value: 2 },
+ ],
+ },
+ 'MM/dd/yyyy',
+ enUS,
+ ),
+ ).toBe('Every month on the 2nd Friday, 3rd, and last day');
+
+ // When there is a mixture of types, day names should always come first
+ expect(
+ getRecurringDescription(
+ {
+ start: '2021-04-25',
+ frequency: 'monthly',
+ patterns: [
+ { type: 'SA', value: 1 },
+ { type: 'day', value: 2 },
+ { type: 'FR', value: 3 },
+ { type: 'day', value: 10 },
+ ],
+ },
+ 'MM/dd/yyyy',
+ enUS,
+ ),
+ ).toBe('Every month on the 1st Saturday, 3rd Friday, 2nd, and 10th');
+ });
+
+ it('describes yearly interval', () => {
+ expect(
+ getRecurringDescription(
+ { start: '2021-05-17', frequency: 'yearly' },
+ 'MM/dd/yyyy',
+ enUS,
+ ),
+ ).toBe('Every year on May 17th');
+
+ expect(
+ getRecurringDescription(
+ {
+ start: '2021-05-17',
+ frequency: 'yearly',
+ interval: 2,
+ },
+ 'MM/dd/yyyy',
+ enUS,
+ ),
+ ).toBe('Every 2 years on May 17th');
+ });
+
+ it('describes intervals with limited occurrences', () => {
+ expect(
+ getRecurringDescription(
+ {
+ start: '2021-05-17',
+ frequency: 'weekly',
+ interval: 2,
+ endMode: 'after_n_occurrences',
+ endOccurrences: 2,
+ },
+ 'MM/dd/yyyy',
+ enUS,
+ ),
+ ).toBe('Every 2 weeks on Monday, 2 times');
+
+ expect(
+ getRecurringDescription(
+ {
+ start: '2021-05-17',
+ frequency: 'weekly',
+ interval: 2,
+ endMode: 'after_n_occurrences',
+ endOccurrences: 1,
+ },
+ 'MM/dd/yyyy',
+ enUS,
+ ),
+ ).toBe('Every 2 weeks on Monday, once');
+
+ expect(
+ getRecurringDescription(
+ {
+ start: '2021-05-17',
+ frequency: 'monthly',
+ interval: 2,
+ endMode: 'after_n_occurrences',
+ endOccurrences: 2,
+ },
+ 'MM/dd/yyyy',
+ enUS,
+ ),
+ ).toBe('Every 2 months on the 17th, 2 times');
+
+ expect(
+ getRecurringDescription(
+ {
+ start: '2021-05-17',
+ frequency: 'yearly',
+ interval: 2,
+ endMode: 'after_n_occurrences',
+ endOccurrences: 2,
+ },
+ 'MM/dd/yyyy',
+ enUS,
+ ),
+ ).toBe('Every 2 years on May 17th, 2 times');
+ });
+
+ it('describes intervals with an end date', () => {
+ expect(
+ getRecurringDescription(
+ {
+ start: '2021-05-17',
+ frequency: 'weekly',
+ interval: 2,
+ endMode: 'on_date',
+ endDate: '2021-06-01',
+ },
+ 'MM/dd/yyyy',
+ enUS,
+ ),
+ ).toBe('Every 2 weeks on Monday, until 06/01/2021');
+
+ expect(
+ getRecurringDescription(
+ {
+ start: '2021-05-17',
+ frequency: 'monthly',
+ interval: 2,
+ endMode: 'on_date',
+ endDate: '2021-06-01',
+ },
+ 'yyyy-MM-dd',
+ enUS,
+ ),
+ ).toBe('Every 2 months on the 17th, until 2021-06-01');
+ });
+
+ it('separates the weekend annotation when there is no end mode', () => {
+ expect(
+ getRecurringDescription(
+ {
+ start: '2021-05-17',
+ frequency: 'weekly',
+ interval: 1,
+ skipWeekend: true,
+ weekendSolveMode: 'after',
+ },
+ 'MM/dd/yyyy',
+ enUS,
+ ),
+ ).toBe('Every week on Monday (after weekend)');
+ });
+
+ it('combines the end mode and weekend annotations', () => {
+ expect(
+ getRecurringDescription(
+ {
+ start: '2021-05-17',
+ frequency: 'weekly',
+ interval: 2,
+ endMode: 'after_n_occurrences',
+ endOccurrences: 2,
+ skipWeekend: true,
+ weekendSolveMode: 'before',
+ },
+ 'MM/dd/yyyy',
+ enUS,
+ ),
+ ).toBe('Every 2 weeks on Monday, 2 times (before weekend)');
+ });
+});
diff --git a/packages/desktop-client/src/util/schedule.ts b/packages/desktop-client/src/util/schedule.ts
new file mode 100644
index 0000000000..00718aa73e
--- /dev/null
+++ b/packages/desktop-client/src/util/schedule.ts
@@ -0,0 +1,219 @@
+// @ts-strict-ignore
+import * as monthUtils from '@actual-app/core/shared/months';
+import type {
+ PayeeEntity,
+ RecurConfig,
+ ScheduleEntity,
+} from '@actual-app/core/types/models';
+import type { Locale } from 'date-fns';
+import { t } from 'i18next';
+
+export function getStatusLabel(status: string) {
+ switch (status) {
+ case 'completed':
+ return t('completed');
+ case 'paid':
+ return t('paid');
+ case 'due':
+ return t('due');
+ case 'upcoming':
+ return t('upcoming');
+ case 'missed':
+ return t('missed');
+ case 'scheduled':
+ return t('scheduled');
+ default:
+ return t('unknown');
+ }
+}
+
+function makeNumberSuffix(num: number, locale: Locale) {
+ // Slight abuse of date-fns to turn a number like "1" into the full
+ // form "1st" but formatting a date with that number
+ return monthUtils.format(new Date(2020, 0, num, 12), 'do', locale);
+}
+
+function prettyDayName(day) {
+ const days = {
+ SU: t('Sunday'),
+ MO: t('Monday'),
+ TU: t('Tuesday'),
+ WE: t('Wednesday'),
+ TH: t('Thursday'),
+ FR: t('Friday'),
+ SA: t('Saturday'),
+ };
+ return days[day];
+}
+
+export function getRecurringDescription(
+ config: RecurConfig,
+ dateFormat: string,
+ locale: Locale,
+) {
+ const interval = config.interval || 1;
+
+ let endModeSuffix = '';
+ switch (config.endMode) {
+ case 'after_n_occurrences':
+ if (config.endOccurrences === 1) {
+ endModeSuffix = t('once');
+ } else {
+ endModeSuffix = t('{{endOccurrences}} times', {
+ endOccurrences: config.endOccurrences,
+ });
+ }
+ break;
+ case 'on_date':
+ endModeSuffix = t('until {{dateFormatted}}', {
+ dateFormatted: monthUtils.format(config.endDate, dateFormat),
+ });
+ break;
+ default:
+ break;
+ }
+
+ const weekendSolveModeString = config.weekendSolveMode
+ ? config.weekendSolveMode === 'after'
+ ? t('(after weekend)')
+ : t('(before weekend)')
+ : '';
+
+ const weekendSolveSuffix = config.skipWeekend ? weekendSolveModeString : '';
+
+ let suffix = '';
+ if (endModeSuffix) {
+ suffix += `, ${endModeSuffix}`;
+ }
+ if (weekendSolveSuffix) {
+ suffix += ` ${weekendSolveSuffix}`;
+ }
+
+ let desc = null;
+
+ switch (config.frequency) {
+ case 'daily':
+ desc =
+ interval !== 1
+ ? t(`Every {{interval}} days`, { interval })
+ : t('Every day');
+ break;
+ case 'weekly':
+ desc =
+ interval !== 1
+ ? t(`Every {{interval}} weeks on {{dateFormatted}}`, {
+ interval,
+ dateFormatted: monthUtils.format(config.start, 'EEEE', locale),
+ })
+ : t('Every week on {{dateFormatted}}', {
+ dateFormatted: monthUtils.format(config.start, 'EEEE', locale),
+ });
+ break;
+ case 'monthly':
+ if (config.patterns && config.patterns.length > 0) {
+ // Sort the days ascending. We filter out -1 because that
+ // represents "last days" and should always be last, but this
+ // sort would put them first
+ let patterns = [...config.patterns]
+ .sort((p1, p2) => {
+ const typeOrder =
+ (p1.type === 'day' ? 1 : 0) - (p2.type === 'day' ? 1 : 0);
+ const valOrder = p1.value - p2.value;
+
+ if (typeOrder === 0) {
+ return valOrder;
+ }
+ return typeOrder;
+ })
+ .filter(p => p.value !== -1);
+
+ // Add on all -1 values to the end
+ patterns = patterns.concat(config.patterns.filter(p => p.value === -1));
+
+ const strs: string[] = [];
+
+ const uniqueDays = new Set(patterns.map(p => p.type));
+ const isSameDay = uniqueDays.size === 1 && !uniqueDays.has('day');
+ for (const pattern of patterns) {
+ if (pattern.type === 'day') {
+ if (pattern.value === -1) {
+ strs.push(t('last day'));
+ } else {
+ // Example: 15th day
+ strs.push(makeNumberSuffix(pattern.value, locale));
+ }
+ } else {
+ const dayName = isSameDay ? '' : ' ' + prettyDayName(pattern.type);
+
+ if (pattern.value === -1) {
+ // Example: last Monday
+ strs.push(t('last') + dayName);
+ } else {
+ // Example: 3rd Monday
+ strs.push(makeNumberSuffix(pattern.value, locale) + dayName);
+ }
+ }
+ }
+
+ let range = '';
+ if (strs.length > 2) {
+ range += strs.slice(0, strs.length - 1).join(', ');
+ range += `, ${t('and')} `;
+ range += strs[strs.length - 1];
+ } else {
+ range += strs.join(` ${t('and')} `);
+ }
+
+ if (isSameDay) {
+ range += ' ' + prettyDayName(patterns[0].type);
+ }
+
+ desc =
+ interval !== 1
+ ? t(`Every {{interval}} months on the {{range}}`, {
+ interval,
+ range,
+ })
+ : t('Every month on the {{range}}', { range });
+ } else {
+ desc =
+ interval !== 1
+ ? t(`Every {{interval}} months on the {{dateFormatted}}`, {
+ interval,
+ dateFormatted: monthUtils.format(config.start, 'do', locale),
+ })
+ : t('Every month on the {{dateFormatted}}', {
+ dateFormatted: monthUtils.format(config.start, 'do', locale),
+ });
+ }
+ break;
+
+ case 'yearly':
+ desc =
+ interval !== 1
+ ? t(`Every {{interval}} years on {{dateFormatted}}`, {
+ interval,
+ dateFormatted: monthUtils.format(config.start, 'LLL do', locale),
+ })
+ : t('Every year on {{dateFormatted}}', {
+ dateFormatted: monthUtils.format(config.start, 'LLL do', locale),
+ });
+ break;
+
+ default:
+ return t('Recurring error');
+ }
+
+ return `${desc}${suffix}`.trim();
+}
+
+export function describeSchedule(
+ schedule: ScheduleEntity,
+ payee?: PayeeEntity,
+) {
+ if (payee) {
+ return `${payee.name} (${schedule.next_date})`;
+ } else {
+ return `${t('Next:')} ${schedule.next_date}`;
+ }
+}
diff --git a/packages/loot-core/package.json b/packages/loot-core/package.json
index e3866367f0..fe4c99323b 100644
--- a/packages/loot-core/package.json
+++ b/packages/loot-core/package.json
@@ -162,7 +162,6 @@
"scripts": {
"build:node": "cross-env NODE_ENV=production vite build --config ./vite.desktop.config.mts",
"watch:node": "cross-env NODE_ENV=development vite build --config ./vite.desktop.config.mts --watch",
- "generate:i18n": "i18next",
"test": "npm-run-all -cp 'test:*'",
"test:node": "ENV=node vitest --run",
"test:web": "ENV=web vitest --run -c vitest.web.config.ts",
@@ -207,7 +206,6 @@
"crypto-browserify": "^3.12.1",
"fake-indexeddb": "^6.2.5",
"fast-check": "^4.6.0",
- "i18next": "^25.10.10",
"jest-diff": "^30.3.0",
"jsverify": "^0.8.4",
"mockdate": "^3.0.5",
diff --git a/packages/loot-core/src/platform/client/connection/index.ts b/packages/loot-core/src/platform/client/connection/index.ts
index 0aa5c6e859..334438705c 100644
--- a/packages/loot-core/src/platform/client/connection/index.ts
+++ b/packages/loot-core/src/platform/client/connection/index.ts
@@ -1,5 +1,4 @@
// @ts-strict-ignore
-import { t } from 'i18next';
import { v4 as uuidv4 } from 'uuid';
import * as undo from '#platform/client/undo';
@@ -127,11 +126,9 @@ function connectWorker(worker, onOpen, onError) {
);
if (msg.message && msg.message.includes('indexeddb-quota-error')) {
- alert(
- t(
- 'We hit a limit on the local storage available. Edits may not be saved. Please get in touch https://actualbudget.org/contact/ so we can help debug this.',
- ),
- );
+ // Surface this as a typed event so the desktop-client can present a
+ // localized message - i18n must not live in loot-core.
+ handleMessage({ type: 'push', name: 'indexeddb-quota-error' });
}
} else if (msg.type === 'capture-breadcrumb') {
captureBreadcrumb(msg.data);
diff --git a/packages/loot-core/src/server/accounts/app.ts b/packages/loot-core/src/server/accounts/app.ts
index 38ca22ce36..b87e0f5107 100644
--- a/packages/loot-core/src/server/accounts/app.ts
+++ b/packages/loot-core/src/server/accounts/app.ts
@@ -1,4 +1,3 @@
-import { t } from 'i18next';
import { v4 as uuidv4 } from 'uuid';
import { captureException } from '#platform/exceptions';
@@ -237,7 +236,10 @@ async function linkSimpleFinAccount({
let id;
const institution = {
- name: externalAccount.institution ?? t('Unknown'),
+ // Persist a null name when the provider doesn't report an institution, so
+ // the desktop-client can render a localized fallback instead of baking an
+ // English string into shared bank data.
+ name: externalAccount.institution ?? null,
};
const bank = await link.findOrCreateBank(
@@ -311,7 +313,10 @@ async function linkPluggyAiAccount({
let id;
const institution = {
- name: externalAccount.institution ?? t('Unknown'),
+ // Persist a null name when the provider doesn't report an institution, so
+ // the desktop-client can render a localized fallback instead of baking an
+ // English string into shared bank data.
+ name: externalAccount.institution ?? null,
};
const bank = await link.findOrCreateBank(
@@ -385,7 +390,10 @@ async function linkEnableBankingAccount({
let id: string | undefined;
const institution = {
- name: externalAccount.institution ?? t('Unknown'),
+ // Persist a null name when the provider doesn't report an institution, so
+ // the desktop-client can render a localized fallback instead of baking an
+ // English string into shared bank data.
+ name: externalAccount.institution ?? null,
};
// Enable Banking uses a session-per-account model, so we use the
diff --git a/packages/loot-core/src/server/db/types/index.ts b/packages/loot-core/src/server/db/types/index.ts
index 42e789555f..14e657988e 100644
--- a/packages/loot-core/src/server/db/types/index.ts
+++ b/packages/loot-core/src/server/db/types/index.ts
@@ -29,7 +29,7 @@ export type DbAccount = {
export type DbBank = {
id: string;
bank_id: string;
- name: string;
+ name: string | null;
tombstone: 1 | 0;
};
diff --git a/packages/loot-core/src/shared/errors.ts b/packages/loot-core/src/shared/errors.ts
index 332d0d7965..01d2e826fd 100644
--- a/packages/loot-core/src/shared/errors.ts
+++ b/packages/loot-core/src/shared/errors.ts
@@ -1,10 +1,13 @@
-import { t } from 'i18next';
-
type ErrorWithMeta = {
reason: string;
meta?: unknown;
};
+// NOTE: These error formatters are consumed by the headless `@actual-app/api`
+// (see `src/server/api.ts`), which has no i18n. They intentionally return
+// plain English strings. User-facing, translated equivalents live in the
+// desktop-client (`src/util/error.ts`).
+
function isDatabaseSchemaMismatch(meta?: unknown): boolean {
if (
meta &&
@@ -24,40 +27,6 @@ function getSchemaMismatchError() {
return 'This budget could not be loaded because it uses a newer database schema than this version of Actual supports. Make sure you are using the latest version, then try again.';
}
-export function getUploadError({ reason, meta }: ErrorWithMeta) {
- switch (reason) {
- case 'unauthorized':
- return t('You are not logged in.');
- case 'encrypt-failure':
- if ((meta as { isMissingKey: boolean }).isMissingKey) {
- return t(
- 'Encrypting your file failed because you are missing your encryption key. Create your key in the next step.',
- );
- }
- return t(
- 'Encrypting the file failed. You have the correct key so this is an internal bug. To fix this, generate a new key in the next step.',
- );
- case 'file-has-reset':
- // Something really weird happened - during reset a sanity
- // check on the server failed. The user just needs to
- // restart the whole process.
- return t(
- 'Something went wrong while resetting your file. Please try again.',
- );
- case 'file-has-new-key':
- return t(
- 'Unable to encrypt your data because you are missing the key. Create the latest key in the next step.',
- );
- case 'network':
- return t('Uploading the file failed. Check your network connection.');
- default:
- return t(
- 'An internal error occurred, sorry! Visit https://actualbudget.org/contact/ for support. (ref: {{reason}})',
- { reason },
- );
- }
-}
-
export function getDownloadError({
reason,
meta,
@@ -74,13 +43,11 @@ export function getDownloadError({
switch (reason) {
case 'network':
case 'download-failure':
- return t('Downloading the file failed. Check your network connection.');
+ return 'Downloading the file failed. Check your network connection.';
case 'not-zip-file':
case 'invalid-zip-file':
case 'invalid-meta-file':
- return t(
- 'Downloaded file is invalid, sorry! Visit https://actualbudget.org/contact/ for support.',
- );
+ return 'Downloaded file is invalid, sorry! Visit https://actualbudget.org/contact/ for support.';
case 'decrypt-failure':
return (
'Unable to decrypt file ' +
@@ -90,71 +57,50 @@ export function getDownloadError({
);
case 'out-of-sync-migrations':
- return t(
- 'This budget cannot be loaded with this version of the app. Make sure the app is up-to-date.',
- );
+ return 'This budget cannot be loaded with this version of the app. Make sure the app is up-to-date.';
case 'clock-drift':
- return t(
- 'Failed to download the budget because your device time differs too much from the server. Please check your device time settings and ensure they are correct.',
- );
+ return 'Failed to download the budget because your device time differs too much from the server. Please check your device time settings and ensure they are correct.';
- default:
+ default: {
const info =
meta && typeof meta === 'object' && 'fileId' in meta && meta.fileId
? `, fileId: ${String(meta.fileId)}`
: '';
- return t(
- 'Something went wrong trying to download that file, sorry! Visit https://actualbudget.org/contact/ for support. reason: {{reason}}{{info}}',
- { reason, info },
- );
+ return `Something went wrong trying to download that file, sorry! Visit https://actualbudget.org/contact/ for support. reason: ${reason}${info}`;
+ }
}
}
-export function getCreateKeyError(error: ErrorWithMeta) {
- return getUploadError(error);
-}
-
export function getTestKeyError({ reason }: ErrorWithMeta) {
switch (reason) {
case 'network':
- return t(
- 'Unable to connect to the server. We need to access the server to get some information about your keys.',
- );
+ return 'Unable to connect to the server. We need to access the server to get some information about your keys.';
case 'old-key-style':
- return t(
- 'This file is encrypted with an old unsupported key style. Recreate the key on a device where the file is available, or use an older version of Actual to download it.',
- );
+ return 'This file is encrypted with an old unsupported key style. Recreate the key on a device where the file is available, or use an older version of Actual to download it.';
case 'decrypt-failure':
- return t('Unable to decrypt file with this password. Please try again.');
+ return 'Unable to decrypt file with this password. Please try again.';
default:
- return t(
- 'Something went wrong trying to create a key, sorry! Visit https://actualbudget.org/contact/ for support.',
- );
+ return 'Something went wrong trying to create a key, sorry! Visit https://actualbudget.org/contact/ for support.';
}
}
export function getSyncError(error: string, id: string, meta?: unknown) {
if (error === 'out-of-sync-migrations' || error === 'out-of-sync-data') {
- return t('This budget cannot be loaded with this version of the app.');
+ return 'This budget cannot be loaded with this version of the app.';
} else if (error === 'invalid-schema' && isDatabaseSchemaMismatch(meta)) {
return getSchemaMismatchError();
} else if (error === 'budget-not-found') {
- return t(
- 'Budget "{{id}}" not found. Check the ID of your budget in the Advanced section of the settings page.',
- { id },
- );
+ return `Budget "${id}" not found. Check the ID of your budget in the Advanced section of the settings page.`;
} else if (error === 'clock-drift') {
- return t(
- 'Failed to sync because your device time differs too much from the server. Please check your device time settings and ensure they are correct.',
- );
+ return 'Failed to sync because your device time differs too much from the server. Please check your device time settings and ensure they are correct.';
} else {
- return t('We had an unknown problem opening "{{id}}".', { id });
+ return `We had an unknown problem opening "${id}".`;
}
}
export function getBankSyncError(error: { message?: string }) {
- return error.message || t('We had an unknown problem syncing the account.');
+ return error.message || 'We had an unknown problem syncing the account.';
}
export class LazyLoadFailedError extends Error {
@@ -167,54 +113,3 @@ export class LazyLoadFailedError extends Error {
this.cause = cause;
}
}
-
-export function getUserAccessErrors(reason: string) {
- switch (reason) {
- case 'unauthorized':
- return t('You are not logged in.');
- case 'token-expired':
- return t('Login expired, please log in again.');
- case 'user-cant-be-empty':
- return t('Please select a user.');
- case 'invalid-file-id':
- return t('This file is invalid.');
- case 'file-denied':
- return t('You don`t have permissions over this file.');
- case 'user-already-have-access':
- return t('User already has access.');
- default:
- return t(
- 'An internal error occurred, sorry! Visit https://actualbudget.org/contact/ for support. (ref: {{reason}})',
- { reason },
- );
- }
-}
-
-export function getSecretsError(error: string, reason: string) {
- switch (reason) {
- case 'unauthorized':
- return t('You are not logged in.');
- case 'not-admin':
- return t('You have to be admin to set secrets');
- default:
- return error;
- }
-}
-
-export function getOpenIdErrors(reason: string) {
- switch (reason) {
- case 'unauthorized':
- return t('You are not logged in.');
- case 'configuration-error':
- return t('This configuration is not valid. Please check it again.');
- case 'unable-to-change-file-config-enabled':
- return t(
- 'Unable to enable OpenID. Please update the config.json file in this case.',
- );
- default:
- return t(
- 'An internal error occurred, sorry! Visit https://actualbudget.org/contact/ for support. (ref: {{reason}})',
- { reason },
- );
- }
-}
diff --git a/packages/loot-core/src/shared/rules.ts b/packages/loot-core/src/shared/rules.ts
index 5f8b3f5d3b..c431867342 100644
--- a/packages/loot-core/src/shared/rules.ts
+++ b/packages/loot-core/src/shared/rules.ts
@@ -1,6 +1,4 @@
// @ts-strict-ignore
-import { t } from 'i18next';
-
import type { FieldValueTypes, RuleConditionOp } from '#types/models';
// For now, this info is duplicated from the backend. Figure out how
@@ -119,143 +117,6 @@ export function getValidOps(field: keyof FieldValueTypes): RuleConditionOp[] {
);
}
-export function getAllocationMethods(hasFormulaMode = false) {
- return {
- 'fixed-amount': t('a fixed amount'),
- 'fixed-percent': t('a fixed percent of the remainder'),
- ...(hasFormulaMode && { formula: t('based on a formula') }),
- remainder: t('an equal portion of the remainder'),
- };
-}
-
-export function mapField(field, opts?) {
- opts = opts || {};
-
- switch (field) {
- case 'imported_payee':
- return t('imported payee');
- case 'payee_name':
- return t('payee (name)');
- case 'amount':
- if (opts.inflow) {
- return t('amount (inflow)');
- } else if (opts.outflow) {
- return t('amount (outflow)');
- }
- return t('amount');
- case 'amount-inflow':
- return t('amount (inflow)');
- case 'amount-outflow':
- return t('amount (outflow)');
- case 'account':
- return t('account');
- case 'date':
- return t('date');
- case 'category':
- return t('category');
- case 'category_group':
- return t('category group');
- case 'notes':
- return t('notes');
- case 'payee':
- return t('payee');
- case 'saved':
- return t('saved');
- case 'cleared':
- return t('cleared');
- case 'reconciled':
- return t('reconciled');
- case 'transfer':
- return t('transfer');
- default:
- return field;
- }
-}
-
-export function friendlyOp(op, type?) {
- switch (op) {
- case 'oneOf':
- return t('one of');
- case 'notOneOf':
- return t('not one of');
- case 'is':
- return t('is');
- case 'isNot':
- return t('is not');
- case 'isapprox':
- return t('is approx');
- case 'isbetween':
- return t('is between');
- case 'contains':
- return t('contains');
- case 'hasTags':
- return t('has all tags');
- case 'hasAnyTag':
- return t('has any tag');
- case 'matches':
- return t('matches');
- case 'doesNotContain':
- return t('does not contain');
- case 'gt':
- if (type === 'date') {
- return t('is after');
- }
- return t('is greater than');
- case 'gte':
- if (type === 'date') {
- return t('is after or equals');
- }
- return t('is greater than or equals');
- case 'lt':
- if (type === 'date') {
- return t('is before');
- }
- return t('is less than');
- case 'lte':
- if (type === 'date') {
- return t('is before or equals');
- }
- return t('is less than or equals');
- case 'true':
- return t('is true');
- case 'false':
- return t('is false');
- case 'set':
- return t('set');
- case 'set-split-amount':
- return t('allocate');
- case 'link-schedule':
- return t('link schedule');
- case 'prepend-notes':
- return t('prepend to notes');
- case 'append-notes':
- return t('append to notes');
- case 'and':
- return t('and');
- case 'or':
- return t('or');
- case 'onBudget':
- return t('is on budget');
- case 'offBudget':
- return t('is off budget');
- case 'delete-transaction':
- return 'delete transaction';
- default:
- return '';
- }
-}
-
-export function translateRuleStage(stage: string): string {
- switch (stage) {
- case 'pre':
- return t('Pre');
- case 'post':
- return t('Post');
- default:
- return '';
- }
-}
-
export function deserializeField(field) {
if (field === 'amount-inflow') {
return { field: 'amount', options: { inflow: true } };
diff --git a/packages/loot-core/src/shared/schedules.test.ts b/packages/loot-core/src/shared/schedules.test.ts
index ba73e4dc83..3795e921fe 100644
--- a/packages/loot-core/src/shared/schedules.test.ts
+++ b/packages/loot-core/src/shared/schedules.test.ts
@@ -1,5 +1,3 @@
-import { enUS } from 'date-fns/locale';
-import i18next from 'i18next';
import MockDate from 'mockdate';
import type { ScheduleEntity } from '#types/models';
@@ -8,60 +6,11 @@ import * as monthUtils from './months';
import {
computeSchedulePreviewTransactions,
getNextDate,
- getRecurringDescription,
getStatus,
getUpcomingDays,
} from './schedules';
import type { ScheduleStatuses } from './schedules';
-void i18next.init({
- lng: 'en',
- fallbackLng: 'en',
- resources: {
- en: {
- translation: {
- Every: 'Every',
- day: 'day',
- week: 'week',
- month: 'month',
- year: 'year',
- on: 'on',
- 'on the': 'on the',
- and: 'and',
- 'until {{date}}': 'until {{date}}',
- once: 'once',
- times: '{{endOccurrences}} times',
- weekend: 'weekend',
- last: 'last',
- 'Next:': 'Next:',
- 'last day': 'last day',
- '{{interval}} days': '{{interval}} days',
- '{{interval}} weeks': '{{interval}} weeks',
- '{{interval}} months': '{{interval}} months',
- '{{interval}} years': '{{interval}} years',
-
- Sunday: 'Sunday',
- Monday: 'Monday',
- Tuesday: 'Tuesday',
- Wednesday: 'Wednesday',
- Thursday: 'Thursday',
- Friday: 'Friday',
- Saturday: 'Saturday',
-
- '{{value}}th day': '{{value}}th day',
- '{{value}}th': '{{value}}th',
- '{{value}}th {{dayName}}': '{{value}}th {{dayName}}',
- 'last {{dayName}}': 'last {{dayName}}',
-
- '({{weekendSolveMode}} weekend)': '({{weekendSolveMode}} weekend)',
- },
- },
- },
- interpolation: {
- escapeValue: false,
- },
-});
-
describe('schedules', () => {
const today = new Date(2017, 0, 1); // Global date when testing is set to 2017-01-01 per monthUtils.currentDay()
const dateFormat = 'yyyy-MM-dd';
@@ -119,308 +68,6 @@ describe('schedules', () => {
});
});
- describe('getRecurringDescription', () => {
- it('describes weekly interval', () => {
- expect(
- getRecurringDescription(
- { start: '2021-05-17', frequency: 'weekly' },
- 'MM/dd/yyyy',
- enUS,
- ),
- ).toBe('Every week on Monday');
-
- expect(
- getRecurringDescription(
- {
- start: '2021-05-17',
- frequency: 'weekly',
- interval: 2,
- },
- 'MM/dd/yyyy',
- enUS,
- ),
- ).toBe('Every 2 weeks on Monday');
- });
-
- it('describes monthly interval', () => {
- expect(
- getRecurringDescription(
- { start: '2021-04-25', frequency: 'monthly' },
- 'MM/dd/yyyy',
- enUS,
- ),
- ).toBe('Every month on the 25th');
-
- expect(
- getRecurringDescription(
- {
- start: '2021-04-25',
- frequency: 'monthly',
- interval: 2,
- },
- 'MM/dd/yyyy',
- enUS,
- ),
- ).toBe('Every 2 months on the 25th');
-
- expect(
- getRecurringDescription(
- {
- start: '2021-04-25',
- frequency: 'monthly',
- patterns: [{ type: 'day', value: 25 }],
- },
- 'MM/dd/yyyy',
- enUS,
- ),
- ).toBe('Every month on the 25th');
-
- expect(
- getRecurringDescription(
- {
- start: '2021-04-25',
- frequency: 'monthly',
- interval: 2,
- patterns: [{ type: 'day', value: 25 }],
- },
- 'MM/dd/yyyy',
- enUS,
- ),
- ).toBe('Every 2 months on the 25th');
-
- // Last day should work
- expect(
- getRecurringDescription(
- {
- start: '2021-04-25',
- frequency: 'monthly',
- patterns: [{ type: 'day', value: 31 }],
- },
- 'MM/dd/yyyy',
- enUS,
- ),
- ).toBe('Every month on the 31st');
-
- // -1 should work, representing the last day
- expect(
- getRecurringDescription(
- {
- start: '2021-04-25',
- frequency: 'monthly',
- patterns: [{ type: 'day', value: -1 }],
- },
- 'MM/dd/yyyy',
- enUS,
- ),
- ).toBe('Every month on the last day');
-
- // Day names should work
- expect(
- getRecurringDescription(
- {
- start: '2021-04-25',
- frequency: 'monthly',
- patterns: [{ type: 'FR', value: 2 }],
- },
- 'MM/dd/yyyy',
- enUS,
- ),
- ).toBe('Every month on the 2nd Friday');
-
- expect(
- getRecurringDescription(
- {
- start: '2021-04-25',
- frequency: 'monthly',
- patterns: [{ type: 'FR', value: -1 }],
- },
- 'MM/dd/yyyy',
- enUS,
- ),
- ).toBe('Every month on the last Friday');
- });
-
- it('describes monthly interval with multiple days', () => {
- // Note how order doesn't matter - the day should be sorted
- expect(
- getRecurringDescription(
- {
- start: '2021-04-25',
- frequency: 'monthly',
- patterns: [
- { type: 'day', value: 15 },
- { type: 'day', value: 3 },
- { type: 'day', value: 20 },
- ],
- },
- 'MM/dd/yyyy',
- enUS,
- ),
- ).toBe('Every month on the 3rd, 15th, and 20th');
-
- expect(
- getRecurringDescription(
- {
- start: '2021-04-25',
- frequency: 'monthly',
- patterns: [
- { type: 'day', value: 3 },
- { type: 'day', value: -1 },
- { type: 'day', value: 20 },
- ],
- },
- 'MM/dd/yyyy',
- enUS,
- ),
- ).toBe('Every month on the 3rd, 20th, and last day');
-
- // Mix days and day names
- expect(
- getRecurringDescription(
- {
- start: '2021-04-25',
- frequency: 'monthly',
- patterns: [
- { type: 'day', value: 3 },
- { type: 'day', value: -1 },
- { type: 'FR', value: 2 },
- ],
- },
- 'MM/dd/yyyy',
- enUS,
- ),
- ).toBe('Every month on the 2nd Friday, 3rd, and last day');
-
- // When there is a mixture of types, day names should always come first
- expect(
- getRecurringDescription(
- {
- start: '2021-04-25',
- frequency: 'monthly',
- patterns: [
- { type: 'SA', value: 1 },
- { type: 'day', value: 2 },
- { type: 'FR', value: 3 },
- { type: 'day', value: 10 },
- ],
- },
- 'MM/dd/yyyy',
- enUS,
- ),
- ).toBe('Every month on the 1st Saturday, 3rd Friday, 2nd, and 10th');
- });
-
- it('describes yearly interval', () => {
- expect(
- getRecurringDescription(
- { start: '2021-05-17', frequency: 'yearly' },
- 'MM/dd/yyyy',
- enUS,
- ),
- ).toBe('Every year on May 17th');
-
- expect(
- getRecurringDescription(
- {
- start: '2021-05-17',
- frequency: 'yearly',
- interval: 2,
- },
- 'MM/dd/yyyy',
- enUS,
- ),
- ).toBe('Every 2 years on May 17th');
- });
-
- it('describes intervals with limited occurrences', () => {
- expect(
- getRecurringDescription(
- {
- start: '2021-05-17',
- frequency: 'weekly',
- interval: 2,
- endMode: 'after_n_occurrences',
- endOccurrences: 2,
- },
- 'MM/dd/yyyy',
- enUS,
- ),
- ).toBe('Every 2 weeks on Monday, 2 times');
-
- expect(
- getRecurringDescription(
- {
- start: '2021-05-17',
- frequency: 'weekly',
- interval: 2,
- endMode: 'after_n_occurrences',
- endOccurrences: 1,
- },
- 'MM/dd/yyyy',
- enUS,
- ),
- ).toBe('Every 2 weeks on Monday, once');
-
- expect(
- getRecurringDescription(
- {
- start: '2021-05-17',
- frequency: 'monthly',
- interval: 2,
- endMode: 'after_n_occurrences',
- endOccurrences: 2,
- },
- 'MM/dd/yyyy',
- enUS,
- ),
- ).toBe('Every 2 months on the 17th, 2 times');
-
- expect(
- getRecurringDescription(
- {
- start: '2021-05-17',
- frequency: 'yearly',
- interval: 2,
- endMode: 'after_n_occurrences',
- endOccurrences: 2,
- },
- 'MM/dd/yyyy',
- enUS,
- ),
- ).toBe('Every 2 years on May 17th, 2 times');
- });
-
- it('describes intervals with an end date', () => {
- expect(
- getRecurringDescription(
- {
- start: '2021-05-17',
- frequency: 'weekly',
- interval: 2,
- endMode: 'on_date',
- endDate: '2021-06-01',
- },
- 'MM/dd/yyyy',
- enUS,
- ),
- ).toBe('Every 2 weeks on Monday, until 06/01/2021');
-
- expect(
- getRecurringDescription(
- {
- start: '2021-05-17',
- frequency: 'monthly',
- interval: 2,
- endMode: 'on_date',
- endDate: '2021-06-01',
- },
- 'yyyy-MM-dd',
- enUS,
- ),
- ).toBe('Every 2 months on the 17th, until 2021-06-01');
- });
- });
-
describe('getUpcomingDays', () => {
it.each([
['1', 1, '2017-01-01'],
diff --git a/packages/loot-core/src/shared/schedules.ts b/packages/loot-core/src/shared/schedules.ts
index 145fd4699c..39743f8815 100644
--- a/packages/loot-core/src/shared/schedules.ts
+++ b/packages/loot-core/src/shared/schedules.ts
@@ -1,11 +1,9 @@
// @ts-strict-ignore
import type { IRuleOptions } from '@rschedule/core';
import * as d from 'date-fns';
-import type { Locale } from 'date-fns';
-import { t } from 'i18next';
import { Condition } from '#server/rules';
-import type { PayeeEntity, RecurConfig, ScheduleEntity } from '#types/models';
+import type { ScheduleEntity } from '#types/models';
import * as monthUtils from './months';
import { q } from './query';
@@ -36,25 +34,6 @@ export function getStatus(
}
}
-export function getStatusLabel(status: string) {
- switch (status) {
- case 'completed':
- return t('completed');
- case 'paid':
- return t('paid');
- case 'due':
- return t('due');
- case 'upcoming':
- return t('upcoming');
- case 'missed':
- return t('missed');
- case 'scheduled':
- return t('scheduled');
- default:
- return t('unknown');
- }
-}
-
/**
* Builds a query to check if each schedule already has a matching transaction.
*
@@ -90,181 +69,6 @@ export function getHasTransactionsQuery(schedules) {
.select(['schedule', 'date']);
}
-function makeNumberSuffix(num: number, locale: Locale) {
- // Slight abuse of date-fns to turn a number like "1" into the full
- // form "1st" but formatting a date with that number
- return monthUtils.format(new Date(2020, 0, num, 12), 'do', locale);
-}
-
-function prettyDayName(day) {
- const days = {
- SU: t('Sunday'),
- MO: t('Monday'),
- TU: t('Tuesday'),
- WE: t('Wednesday'),
- TH: t('Thursday'),
- FR: t('Friday'),
- SA: t('Saturday'),
- };
- return days[day];
-}
-
-export function getRecurringDescription(
- config: RecurConfig,
- dateFormat: string,
- locale: Locale,
-) {
- const interval = config.interval || 1;
-
- let endModeSuffix = '';
- switch (config.endMode) {
- case 'after_n_occurrences':
- if (config.endOccurrences === 1) {
- endModeSuffix = t('once');
- } else {
- endModeSuffix = t('{{endOccurrences}} times', {
- endOccurrences: config.endOccurrences,
- });
- }
- break;
- case 'on_date':
- endModeSuffix = t('until {{dateFormatted}}', {
- dateFormatted: monthUtils.format(config.endDate, dateFormat),
- });
- break;
- default:
- break;
- }
-
- const weekendSolveModeString = config.weekendSolveMode
- ? config.weekendSolveMode === 'after'
- ? t('(after weekend)')
- : t('(before weekend)')
- : '';
-
- const weekendSolveSuffix = config.skipWeekend ? weekendSolveModeString : '';
- const suffix = endModeSuffix
- ? `, ${endModeSuffix} ${weekendSolveSuffix}`
- : `${weekendSolveSuffix}`;
-
- let desc = null;
-
- switch (config.frequency) {
- case 'daily':
- desc =
- interval !== 1
- ? t(`Every {{interval}} days`, { interval })
- : t('Every day');
- break;
- case 'weekly':
- desc =
- interval !== 1
- ? t(`Every {{interval}} weeks on {{dateFormatted}}`, {
- interval,
- dateFormatted: monthUtils.format(config.start, 'EEEE', locale),
- })
- : t('Every week on {{dateFormatted}}', {
- dateFormatted: monthUtils.format(config.start, 'EEEE', locale),
- });
- break;
- case 'monthly':
- if (config.patterns && config.patterns.length > 0) {
- // Sort the days ascending. We filter out -1 because that
- // represents "last days" and should always be last, but this
- // sort would put them first
- let patterns = [...config.patterns]
- .sort((p1, p2) => {
- const typeOrder =
- (p1.type === 'day' ? 1 : 0) - (p2.type === 'day' ? 1 : 0);
- const valOrder = p1.value - p2.value;
-
- if (typeOrder === 0) {
- return valOrder;
- }
- return typeOrder;
- })
- .filter(p => p.value !== -1);
-
- // Add on all -1 values to the end
- patterns = patterns.concat(config.patterns.filter(p => p.value === -1));
-
- const strs: string[] = [];
-
- const uniqueDays = new Set(patterns.map(p => p.type));
- const isSameDay = uniqueDays.size === 1 && !uniqueDays.has('day');
- for (const pattern of patterns) {
- if (pattern.type === 'day') {
- if (pattern.value === -1) {
- strs.push(t('last day'));
- } else {
- // Example: 15th day
- strs.push(makeNumberSuffix(pattern.value, locale));
- }
- } else {
- const dayName = isSameDay ? '' : ' ' + prettyDayName(pattern.type);
-
- if (pattern.value === -1) {
- // Example: last Monday
- strs.push(t('last') + dayName);
- } else {
- // Example: 3rd Monday
- strs.push(makeNumberSuffix(pattern.value, locale) + dayName);
- }
- }
- }
-
- let range = '';
- if (strs.length > 2) {
- range += strs.slice(0, strs.length - 1).join(', ');
- range += `, ${t('and')} `;
- range += strs[strs.length - 1];
- } else {
- range += strs.join(` ${t('and')} `);
- }
-
- if (isSameDay) {
- range += ' ' + prettyDayName(patterns[0].type);
- }
-
- desc =
- interval !== 1
- ? t(`Every {{interval}} months on the {{range}}`, {
- interval,
- range,
- })
- : t('Every month on the {{range}}', { range });
- } else {
- desc =
- interval !== 1
- ? t(`Every {{interval}} months on the {{dateFormatted}}`, {
- interval,
- dateFormatted: monthUtils.format(config.start, 'do', locale),
- })
- : t('Every month on the {{dateFormatted}}', {
- dateFormatted: monthUtils.format(config.start, 'do', locale),
- });
- }
- break;
-
- case 'yearly':
- desc =
- interval !== 1
- ? t(`Every {{interval}} years on {{dateFormatted}}`, {
- interval,
- dateFormatted: monthUtils.format(config.start, 'LLL do', locale),
- })
- : t('Every year on {{dateFormatted}}', {
- dateFormatted: monthUtils.format(config.start, 'LLL do', locale),
- });
- break;
-
- default:
- return t('Recurring error');
- }
-
- return `${desc}${suffix}`.trim();
-}
-
type ScheduleRuleOptions = IRuleOptions & {
frequency: string;
interval?: number;
@@ -419,17 +223,6 @@ export function getScheduledAmount(
return inverse ? -Math.round(avg) : Math.round(avg);
}
-export function describeSchedule(
- schedule: ScheduleEntity,
- payee?: PayeeEntity,
-) {
- if (payee) {
- return `${payee.name} (${schedule.next_date})`;
- } else {
- return `${t('Next:')} ${schedule.next_date}`;
- }
-}
-
export function getUpcomingDays(
upcomingLength = '7',
today = monthUtils.currentDay(), // for testability
diff --git a/packages/loot-core/src/types/server-events.ts b/packages/loot-core/src/types/server-events.ts
index 573aff9dbd..4956731c3e 100644
--- a/packages/loot-core/src/types/server-events.ts
+++ b/packages/loot-core/src/types/server-events.ts
@@ -53,6 +53,7 @@ type CellsChangedEvent = Array<{
type FallbackWriteErrorEvent = undefined;
type FinishImportEvent = undefined;
type FinishLoadEvent = undefined;
+type IndexeddbQuotaErrorEvent = undefined;
type OrphanedPayeesEvent = {
orphanedIds: string[];
@@ -73,6 +74,7 @@ export type ServerEvents = {
'fallback-write-error': FallbackWriteErrorEvent;
'finish-import': FinishImportEvent;
'finish-load': FinishLoadEvent;
+ 'indexeddb-quota-error': IndexeddbQuotaErrorEvent;
'orphaned-payees': OrphanedPayeesEvent;
'prefs-updated': PrefsUpdatedEvent;
'schedules-offline': SchedulesOfflineEvent;
diff --git a/upcoming-release-notes/8027.md b/upcoming-release-notes/8027.md
new file mode 100644
index 0000000000..ba749972f9
--- /dev/null
+++ b/upcoming-release-notes/8027.md
@@ -0,0 +1,6 @@
+---
+category: Maintenance
+authors: [MatissJanis]
+---
+
+Move i18n usage outside of loot-core.
diff --git a/yarn.lock b/yarn.lock
index 2d94b3defb..8ee92e845a 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -127,7 +127,6 @@ __metadata:
fast-check: "npm:^4.6.0"
handlebars: "npm:^4.7.9"
hyperformula: "npm:^3.2.0"
- i18next: "npm:^25.10.10"
jest-diff: "npm:^30.3.0"
jsverify: "npm:^0.8.4"
lodash: "npm:^4.18.1"