Skip to content

A local-first personal finance app

📚 Translate calendar related strings (#4211)

lelemm60a864a7903c
diff --git a/packages/desktop-client/src/components/accounts/Header.tsx b/packages/desktop-client/src/components/accounts/Header.tsx
index 4a68f224f9..f712ddf184 100644
--- a/packages/desktop-client/src/components/accounts/Header.tsx
+++ b/packages/desktop-client/src/components/accounts/Header.tsx
@@ -25,7 +25,7 @@ import {
type TransactionFilterEntity,
} from 'loot-core/types/models';
-import { useGlobalPref } from '../../hooks/useGlobalPref';
+import { useLocale } from '../../hooks/useLocale';
import { useLocalPref } from '../../hooks/useLocalPref';
import { useSplitsExpanded } from '../../hooks/useSplitsExpanded';
import { useSyncServerStatus } from '../../hooks/useSyncServerStatus';
@@ -188,7 +188,6 @@ export function AccountHeader({
onMakeAsNonSplitTransactions,
}: AccountHeaderProps) {
const { t } = useTranslation();
- const [language] = useGlobalPref('language');
const [menuOpen, setMenuOpen] = useState(false);
const [reconcileOpen, setReconcileOpen] = useState(false);
@@ -201,6 +200,8 @@ export function AccountHeader({
const isServerOffline = syncServerStatus === 'offline';
const [_, setExpandSplitsPref] = useLocalPref('expand-splits');
+ const locale = useLocale();
+
let canSync = !!(account?.account_id && isUsingServer);
if (!account) {
// All accounts - check for any syncable account
@@ -388,7 +389,7 @@ export function AccountHeader({
}}
content={
account?.last_reconciled
- ? `${t('Reconciled')} ${tsToRelativeTime(account.last_reconciled, language || 'en-US')}`
+ ? `${t('Reconciled')} ${tsToRelativeTime(account.last_reconciled, locale)}`
: t('Not yet reconciled')
}
placement="top"
diff --git a/packages/desktop-client/src/components/banksync/AccountRow.tsx b/packages/desktop-client/src/components/banksync/AccountRow.tsx
index f0df6fd6f1..73421fc5c0 100644
--- a/packages/desktop-client/src/components/banksync/AccountRow.tsx
+++ b/packages/desktop-client/src/components/banksync/AccountRow.tsx
@@ -6,7 +6,6 @@ import { Button } from '@actual-app/components/button';
import { tsToRelativeTime } from 'loot-core/shared/util';
import { type AccountEntity } from 'loot-core/src/types/models';
-import { useGlobalPref } from '../../hooks/useGlobalPref';
import { theme } from '../../style';
import { Row, Cell } from '../table';
@@ -15,15 +14,14 @@ type AccountRowProps = {
hovered: boolean;
onHover: (id: AccountEntity['id'] | null) => void;
onAction: (account: AccountEntity, action: 'link' | 'edit') => void;
+ locale: Locale;
};
export const AccountRow = memo(
- ({ account, hovered, onHover, onAction }: AccountRowProps) => {
+ ({ account, hovered, onHover, onAction, locale }: AccountRowProps) => {
const backgroundFocus = hovered;
- const [language = 'en-US'] = useGlobalPref('language');
-
- const lastSync = tsToRelativeTime(account.last_sync, language, {
+ const lastSync = tsToRelativeTime(account.last_sync, locale, {
capitalize: true,
});
diff --git a/packages/desktop-client/src/components/banksync/AccountsList.tsx b/packages/desktop-client/src/components/banksync/AccountsList.tsx
index 49469a38e1..42b21c0bad 100644
--- a/packages/desktop-client/src/components/banksync/AccountsList.tsx
+++ b/packages/desktop-client/src/components/banksync/AccountsList.tsx
@@ -4,6 +4,8 @@ import { View } from '@actual-app/components/view';
import { type AccountEntity } from 'loot-core/src/types/models';
+import { useLocale } from '../../hooks/useLocale';
+
import { AccountRow } from './AccountRow';
type AccountsListProps = {
@@ -19,6 +21,8 @@ export function AccountsList({
onHover,
onAction,
}: AccountsListProps) {
+ const locale = useLocale();
+
if (accounts.length === 0) {
return null;
}
@@ -39,6 +43,7 @@ export function AccountsList({
hovered={hovered}
onHover={onHover}
onAction={onAction}
+ locale={locale}
/>
);
})}
diff --git a/packages/desktop-client/src/components/budget/MonthPicker.tsx b/packages/desktop-client/src/components/budget/MonthPicker.tsx
index fb8604f02b..6873e83235 100644
--- a/packages/desktop-client/src/components/budget/MonthPicker.tsx
+++ b/packages/desktop-client/src/components/budget/MonthPicker.tsx
@@ -7,6 +7,7 @@ import { View } from '@actual-app/components/view';
import * as monthUtils from 'loot-core/shared/months';
+import { useLocale } from '../../hooks/useLocale';
import { useResizeObserver } from '../../hooks/useResizeObserver';
import { SvgCalendar } from '../../icons/v2';
import { theme } from '../../style';
@@ -29,6 +30,7 @@ export const MonthPicker = ({
style,
onSelect,
}: MonthPickerProps) => {
+ const locale = useLocale();
const { t } = useTranslation();
const [hoverId, setHoverId] = useState(null);
const [targetMonthCount, setTargetMonthCount] = useState(12);
@@ -103,7 +105,7 @@ export const MonthPicker = ({
</View>
</Link>
{range.map((month, idx) => {
- const monthName = monthUtils.format(month, 'MMM');
+ const monthName = monthUtils.format(month, 'MMM', locale);
const selected =
idx >= firstSelectedIndex && idx <= lastSelectedIndex;
diff --git a/packages/desktop-client/src/components/budget/envelope/budgetsummary/BudgetSummary.tsx b/packages/desktop-client/src/components/budget/envelope/budgetsummary/BudgetSummary.tsx
index b8347ddc67..9835f7f130 100644
--- a/packages/desktop-client/src/components/budget/envelope/budgetsummary/BudgetSummary.tsx
+++ b/packages/desktop-client/src/components/budget/envelope/budgetsummary/BudgetSummary.tsx
@@ -9,6 +9,7 @@ import { css } from '@emotion/css';
import * as monthUtils from 'loot-core/shared/months';
+import { useLocale } from '../../../../hooks/useLocale';
import { useUndo } from '../../../../hooks/useUndo';
import { SvgDotsHorizontalTriple } from '../../../../icons/v1';
import { SvgArrowButtonDown1, SvgArrowButtonUp1 } from '../../../../icons/v2';
@@ -26,6 +27,7 @@ type BudgetSummaryProps = {
isGoalTemplatesEnabled?: boolean;
};
export function BudgetSummary({ month }: BudgetSummaryProps) {
+ const locale = useLocale();
const {
currentMonth,
summaryCollapsed: collapsed,
@@ -45,13 +47,17 @@ export function BudgetSummary({ month }: BudgetSummaryProps) {
setMenuOpen(false);
}
- const prevMonthName = monthUtils.format(monthUtils.prevMonth(month), 'MMM');
+ const prevMonthName = monthUtils.format(
+ monthUtils.prevMonth(month),
+ 'MMM',
+ locale,
+ );
const ExpandOrCollapseIcon = collapsed
? SvgArrowButtonDown1
: SvgArrowButtonUp1;
- const displayMonth = monthUtils.format(month, 'MMMM ‘yy');
+ const displayMonth = monthUtils.format(month, 'MMMM ‘yy', locale);
const { t } = useTranslation();
return (
@@ -125,7 +131,7 @@ export function BudgetSummary({ month }: BudgetSummaryProps) {
currentMonth === month && { fontWeight: 'bold' },
])}
>
- {monthUtils.format(month, 'MMMM')}
+ {monthUtils.format(month, 'MMMM', locale)}
</div>
<View
diff --git a/packages/desktop-client/src/components/budget/tracking/budgetsummary/BudgetSummary.tsx b/packages/desktop-client/src/components/budget/tracking/budgetsummary/BudgetSummary.tsx
index 16eef91be3..509f0fa2d9 100644
--- a/packages/desktop-client/src/components/budget/tracking/budgetsummary/BudgetSummary.tsx
+++ b/packages/desktop-client/src/components/budget/tracking/budgetsummary/BudgetSummary.tsx
@@ -11,6 +11,7 @@ import { css } from '@emotion/css';
import * as monthUtils from 'loot-core/shared/months';
+import { useLocale } from '../../../../hooks/useLocale';
import { useUndo } from '../../../../hooks/useUndo';
import { SvgDotsHorizontalTriple } from '../../../../icons/v1';
import { SvgArrowButtonDown1, SvgArrowButtonUp1 } from '../../../../icons/v2';
@@ -28,6 +29,7 @@ type BudgetSummaryProps = {
month?: string;
};
export function BudgetSummary({ month }: BudgetSummaryProps) {
+ const locale = useLocale();
const { t } = useTranslation();
const {
currentMonth,
@@ -52,7 +54,7 @@ export function BudgetSummary({ month }: BudgetSummaryProps) {
? SvgArrowButtonDown1
: SvgArrowButtonUp1;
- const displayMonth = monthUtils.format(month, 'MMMM ‘yy');
+ const displayMonth = monthUtils.format(month, 'MMMM ‘yy', locale);
return (
<View
@@ -121,7 +123,7 @@ export function BudgetSummary({ month }: BudgetSummaryProps) {
textDecorationSkip: 'ink',
})}
>
- {monthUtils.format(month, 'MMMM')}
+ {monthUtils.format(month, 'MMMM', locale)}
</div>
<View
diff --git a/packages/desktop-client/src/components/mobile/budget/BudgetTable.jsx b/packages/desktop-client/src/components/mobile/budget/BudgetTable.jsx
index 48e888c5f3..90ef14bf16 100644
--- a/packages/desktop-client/src/components/mobile/budget/BudgetTable.jsx
+++ b/packages/desktop-client/src/components/mobile/budget/BudgetTable.jsx
@@ -22,6 +22,7 @@ import { groupById, integerToCurrency } from 'loot-core/shared/util';
import { useCategories } from '../../../hooks/useCategories';
import { useFeatureFlag } from '../../../hooks/useFeatureFlag';
+import { useLocale } from '../../../hooks/useLocale';
import { useLocalPref } from '../../../hooks/useLocalPref';
import { useNavigate } from '../../../hooks/useNavigate';
import { useNotes } from '../../../hooks/useNotes';
@@ -2042,6 +2043,7 @@ function MonthSelector({
onPrevMonth,
onNextMonth,
}) {
+ const locale = useLocale();
const { t } = useTranslation();
const prevEnabled = month > monthBounds.start;
const nextEnabled = month < monthUtils.subMonths(monthBounds.end, 1);
@@ -2086,7 +2088,7 @@ function MonthSelector({
data-month={month}
>
<Text style={styles.underlinedText}>
- {monthUtils.format(month, 'MMMM ‘yy')}
+ {monthUtils.format(month, 'MMMM ‘yy', locale)}
</Text>
</Button>
<Button
diff --git a/packages/desktop-client/src/components/mobile/budget/CategoryTransactions.tsx b/packages/desktop-client/src/components/mobile/budget/CategoryTransactions.tsx
index dac9bb132a..d706a48d1b 100644
--- a/packages/desktop-client/src/components/mobile/budget/CategoryTransactions.tsx
+++ b/packages/desktop-client/src/components/mobile/budget/CategoryTransactions.tsx
@@ -19,6 +19,7 @@ import {
} from 'loot-core/types/models';
import { useDateFormat } from '../../../hooks/useDateFormat';
+import { useLocale } from '../../../hooks/useLocale';
import { useNavigate } from '../../../hooks/useNavigate';
import { useDispatch } from '../../../redux';
import { MobilePageHeader, Page } from '../../Page';
@@ -35,6 +36,7 @@ export function CategoryTransactions({
category,
month,
}: CategoryTransactionsProps) {
+ const locale = useLocale();
const dispatch = useDispatch();
const navigate = useNavigate();
@@ -105,7 +107,7 @@ export function CategoryTransactions({
<View>
<TextOneLine>{category.name}</TextOneLine>
<TextOneLine>
- ({monthUtils.format(month, 'MMMM ‘yy')})
+ ({monthUtils.format(month, 'MMMM ‘yy', locale)})
</TextOneLine>
</View>
}
diff --git a/packages/desktop-client/src/components/mobile/budget/index.tsx b/packages/desktop-client/src/components/mobile/budget/index.tsx
index 41b3fd5781..f945e94165 100644
--- a/packages/desktop-client/src/components/mobile/budget/index.tsx
+++ b/packages/desktop-client/src/components/mobile/budget/index.tsx
@@ -21,6 +21,7 @@ import { send } from 'loot-core/platform/client/fetch';
import * as monthUtils from 'loot-core/shared/months';
import { useCategories } from '../../../hooks/useCategories';
+import { useLocale } from '../../../hooks/useLocale';
import { useLocalPref } from '../../../hooks/useLocalPref';
import { useSyncedPref } from '../../../hooks/useSyncedPref';
import { AnimatedLoading } from '../../../icons/AnimatedLoading';
@@ -37,6 +38,7 @@ function isBudgetType(input?: string): input is 'rollover' | 'report' {
}
export function Budget() {
+ const locale = useLocale();
const { list: categories, grouped: categoryGroups } = useCategories();
const [budgetTypePref] = useSyncedPref('budgetType');
const budgetType = isBudgetType(budgetTypePref) ? budgetTypePref : 'rollover';
@@ -485,14 +487,14 @@ export function Budget() {
name: 'notes',
options: {
id: `budget-${month}`,
- name: monthUtils.format(month, 'MMMM ‘yy'),
+ name: monthUtils.format(month, 'MMMM ‘yy', locale),
onSave: onSaveNotes,
},
},
}),
);
},
- [dispatch, onSaveNotes],
+ [dispatch, onSaveNotes, locale],
);
const onSwitchBudgetFile = useCallback(() => {
diff --git a/packages/desktop-client/src/components/mobile/transactions/TransactionList.tsx b/packages/desktop-client/src/components/mobile/transactions/TransactionList.tsx
index 28ee59a84b..5294f85055 100644
--- a/packages/desktop-client/src/components/mobile/transactions/TransactionList.tsx
+++ b/packages/desktop-client/src/components/mobile/transactions/TransactionList.tsx
@@ -30,6 +30,7 @@ import { type TransactionEntity } from 'loot-core/types/models/transaction';
import { useAccounts } from '../../../hooks/useAccounts';
import { useCategories } from '../../../hooks/useCategories';
+import { useLocale } from '../../../hooks/useLocale';
import { useNavigate } from '../../../hooks/useNavigate';
import { usePayees } from '../../../hooks/usePayees';
import {
@@ -89,6 +90,7 @@ export function TransactionList({
onLoadMore,
account,
}: TransactionListProps) {
+ const locale = useLocale();
const { t } = useTranslation();
const sections = useMemo(() => {
// Group by date. We can assume transactions is ordered
@@ -181,7 +183,7 @@ export function TransactionList({
zIndex: 10,
}}
>
- {monthUtils.format(section.date, 'MMMM dd, yyyy')}
+ {monthUtils.format(section.date, 'MMMM dd, yyyy', locale)}
</Header>
<Collection
items={section.transactions.filter(
diff --git a/packages/desktop-client/src/components/modals/EnvelopeBudgetMonthMenuModal.tsx b/packages/desktop-client/src/components/modals/EnvelopeBudgetMonthMenuModal.tsx
index 36d0d236f8..632d1fa6e2 100644
--- a/packages/desktop-client/src/components/modals/EnvelopeBudgetMonthMenuModal.tsx
+++ b/packages/desktop-client/src/components/modals/EnvelopeBudgetMonthMenuModal.tsx
@@ -10,6 +10,7 @@ import { css } from '@emotion/css';
import { type Modal as ModalType } from 'loot-core/client/modals/modalsSlice';
import * as monthUtils from 'loot-core/shared/months';
+import { useLocale } from '../../hooks/useLocale';
import { useNotes } from '../../hooks/useNotes';
import { useUndo } from '../../hooks/useUndo';
import { SvgCheveronDown, SvgCheveronUp } from '../../icons/v1';
@@ -29,6 +30,7 @@ export function EnvelopeBudgetMonthMenuModal({
onBudgetAction,
onEditNotes,
}: EnvelopeBudgetMonthMenuModalProps) {
+ const locale = useLocale();
const originalNotes = useNotes(`budget-${month}`);
const { showUndoNotification } = useUndo();
@@ -57,7 +59,7 @@ export function EnvelopeBudgetMonthMenuModal({
setShowMore(!showMore);
};
- const displayMonth = monthUtils.format(month, 'MMMM ‘yy');
+ const displayMonth = monthUtils.format(month, 'MMMM ‘yy', locale);
const { t } = useTranslation();
return (
diff --git a/packages/desktop-client/src/components/modals/EnvelopeBudgetSummaryModal.tsx b/packages/desktop-client/src/components/modals/EnvelopeBudgetSummaryModal.tsx
index 75fbc3dcee..8399e99db8 100644
--- a/packages/desktop-client/src/components/modals/EnvelopeBudgetSummaryModal.tsx
+++ b/packages/desktop-client/src/components/modals/EnvelopeBudgetSummaryModal.tsx
@@ -13,6 +13,7 @@ import { format, sheetForMonth, prevMonth } from 'loot-core/shared/months';
import { groupById, integerToCurrency } from 'loot-core/shared/util';
import { useCategories } from '../../hooks/useCategories';
+import { useLocale } from '../../hooks/useLocale';
import { useUndo } from '../../hooks/useUndo';
import { useDispatch } from '../../redux';
import { ToBudgetAmount } from '../budget/envelope/budgetsummary/ToBudgetAmount';
@@ -32,8 +33,9 @@ export function EnvelopeBudgetSummaryModal({
}: EnvelopeBudgetSummaryModalProps) {
const { t } = useTranslation();
+ const locale = useLocale();
const dispatch = useDispatch();
- const prevMonthName = format(prevMonth(month), 'MMM');
+ const prevMonthName = format(prevMonth(month), 'MMM', locale);
const sheetValue =
useEnvelopeSheetValue({
name: envelopeBudget.toBudget,
diff --git a/packages/desktop-client/src/components/modals/ScheduledTransactionMenuModal.tsx b/packages/desktop-client/src/components/modals/ScheduledTransactionMenuModal.tsx
index 622ab9199d..b2488ce6fe 100644
--- a/packages/desktop-client/src/components/modals/ScheduledTransactionMenuModal.tsx
+++ b/packages/desktop-client/src/components/modals/ScheduledTransactionMenuModal.tsx
@@ -19,6 +19,7 @@ import {
extractScheduleConds,
} from 'loot-core/shared/schedules';
+import { useLocale } from '../../hooks/useLocale';
import { theme } from '../../style';
import {
Modal,
@@ -38,6 +39,7 @@ export function ScheduledTransactionMenuModal({
onPost,
onComplete,
}: ScheduledTransactionMenuModalProps) {
+ const locale = useLocale();
const { t } = useTranslation();
const defaultMenuItemStyle: CSSProperties = {
...styles.mobileMenuItem,
@@ -83,7 +85,7 @@ export function ScheduledTransactionMenuModal({
{t('Scheduled date')}
</Text>
<Text style={{ fontSize: 17, fontWeight: 700 }}>
- {format(schedule?.next_date || '', 'MMMM dd, yyyy')}
+ {format(schedule?.next_date || '', 'MMMM dd, yyyy', locale)}
</Text>
</View>
<ScheduledTransactionMenu
diff --git a/packages/desktop-client/src/components/modals/TrackingBudgetMonthMenuModal.tsx b/packages/desktop-client/src/components/modals/TrackingBudgetMonthMenuModal.tsx
index fbd5b7978f..e97d62d5c2 100644
--- a/packages/desktop-client/src/components/modals/TrackingBudgetMonthMenuModal.tsx
+++ b/packages/desktop-client/src/components/modals/TrackingBudgetMonthMenuModal.tsx
@@ -10,6 +10,7 @@ import { css } from '@emotion/css';
import { type Modal as ModalType } from 'loot-core/client/modals/modalsSlice';
import * as monthUtils from 'loot-core/shared/months';
+import { useLocale } from '../../hooks/useLocale';
import { useNotes } from '../../hooks/useNotes';
import { useUndo } from '../../hooks/useUndo';
import { SvgCheveronDown, SvgCheveronUp } from '../../icons/v1';
@@ -29,6 +30,7 @@ export function TrackingBudgetMonthMenuModal({
onBudgetAction,
onEditNotes,
}: TrackingBudgetMonthMenuModalProps) {
+ const locale = useLocale();
const { t } = useTranslation();
const originalNotes = useNotes(`budget-${month}`);
const { showUndoNotification } = useUndo();
@@ -58,7 +60,7 @@ export function TrackingBudgetMonthMenuModal({
setShowMore(!showMore);
};
- const displayMonth = monthUtils.format(month, 'MMMM ‘yy');
+ const displayMonth = monthUtils.format(month, 'MMMM ‘yy', locale);
return (
<Modal
diff --git a/packages/desktop-client/src/components/reports/DateRange.tsx b/packages/desktop-client/src/components/reports/DateRange.tsx
index f7d61a250b..cc2243674e 100644
--- a/packages/desktop-client/src/components/reports/DateRange.tsx
+++ b/packages/desktop-client/src/components/reports/DateRange.tsx
@@ -9,6 +9,8 @@ import * as d from 'date-fns';
import * as monthUtils from 'loot-core/shared/months';
+import { useLocale } from '../../hooks/useLocale';
+
type DateRangeProps = {
start: string;
end: string;
@@ -25,6 +27,7 @@ function checkDate(date: string) {
}
export function DateRange({ start, end, type }: DateRangeProps): ReactElement {
+ const locale = useLocale();
const checkStart = checkDate(start);
const checkEnd = checkDate(end);
@@ -41,8 +44,8 @@ export function DateRange({ start, end, type }: DateRangeProps): ReactElement {
);
}
- const formattedStartDate = d.format(startDate, 'MMM yyyy');
- const formattedEndDate = d.format(endDate, 'MMM yyyy');
+ const formattedStartDate = d.format(startDate, 'MMM yyyy', { locale });
+ const formattedEndDate = d.format(endDate, 'MMM yyyy', { locale });
let typeOrFormattedEndDate: string;
if (type && ['budget', 'average'].includes(type)) {
@@ -78,7 +81,7 @@ export function DateRange({ start, end, type }: DateRangeProps): ReactElement {
</div>
);
} else {
- content = d.format(endDate, 'MMMM yyyy');
+ content = d.format(endDate, 'MMMM yyyy', { locale });
}
return <Block style={{ color: theme.pageTextSubdued }}>{content}</Block>;
diff --git a/packages/desktop-client/src/components/reports/Header.tsx b/packages/desktop-client/src/components/reports/Header.tsx
index c0be1356c8..b6896abf25 100644
--- a/packages/desktop-client/src/components/reports/Header.tsx
+++ b/packages/desktop-client/src/components/reports/Header.tsx
@@ -12,6 +12,7 @@ import {
} from 'loot-core/types/models';
import { type SyncedPrefs } from 'loot-core/types/prefs';
+import { useLocale } from '../../hooks/useLocale';
import { Select } from '../common/Select';
import { AppliedFilters } from '../filters/AppliedFilters';
import { FilterButton } from '../filters/FiltersMenu';
@@ -67,6 +68,7 @@ export function Header({
onConditionsOpChange,
children,
}: HeaderProps) {
+ const locale = useLocale();
const { t } = useTranslation();
const { isNarrowWidth } = useResponsive();
function convertToMonth(
@@ -123,7 +125,7 @@ export function Header({
)
}
value={start}
- defaultLabel={monthUtils.format(start, 'MMMM, yyyy')}
+ defaultLabel={monthUtils.format(start, 'MMMM, yyyy', locale)}
options={allMonths.map(({ name, pretty }) => [name, pretty])}
/>
<View>{t('to')}</View>
diff --git a/packages/desktop-client/src/components/reports/ReportSummary.tsx b/packages/desktop-client/src/components/reports/ReportSummary.tsx
index 30f620c9a1..4191f664fa 100644
--- a/packages/desktop-client/src/components/reports/ReportSummary.tsx
+++ b/packages/desktop-client/src/components/reports/ReportSummary.tsx
@@ -16,6 +16,7 @@ import {
type DataEntity,
} from 'loot-core/types/models/reports';
+import { useLocale } from '../../hooks/useLocale';
import { theme } from '../../style';
import { PrivacyFilter } from '../PrivacyFilter';
@@ -38,6 +39,7 @@ export function ReportSummary({
interval,
intervalsCount,
}: ReportSummaryProps) {
+ const locale = useLocale();
const { t } = useTranslation();
const net =
balanceTypeOp === 'netAssets'
@@ -74,19 +76,23 @@ export function ReportSummary({
{monthUtils.format(
startDate,
ReportOptions.intervalFormat.get(interval) || '',
+ locale,
)}
{monthUtils.format(
startDate,
ReportOptions.intervalFormat.get(interval) || '',
+ locale,
) !==
monthUtils.format(
endDate,
ReportOptions.intervalFormat.get(interval) || '',
+ locale,
) &&
- ' to ' +
+ ` ${t('to')} ` +
monthUtils.format(
endDate,
ReportOptions.intervalFormat.get(interval) || '',
+ locale,
)}
</Text>
</View>
diff --git a/packages/desktop-client/src/components/reports/graphs/CashFlowGraph.tsx b/packages/desktop-client/src/components/reports/graphs/CashFlowGraph.tsx
index a90c4752e1..79e765ad68 100644
--- a/packages/desktop-client/src/components/reports/graphs/CashFlowGraph.tsx
+++ b/packages/desktop-client/src/components/reports/graphs/CashFlowGraph.tsx
@@ -23,6 +23,7 @@ import {
amountToCurrencyNoDecimal,
} from 'loot-core/shared/util';
+import { useLocale } from '../../../hooks/useLocale';
import { usePrivacyMode } from '../../../hooks/usePrivacyMode';
import { chartTheme } from '../chart-theme';
import { Container } from '../Container';
@@ -35,6 +36,7 @@ type CustomTooltipProps = TooltipProps<number, 'date'> & {
};
function CustomTooltip({ active, payload, isConcise }: CustomTooltipProps) {
+ const locale = useLocale();
const { t } = useTranslation();
if (!active || !payload || !Array.isArray(payload) || !payload[0]) {
@@ -57,7 +59,9 @@ function CustomTooltip({ active, payload, isConcise }: CustomTooltipProps) {
<div>
<div style={{ marginBottom: 10 }}>
<strong>
- {d.format(data.date, isConcise ? 'MMMM yyyy' : 'MMMM dd, yyyy')}
+ {d.format(data.date, isConcise ? 'MMMM yyyy' : 'MMMM dd, yyyy', {
+ locale,
+ })}
</strong>
</div>
<div style={{ lineHeight: 1.5 }}>
@@ -108,6 +112,7 @@ export function CashFlowGraph({
showBalance = true,
style,
}: CashFlowGraphProps) {
+ const locale = useLocale();
const privacyMode = usePrivacyMode();
const [yAxisIsHovered, setYAxisIsHovered] = useState(false);
@@ -135,7 +140,9 @@ export function CashFlowGraph({
tick={{ fill: theme.reportsLabel }}
tickFormatter={x => {
// eslint-disable-next-line rulesdir/typography
- return d.format(x, isConcise ? "MMM ''yy" : 'MMM d');
+ return d.format(x, isConcise ? "MMM ''yy" : 'MMM d', {
+ locale,
+ });
}}
minTickGap={50}
/>
@@ -153,7 +160,9 @@ export function CashFlowGraph({
<Tooltip
labelFormatter={x => {
// eslint-disable-next-line rulesdir/typography
- return d.format(x, isConcise ? "MMM ''yy" : 'MMM d');
+ return d.format(x, isConcise ? "MMM ''yy" : 'MMM d', {
+ locale,
+ });
}}
content={<CustomTooltip isConcise={isConcise} />}
isAnimationActive={false}
diff --git a/packages/desktop-client/src/components/reports/reports/Calendar.tsx b/packages/desktop-client/src/components/reports/reports/Calendar.tsx
index ea5483fe15..9ff6988463 100644
--- a/packages/desktop-client/src/components/reports/reports/Calendar.tsx
+++ b/packages/desktop-client/src/components/reports/reports/Calendar.tsx
@@ -37,6 +37,7 @@ import { useAccounts } from '../../../hooks/useAccounts';
import { useCategories } from '../../../hooks/useCategories';
import { useDateFormat } from '../../../hooks/useDateFormat';
import { useFilters } from '../../../hooks/useFilters';
+import { useLocale } from '../../../hooks/useLocale';
import { useMergedRefs } from '../../../hooks/useMergedRefs';
import { useNavigate } from '../../../hooks/useNavigate';
import { usePayees } from '../../../hooks/usePayees';
@@ -96,6 +97,7 @@ type CalendarInnerProps = {
};
function CalendarInner({ widget, parameters }: CalendarInnerProps) {
+ const locale = useLocale();
const { t } = useTranslation();
const [initialStart, initialEnd, initialMode] = calculateTimeRange(
widget?.meta?.timeFrame,
@@ -267,7 +269,7 @@ function CalendarInner({ widget, parameters }: CalendarInnerProps) {
.rangeInclusive(earliestMonth, monthUtils.currentMonth())
.map(month => ({
name: month,
- pretty: monthUtils.format(month, 'MMMM, yyyy'),
+ pretty: monthUtils.format(month, 'MMMM, yyyy', locale),
}))
.reverse();
@@ -277,7 +279,7 @@ function CalendarInner({ widget, parameters }: CalendarInnerProps) {
}
}
run();
- }, []);
+ }, [locale]);
const dispatch = useDispatch();
const navigate = useNavigate();
diff --git a/packages/desktop-client/src/components/reports/reports/CashFlow.tsx b/packages/desktop-client/src/components/reports/reports/CashFlow.tsx
index f9df45f7b6..77ba93ebc9 100644
--- a/packages/desktop-client/src/components/reports/reports/CashFlow.tsx
+++ b/packages/desktop-client/src/components/reports/reports/CashFlow.tsx
@@ -23,6 +23,7 @@ import {
} from 'loot-core/types/models';
import { useFilters } from '../../../hooks/useFilters';
+import { useLocale } from '../../../hooks/useLocale';
import { useNavigate } from '../../../hooks/useNavigate';
import { useSyncedPref } from '../../../hooks/useSyncedPref';
import { useDispatch } from '../../../redux';
@@ -64,6 +65,7 @@ type CashFlowInnerProps = {
};
function CashFlowInner({ widget }: CashFlowInnerProps) {
+ const locale = useLocale();
const dispatch = useDispatch();
const { t } = useTranslation();
@@ -104,8 +106,9 @@ function CashFlowInner({ widget }: CashFlowInnerProps) {
});
const params = useMemo(
- () => cashFlowByDate(start, end, isConcise, conditions, conditionsOp),
- [start, end, isConcise, conditions, conditionsOp],
+ () =>
+ cashFlowByDate(start, end, isConcise, conditions, conditionsOp, locale),
+ [start, end, isConcise, conditions, conditionsOp, locale],
);
const data = useReport('cash_flow', params);
@@ -120,14 +123,14 @@ function CashFlowInner({ widget }: CashFlowInnerProps) {
.rangeInclusive(earliestMonth, monthUtils.currentMonth())
.map(month => ({
name: month,
- pretty: monthUtils.format(month, 'MMMM, yyyy'),
+ pretty: monthUtils.format(month, 'MMMM, yyyy', locale),
}))
.reverse();
setAllMonths(allMonths);
}
run();
- }, []);
+ }, [locale]);
function onChangeDates(start: string, end: string, mode: TimeFrame['mode']) {
const numDays = d.differenceInCalendarDays(
diff --git a/packages/desktop-client/src/components/reports/reports/CustomReport.tsx b/packages/desktop-client/src/components/reports/reports/CustomReport.tsx
index 918d462dcd..9d3ef1eade 100644
--- a/packages/desktop-client/src/components/reports/reports/CustomReport.tsx
+++ b/packages/desktop-client/src/components/reports/reports/CustomReport.tsx
@@ -28,6 +28,7 @@ import { type TransObjectLiteral } from 'loot-core/types/util';
import { useAccounts } from '../../../hooks/useAccounts';
import { useCategories } from '../../../hooks/useCategories';
import { useFilters } from '../../../hooks/useFilters';
+import { useLocale } from '../../../hooks/useLocale';
import { useLocalPref } from '../../../hooks/useLocalPref';
import { useNavigate } from '../../../hooks/useNavigate';
import { usePayees } from '../../../hooks/usePayees';
@@ -122,6 +123,7 @@ type CustomReportInnerProps = {
};
function CustomReportInner({ report: initialReport }: CustomReportInnerProps) {
+ const locale = useLocale();
const { t } = useTranslation();
const categories = useCategories();
const { isNarrowWidth } = useResponsive();
@@ -319,6 +321,7 @@ function CustomReportInner({ report: initialReport }: CustomReportInnerProps) {
pretty: monthUtils.format(
inter,
ReportOptions.intervalFormat.get(interval) || '',
+ locale,
),
}))
.reverse();
@@ -345,6 +348,7 @@ function CustomReportInner({ report: initialReport }: CustomReportInnerProps) {
onApplyFilter,
report.conditions,
includeCurrentInterval,
+ locale,
]);
useEffect(() => {
diff --git a/packages/desktop-client/src/components/reports/reports/NetWorth.tsx b/packages/desktop-client/src/components/reports/reports/NetWorth.tsx
index b31a1c97ac..05c8f429f4 100644
--- a/packages/desktop-client/src/components/reports/reports/NetWorth.tsx
+++ b/packages/desktop-client/src/components/reports/reports/NetWorth.tsx
@@ -17,6 +17,7 @@ import { type TimeFrame, type NetWorthWidget } from 'loot-core/types/models';
import { useAccounts } from '../../../hooks/useAccounts';
import { useFilters } from '../../../hooks/useFilters';
+import { useLocale } from '../../../hooks/useLocale';
import { useNavigate } from '../../../hooks/useNavigate';
import { useSyncedPref } from '../../../hooks/useSyncedPref';
import { useDispatch } from '../../../redux';
@@ -54,6 +55,7 @@ type NetWorthInnerProps = {
};
function NetWorthInner({ widget }: NetWorthInnerProps) {
+ const locale = useLocale();
const dispatch = useDispatch();
const { t } = useTranslation();
@@ -80,8 +82,16 @@ function NetWorthInner({ widget }: NetWorthInnerProps) {
const [mode, setMode] = useState(initialMode);
const reportParams = useMemo(
- () => netWorthSpreadsheet(start, end, accounts, conditions, conditionsOp),
- [start, end, accounts, conditions, conditionsOp],
+ () =>
+ netWorthSpreadsheet(
+ start,
+ end,
+ accounts,
+ conditions,
+ conditionsOp,
+ locale,
+ ),
+ [start, end, accounts, conditions, conditionsOp, locale],
);
const data = useReport('net_worth', reportParams);
useEffect(() => {
@@ -104,14 +114,14 @@ function NetWorthInner({ widget }: NetWorthInnerProps) {
.rangeInclusive(earliestMonth, monthUtils.currentMonth())
.map(month => ({
name: month,
- pretty: monthUtils.format(month, 'MMMM, yyyy'),
+ pretty: monthUtils.format(month, 'MMMM, yyyy', locale),
}))
.reverse();
setAllMonths(allMonths);
}
run();
- }, []);
+ }, [locale]);
function onChangeDates(start: string, end: string, mode: TimeFrame['mode']) {
setStart(start);
diff --git a/packages/desktop-client/src/components/reports/reports/NetWorthCard.tsx b/packages/desktop-client/src/components/reports/reports/NetWorthCard.tsx
index 29361f2323..1f19870eb7 100644
--- a/packages/desktop-client/src/components/reports/reports/NetWorthCard.tsx
+++ b/packages/desktop-client/src/components/reports/reports/NetWorthCard.tsx
@@ -11,6 +11,7 @@ import {
type NetWorthWidget,
} from 'loot-core/types/models';
+import { useLocale } from '../../../hooks/useLocale';
import { PrivacyFilter } from '../../PrivacyFilter';
import { useResponsive } from '../../responsive/ResponsiveProvider';
import { Change } from '../Change';
@@ -40,6 +41,7 @@ export function NetWorthCard({
onMetaChange,
onRemove,
}: NetWorthCardProps) {
+ const locale = useLocale();
const { t } = useTranslation();
const { isNarrowWidth } = useResponsive();
@@ -58,8 +60,9 @@ export function NetWorthCard({
accounts,
meta?.conditions,
meta?.conditionsOp,
+ locale,
),
- [start, end, accounts, meta?.conditions, meta?.conditionsOp],
+ [start, end, accounts, meta?.conditions, meta?.conditionsOp, locale],
);
const data = useReport('net_worth', params);
diff --git a/packages/desktop-client/src/components/reports/reports/Spending.tsx b/packages/desktop-client/src/components/reports/reports/Spending.tsx
index e11aa372e8..7ea6befb92 100644
--- a/packages/desktop-client/src/components/reports/reports/Spending.tsx
+++ b/packages/desktop-client/src/components/reports/reports/Spending.tsx
@@ -23,6 +23,7 @@ import { type SpendingWidget } from 'loot-core/types/models';
import { type RuleConditionEntity } from 'loot-core/types/models/rule';
import { useFilters } from '../../../hooks/useFilters';
+import { useLocale } from '../../../hooks/useLocale';
import { useNavigate } from '../../../hooks/useNavigate';
import { useDispatch } from '../../../redux';
import { Select } from '../../common/Select';
@@ -61,6 +62,7 @@ type SpendingInternalProps = {
};
function SpendingInternal({ widget }: SpendingInternalProps) {
+ const locale = useLocale();
const dispatch = useDispatch();
const { t } = useTranslation();
@@ -109,14 +111,14 @@ function SpendingInternal({ widget }: SpendingInternalProps) {
.rangeInclusive(earliestMonth, monthUtils.currentMonth())
.map(month => ({
name: month,
- pretty: monthUtils.format(month, 'MMMM, yyyy'),
+ pretty: monthUtils.format(month, 'MMMM, yyyy', locale),
}))
.reverse();
setAllIntervals(allMonths);
}
run();
- }, []);
+ }, [locale]);
const getGraphData = useMemo(
() =>
@@ -448,14 +450,14 @@ function SpendingInternal({ widget }: SpendingInternalProps) {
<View>
<LegendItem
color={theme.reportsGreen}
- label={monthUtils.format(compare, 'MMM, yyyy')}
+ label={monthUtils.format(compare, 'MMM, yyyy', locale)}
style={{ padding: 0, paddingBottom: 10 }}
/>
<LegendItem
color={theme.reportsGray}
label={
reportMode === 'single-month'
- ? monthUtils.format(compareTo, 'MMM, yyyy')
+ ? monthUtils.format(compareTo, 'MMM, yyyy', locale)
: reportMode === 'budget'
? t('Budgeted')
: t('Average')
@@ -481,12 +483,14 @@ function SpendingInternal({ widget }: SpendingInternalProps) {
monthYearFormatted: monthUtils.format(
compare,
'MMM, yyyy',
+ locale,
),
})
: t('Spent {{monthYearFormatted}}:', {
monthYearFormatted: monthUtils.format(
compare,
'MMM, yyyy',
+ locale,
),
})}
:
@@ -513,12 +517,14 @@ function SpendingInternal({ widget }: SpendingInternalProps) {
monthYearFormatted: monthUtils.format(
compare,
'MMM, yyyy',
+ locale,
),
})
: t('Spent {{monthYearFormatted}}:', {
monthYearFormatted: monthUtils.format(
compare,
'MMM, yyyy',
+ locale,
),
})}
</Block>
diff --git a/packages/desktop-client/src/components/reports/reports/Summary.tsx b/packages/desktop-client/src/components/reports/reports/Summary.tsx
index 25ceea228e..c65b8708fd 100644
--- a/packages/desktop-client/src/components/reports/reports/Summary.tsx
+++ b/packages/desktop-client/src/components/reports/reports/Summary.tsx
@@ -26,6 +26,7 @@ import {
} from 'loot-core/types/models';
import { useFilters } from '../../../hooks/useFilters';
+import { useLocale } from '../../../hooks/useLocale';
import { useNavigate } from '../../../hooks/useNavigate';
import { useSyncedPref } from '../../../hooks/useSyncedPref';
import { useDispatch } from '../../../redux';
@@ -67,6 +68,7 @@ type SummaryInnerProps = {
type FilterObject = ReturnType<typeof useFilters>;
function SummaryInner({ widget }: SummaryInnerProps) {
+ const locale = useLocale();
const { t } = useTranslation();
const [initialStart, initialEnd, initialMode] = calculateTimeRange(
widget?.meta?.timeFrame,
@@ -123,6 +125,7 @@ function SummaryInner({ widget }: SummaryInnerProps) {
dividendFilters.conditions,
dividendFilters.conditionsOp,
content,
+ locale,
),
[
start,
@@ -130,6 +133,7 @@ function SummaryInner({ widget }: SummaryInnerProps) {
dividendFilters.conditions,
dividendFilters.conditionsOp,
content,
+ locale,
],
);
@@ -174,14 +178,14 @@ function SummaryInner({ widget }: SummaryInnerProps) {
.rangeInclusive(earliestMonth, monthUtils.currentMonth())
.map(month => ({
name: month,
- pretty: monthUtils.format(month, 'MMMM, yyyy'),
+ pretty: monthUtils.format(month, 'MMMM, yyyy', locale),
}))
.reverse();
setAllMonths(allMonths);
}
run();
- }, []);
+ }, [locale]);
const dispatch = useDispatch();
const navigate = useNavigate();
diff --git a/packages/desktop-client/src/components/reports/reports/SummaryCard.tsx b/packages/desktop-client/src/components/reports/reports/SummaryCard.tsx
index 0ec4c9190c..47c8764612 100644
--- a/packages/desktop-client/src/components/reports/reports/SummaryCard.tsx
+++ b/packages/desktop-client/src/components/reports/reports/SummaryCard.tsx
@@ -9,6 +9,7 @@ import {
type SummaryWidget,
} from 'loot-core/types/models';
+import { useLocale } from '../../../hooks/useLocale';
import { DateRange } from '../DateRange';
import { LoadingIndicator } from '../LoadingIndicator';
import { ReportCard } from '../ReportCard';
@@ -33,6 +34,7 @@ export function SummaryCard({
onMetaChange,
onRemove,
}: SummaryCardProps) {
+ const locale = useLocale();
const { t } = useTranslation();
const [start, end] = calculateTimeRange(meta?.timeFrame, {
start: monthUtils.dayFromDate(monthUtils.currentMonth()),
@@ -63,8 +65,9 @@ export function SummaryCard({
meta?.conditions,
meta?.conditionsOp,
content,
+ locale,
),
- [start, end, meta?.conditions, meta?.conditionsOp, content],
+ [start, end, meta?.conditions, meta?.conditionsOp, content, locale],
);
const data = useReport('summary', params);
diff --git a/packages/desktop-client/src/components/reports/spreadsheets/cash-flow-spreadsheet.tsx b/packages/desktop-client/src/components/reports/spreadsheets/cash-flow-spreadsheet.tsx
index c291b4ba48..151a97267c 100644
--- a/packages/desktop-client/src/components/reports/spreadsheets/cash-flow-spreadsheet.tsx
+++ b/packages/desktop-client/src/components/reports/spreadsheets/cash-flow-spreadsheet.tsx
@@ -73,6 +73,7 @@ export function cashFlowByDate(
isConcise: boolean,
conditions: RuleConditionEntity[] = [],
conditionsOp: 'and' | 'or',
+ locale: Locale,
) {
const start = monthUtils.firstDayOfMonth(startMonth);
const end = monthUtils.lastDayOfMonth(endMonth);
@@ -133,7 +134,7 @@ export function cashFlowByDate(
makeQuery().filter({ amount: { $lt: 0 } }),
],
data => {
- setData(recalculate(data, start, fixedEnd, isConcise));
+ setData(recalculate(data, start, fixedEnd, isConcise, locale));
},
);
};
@@ -148,6 +149,7 @@ function recalculate(
start: string,
end: string,
isConcise: boolean,
+ locale: Locale,
) {
const [startingBalance, income, expense] = data;
const convIncome = income.map(trans => {
@@ -206,7 +208,9 @@ function recalculate(
<div>
<div style={{ marginBottom: 10 }}>
<strong>
- {d.format(x, isConcise ? 'MMMM yyyy' : 'MMMM d, yyyy')}
+ {d.format(x, isConcise ? 'MMMM yyyy' : 'MMMM d, yyyy', {
+ locale,
+ })}
</strong>
</div>
<div style={{ lineHeight: 1.5 }}>
diff --git a/packages/desktop-client/src/components/reports/spreadsheets/net-worth-spreadsheet.ts b/packages/desktop-client/src/components/reports/spreadsheets/net-worth-spreadsheet.ts
index 2f36a2000c..c754640738 100644
--- a/packages/desktop-client/src/components/reports/spreadsheets/net-worth-spreadsheet.ts
+++ b/packages/desktop-client/src/components/reports/spreadsheets/net-worth-spreadsheet.ts
@@ -27,6 +27,7 @@ export function createSpreadsheet(
accounts: AccountEntity[],
conditions: RuleConditionEntity[] = [],
conditionsOp: 'and' | 'or' = 'and',
+ locale: Locale,
) {
return async (
spreadsheet: ReturnType<typeof useSpreadsheet>,
@@ -78,7 +79,7 @@ export function createSpreadsheet(
}),
);
- setData(recalculate(data, start, end));
+ setData(recalculate(data, start, end, locale));
};
}
@@ -90,6 +91,7 @@ function recalculate(
}>,
start: string,
end: string,
+ locale: Locale,
) {
const months = monthUtils.rangeInclusive(start, end);
@@ -149,13 +151,13 @@ function recalculate(
endNetWorth = total;
arr.push({
- x: d.format(x, 'MMM ’yy'),
+ x: d.format(x, 'MMM ’yy', { locale }),
y: integerToAmount(total),
assets: integerToCurrency(assets),
debt: `-${integerToCurrency(debt)}`,
change: integerToCurrency(change),
networth: integerToCurrency(total),
- date: d.format(x, 'MMMM yyyy'),
+ date: d.format(x, 'MMMM yyyy', { locale }),
});
arr.forEach(item => {
diff --git a/packages/desktop-client/src/components/reports/spreadsheets/summary-spreadsheet.ts b/packages/desktop-client/src/components/reports/spreadsheets/summary-spreadsheet.ts
index 68fa418c09..07fb5d4168 100644
--- a/packages/desktop-client/src/components/reports/spreadsheets/summary-spreadsheet.ts
+++ b/packages/desktop-client/src/components/reports/spreadsheets/summary-spreadsheet.ts
@@ -16,6 +16,7 @@ export function summarySpreadsheet(
conditions: RuleConditionEntity[] = [],
conditionsOp: 'and' | 'or' = 'and',
summaryContent: SummaryContent,
+ locale: Locale,
) {
return async (
spreadsheet: ReturnType<typeof useSpreadsheet>,
@@ -121,8 +122,8 @@ export function summarySpreadsheet(
}
const dateRanges = {
- fromRange: d.format(startDay, 'MMM yy'),
- toRange: d.format(endDay, 'MMM yy'),
+ fromRange: d.format(startDay, 'MMM yy', { locale }),
+ toRange: d.format(endDay, 'MMM yy', { locale }),
};
switch (summaryContent.type) {
diff --git a/packages/desktop-client/src/components/rules/Value.tsx b/packages/desktop-client/src/components/rules/Value.tsx
index 101e186681..b7f173567c 100644
--- a/packages/desktop-client/src/components/rules/Value.tsx
+++ b/packages/desktop-client/src/components/rules/Value.tsx
@@ -12,6 +12,7 @@ import { integerToCurrency } from 'loot-core/shared/util';
import { useAccounts } from '../../hooks/useAccounts';
import { useCategories } from '../../hooks/useCategories';
import { useDateFormat } from '../../hooks/useDateFormat';
+import { useLocale } from '../../hooks/useLocale';
import { usePayees } from '../../hooks/usePayees';
import { theme } from '../../style';
import { Link } from '../common/Link';
@@ -45,6 +46,7 @@ export function Value<T>({
color: theme.pageTextPositive,
...style,
};
+ const locale = useLocale();
const data =
dataProp ||
@@ -75,7 +77,7 @@ export function Value<T>({
case 'date':
if (value) {
if (value.frequency) {
- return getRecurringDescription(value, dateFormat);
+ return getRecurringDescription(value, dateFormat, locale);
}
return formatDate(parseISO(value), dateFormat);
}
diff --git a/packages/desktop-client/src/components/schedules/DiscoverSchedules.tsx b/packages/desktop-client/src/components/schedules/DiscoverSchedules.tsx
index 54a39d9a33..3ba77f8936 100644
--- a/packages/desktop-client/src/components/schedules/DiscoverSchedules.tsx
+++ b/packages/desktop-client/src/components/schedules/DiscoverSchedules.tsx
@@ -14,6 +14,7 @@ import { getRecurringDescription } from 'loot-core/shared/schedules';
import type { DiscoverScheduleEntity } from 'loot-core/types/models';
import { useDateFormat } from '../../hooks/useDateFormat';
+import { useLocale } from '../../hooks/useLocale';
import {
useSelected,
useSelectedDispatch,
@@ -42,11 +43,16 @@ function DiscoverSchedulesTable({
const selectedItems = useSelectedItems();
const dispatchSelected = useSelectedDispatch();
const dateFormat = useDateFormat() || 'MM/dd/yyyy';
+ const locale = useLocale();
function renderItem({ item }: { item: DiscoverScheduleEntity }) {
const selected = selectedItems.has(item.id);
const amountOp = item._conditions.find(c => c.field === 'amount').op;
- const recurDescription = getRecurringDescription(item.date, dateFormat);
+ const recurDescription = getRecurringDescription(
+ item.date,
+ dateFormat,
+ locale,
+ );
return (
<Row
diff --git a/packages/desktop-client/src/components/schedules/ScheduleDetails.tsx b/packages/desktop-client/src/components/schedules/ScheduleDetails.tsx
index 0f5eeae317..976fc5e3d7 100644
--- a/packages/desktop-client/src/components/schedules/ScheduleDetails.tsx
+++ b/packages/desktop-client/src/components/schedules/ScheduleDetails.tsx
@@ -27,6 +27,7 @@ import {
} from 'loot-core/types/models';
import { useDateFormat } from '../../hooks/useDateFormat';
+import { useLocale } from '../../hooks/useLocale';
import { usePayees } from '../../hooks/usePayees';
import { useSelected, SelectedProvider } from '../../hooks/useSelected';
import { useDispatch } from '../../redux';
@@ -109,6 +110,7 @@ type ScheduleDetailsProps = Extract<
>['options'];
export function ScheduleDetails({ id, transaction }: ScheduleDetailsProps) {
+ const locale = useLocale();
const { t } = useTranslation();
const adding = id == null;
@@ -749,7 +751,7 @@ export function ScheduleDetails({ id, transaction }: ScheduleDetailsProps) {
>
{state.upcomingDates.map(date => (
<View key={date}>
- {monthUtils.format(date, `${dateFormat} EEEE`)}
+ {monthUtils.format(date, `${dateFormat} EEEE`, locale)}
</View>
))}
</Stack>
diff --git a/packages/desktop-client/src/components/select/DateSelect.tsx b/packages/desktop-client/src/components/select/DateSelect.tsx
index fe76db19e4..42e19da62d 100644
--- a/packages/desktop-client/src/components/select/DateSelect.tsx
+++ b/packages/desktop-client/src/components/select/DateSelect.tsx
@@ -29,6 +29,7 @@ import {
currentDate,
} from 'loot-core/shared/months';
+import { useLocale } from '../../hooks/useLocale';
import { useSyncedPref } from '../../hooks/useSyncedPref';
import { theme, type CSSProperties } from '../../style';
import { Input } from '../common/Input';
@@ -81,6 +82,39 @@ const pickerStyles: CSSProperties = {
},
};
+type PikadayI18n = {
+ previousMonth: string;
+ nextMonth: string;
+ months: string[];
+ weekdays: string[];
+ weekdaysShort: string[];
+};
+
+function createPikadayLocale(dateFnsLocale: Locale): PikadayI18n {
+ const months = Array.from({ length: 12 }, (_, i) =>
+ format(new Date(2023, i, 1), 'MMMM', { locale: dateFnsLocale }),
+ );
+
+ const weekdays = Array.from({ length: 7 }, (_, i) =>
+ format(new Date(2023, 0, i + 1), 'EEEE', { locale: dateFnsLocale }),
+ );
+
+ const weekdaysShort = Array.from({ length: 7 }, (_, i) =>
+ format(new Date(2023, 0, i + 1), 'EEE', { locale: dateFnsLocale }).slice(
+ 0,
+ 3,
+ ),
+ );
+
+ return {
+ previousMonth: 'Previous',
+ nextMonth: 'Next',
+ months,
+ weekdays,
+ weekdaysShort,
+ };
+}
+
type DatePickerProps = {
value: string;
firstDayOfWeekIdx: string;
@@ -94,6 +128,7 @@ type DatePickerForwardedRef = {
};
const DatePicker = forwardRef<DatePickerForwardedRef, DatePickerProps>(
({ value, firstDayOfWeekIdx, dateFormat, onUpdate, onSelect }, ref) => {
+ const locale = useLocale();
const picker = useRef(null);
const mountPoint = useRef(null);
@@ -132,6 +167,8 @@ const DatePicker = forwardRef<DatePickerForwardedRef, DatePickerProps>(
);
useLayoutEffect(() => {
+ const pikadayLocale = createPikadayLocale(locale);
+
picker.current = new Pikaday({
theme: 'actual-date-picker',
keyboardInput: false,
@@ -147,6 +184,7 @@ const DatePicker = forwardRef<DatePickerForwardedRef, DatePickerProps>(
return parse(dateString, dateFormat, new Date());
},
onSelect,
+ i18n: pikadayLocale,
});
mountPoint.current.appendChild(picker.current.el);
diff --git a/packages/desktop-client/src/components/select/RecurringSchedulePicker.tsx b/packages/desktop-client/src/components/select/RecurringSchedulePicker.tsx
index 291abefc40..3e5adfff56 100644
--- a/packages/desktop-client/src/components/select/RecurringSchedulePicker.tsx
+++ b/packages/desktop-client/src/components/select/RecurringSchedulePicker.tsx
@@ -2,6 +2,7 @@ import {
type CSSProperties,
type Dispatch,
useEffect,
+ useMemo,
useReducer,
useRef,
useState,
@@ -26,6 +27,7 @@ import {
} from 'loot-core/types/util';
import { useDateFormat } from '../../hooks/useDateFormat';
+import { useLocale } from '../../hooks/useLocale';
import { SvgAdd, SvgSubtract } from '../../icons/v0';
import { theme } from '../../style';
import { Input } from '../common/Input';
@@ -240,6 +242,7 @@ function SchedulePreview({
}: {
previewDates: string[] | string;
}) {
+ const locale = useLocale();
const dateFormat = (useDateFormat() || 'MM/dd/yyyy')
.replace('MM', 'M')
.replace('dd', 'd');
@@ -254,12 +257,14 @@ function SchedulePreview({
} else {
content = (
<View>
- <Text style={{ fontWeight: 600 }}>Upcoming dates</Text>
+ <Text style={{ fontWeight: 600 }}>
+ <Trans>Upcoming dates</Trans>
+ </Text>
<Stack direction="row" spacing={4} style={{ marginTop: 10 }}>
{previewDates.map((d, idx) => (
<View key={idx}>
- <Text>{monthUtils.format(d, dateFormat)}</Text>
- <Text>{monthUtils.format(d, 'EEEE')}</Text>
+ <Text>{monthUtils.format(d, dateFormat, locale)}</Text>
+ <Text>{monthUtils.format(d, 'EEEE', locale)}</Text>
</View>
))}
</Stack>
@@ -409,10 +414,10 @@ function RecurringScheduleTooltip({
config: unparseConfig(config),
count: 4,
});
- setPreviewDates(error ? 'Invalid rule' : data);
+ setPreviewDates(error ? t('Invalid rule') : data);
}
run();
- }, [config]);
+ }, [config, t]);
if (previewDates == null) {
return null;
@@ -427,7 +432,7 @@ function RecurringScheduleTooltip({
<InitialFocus>
<DateSelect
id="start"
- inputProps={{ placeholder: 'Start Date' }}
+ inputProps={{ placeholder: t('Start Date') }}
value={config.start}
onSelect={value => updateField('start', value)}
containerProps={{ style: { width: 100 } }}
@@ -437,9 +442,9 @@ function RecurringScheduleTooltip({
<Select
id="repeat_end_dropdown"
options={[
- ['never', 'indefinitely'],
- ['after_n_occurrences', 'for'],
- ['on_date', 'until'],
+ ['never', t('indefinitely')],
+ ['after_n_occurrences', t('for')],
+ ['on_date', t('until')],
]}
value={config.endMode}
onChange={value => updateField('endMode', value)}
@@ -454,7 +459,11 @@ function RecurringScheduleTooltip({
onChange={e => updateField('endOccurrences', e.target.value)}
defaultValue={config.endOccurrences || 1}
/>
- <Text>occurrence{config.endOccurrences === '1' ? '' : 's'}</Text>
+ {config.endOccurrences === '1' ? (
+ <Trans>ocurrence</Trans>
+ ) : (
+ <Trans>ocurrences</Trans>
+ )}
</>
)}
{config.endMode === 'on_date' && (
@@ -540,8 +549,8 @@ function RecurringScheduleTooltip({
<Select
id="solve_dropdown"
options={[
- ['before', 'before'],
- ['after', 'after'],
+ ['before', t('before')],
+ ['after', t('after')],
]}
value={state.config.weekendSolveMode}
onChange={value => dispatch({ type: 'set-weekend-solve', value })}
@@ -591,12 +600,18 @@ export function RecurringSchedulePicker({
const triggerRef = useRef(null);
const [isOpen, setIsOpen] = useState(false);
const dateFormat = useDateFormat() || 'MM/dd/yyyy';
+ const locale = useLocale();
function onSave(config: RecurConfig) {
onChange(config);
setIsOpen(false);
}
+ const recurringDescription = useMemo(
+ () => getRecurringDescription(value, dateFormat, locale),
+ [locale, value, dateFormat],
+ );
+
return (
<View>
<Button
@@ -604,9 +619,7 @@ export function RecurringSchedulePicker({
style={{ textAlign: 'left', ...buttonStyle }}
onPress={() => setIsOpen(true)}
>
- {value
- ? getRecurringDescription(value, dateFormat)
- : t('No recurring date')}
+ {value ? recurringDescription : t('No recurring date')}
</Button>
<Popover
diff --git a/packages/desktop-client/src/components/settings/LanguageSettings.tsx b/packages/desktop-client/src/components/settings/LanguageSettings.tsx
index ab479f4cb8..60b5d785e0 100644
--- a/packages/desktop-client/src/components/settings/LanguageSettings.tsx
+++ b/packages/desktop-client/src/components/settings/LanguageSettings.tsx
@@ -12,6 +12,10 @@ import { Select, type SelectOption } from '../common/Select';
import { Setting } from './UI';
+const languageDisplayNameOverride: { [key: string]: string } = {
+ 'pt-BR': 'Português (Brasil)',
+};
+
const languageOptions = (t: TFunction): SelectOption[] =>
[
['', t('System default')] as [string, string],
@@ -19,9 +23,11 @@ const languageOptions = (t: TFunction): SelectOption[] =>
].concat(
availableLanguages.map(lang => [
lang,
- new Intl.DisplayNames([lang], {
- type: 'language',
- }).of(lang) || lang,
+ lang in languageDisplayNameOverride
+ ? languageDisplayNameOverride[lang]
+ : new Intl.DisplayNames([lang], {
+ type: 'language',
+ }).of(lang) || lang,
]),
);
diff --git a/packages/desktop-client/src/hooks/useLocale.ts b/packages/desktop-client/src/hooks/useLocale.ts
new file mode 100644
index 0000000000..c0f9b67c7d
--- /dev/null
+++ b/packages/desktop-client/src/hooks/useLocale.ts
@@ -0,0 +1,14 @@
+import { useMemo } from 'react';
+
+import { getLocale } from 'loot-core/shared/locale';
+
+import { useGlobalPref } from './useGlobalPref';
+
+export function useLocale() {
+ const [language] = useGlobalPref('language');
+ const locale = useMemo(
+ () => getLocale(language ? language : (navigator.language ?? 'en-US')),
+ [language],
+ );
+ return locale;
+}
diff --git a/packages/loot-core/src/server/budget/actions.ts b/packages/loot-core/src/server/budget/actions.ts
index 69b5292674..27bd6838cd 100644
--- a/packages/loot-core/src/server/budget/actions.ts
+++ b/packages/loot-core/src/server/budget/actions.ts
@@ -1,5 +1,7 @@
// @ts-strict-ignore
+import * as asyncStorage from '../../platform/server/asyncStorage';
+import { getLocale } from '../../shared/locale';
import * as monthUtils from '../../shared/months';
import { integerToCurrency, safeNumber } from '../../shared/util';
import * as db from '../db';
@@ -561,7 +563,12 @@ async function addMovementNotes({
)?.note,
);
- const displayDay = monthUtils.format(monthUtils.currentDate(), 'MMMM dd');
+ const locale = getLocale(await asyncStorage.getItem('language'));
+ const displayDay = monthUtils.format(
+ monthUtils.currentDate(),
+ 'MMMM dd',
+ locale,
+ );
const categories = await db.getCategories(
[from, to].filter(c => c !== 'to-be-budgeted' && c !== 'overbudgeted'),
);
diff --git a/packages/loot-core/src/shared/locale.ts b/packages/loot-core/src/shared/locale.ts
new file mode 100644
index 0000000000..49c48014d8
--- /dev/null
+++ b/packages/loot-core/src/shared/locale.ts
@@ -0,0 +1,22 @@
+import * as locales from 'date-fns/locale';
+
+export function getLocale(language: string) {
+ if (!language || typeof language !== 'string') {
+ return locales.enUS;
+ }
+
+ let localeKey = language.replace('-', '') as keyof typeof locales;
+
+ if (localeKey in locales) {
+ return locales[localeKey];
+ }
+
+ //if language was not found with four letters, try with two
+ localeKey = language.replace('-', '').substring(0, 2) as keyof typeof locales;
+
+ if (localeKey in locales) {
+ return locales[localeKey];
+ }
+
+ return locales.enUS;
+}
diff --git a/packages/loot-core/src/shared/months.ts b/packages/loot-core/src/shared/months.ts
index f8c2db2726..9986caa216 100644
--- a/packages/loot-core/src/shared/months.ts
+++ b/packages/loot-core/src/shared/months.ts
@@ -393,12 +393,16 @@ export function sheetForMonth(month: string): string {
return 'budget' + month.replace('-', '');
}
-export function nameForMonth(month: DateLike): string {
- return d.format(_parse(month), 'MMMM ‘yy');
+export function nameForMonth(month: DateLike, locale?: Locale): string {
+ return d.format(_parse(month), 'MMMM ‘yy', { locale });
}
-export function format(month: DateLike, format: string): string {
- return d.format(_parse(month), format);
+export function format(
+ month: DateLike,
+ format: string,
+ locale?: Locale,
+): string {
+ return d.format(_parse(month), format, { locale });
}
export const getDateFormatRegex = memoizeOne((format: string) => {
diff --git a/packages/loot-core/src/shared/rules.ts b/packages/loot-core/src/shared/rules.ts
index 82c837fe17..0fd8c6a74e 100644
--- a/packages/loot-core/src/shared/rules.ts
+++ b/packages/loot-core/src/shared/rules.ts
@@ -140,6 +140,22 @@ export function mapField(field, opts?) {
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 'notes':
+ return t('notes');
+ case 'payee':
+ return t('payee');
+ case 'saved':
+ return t('saved');
+ case 'cleared':
+ return t('cleared');
+ case 'reconciled':
+ return t('reconciled');
default:
return field;
}
@@ -204,11 +220,11 @@ export function friendlyOp(op, type?) {
case 'and':
return t('and');
case 'or':
- return 'or';
+ return t('or');
case 'onBudget':
- return 'is on budget';
+ return t('is on budget');
case 'offBudget':
- return 'is off budget';
+ return t('is off budget');
default:
return '';
}
diff --git a/packages/loot-core/src/shared/schedules.test.ts b/packages/loot-core/src/shared/schedules.test.ts
index 69b55ae12e..143c6dc6e1 100644
--- a/packages/loot-core/src/shared/schedules.test.ts
+++ b/packages/loot-core/src/shared/schedules.test.ts
@@ -1,3 +1,5 @@
+import { enUS } from 'date-fns/locale';
+import i18next from 'i18next';
import MockDate from 'mockdate';
import * as monthUtils from './months';
@@ -7,6 +9,54 @@ import {
getUpcomingDays,
} from './schedules';
+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';
@@ -70,6 +120,7 @@ describe('schedules', () => {
getRecurringDescription(
{ start: '2021-05-17', frequency: 'weekly' },
'MM/dd/yyyy',
+ enUS,
),
).toBe('Every week on Monday');
@@ -81,6 +132,7 @@ describe('schedules', () => {
interval: 2,
},
'MM/dd/yyyy',
+ enUS,
),
).toBe('Every 2 weeks on Monday');
});
@@ -90,6 +142,7 @@ describe('schedules', () => {
getRecurringDescription(
{ start: '2021-04-25', frequency: 'monthly' },
'MM/dd/yyyy',
+ enUS,
),
).toBe('Every month on the 25th');
@@ -101,6 +154,7 @@ describe('schedules', () => {
interval: 2,
},
'MM/dd/yyyy',
+ enUS,
),
).toBe('Every 2 months on the 25th');
@@ -112,6 +166,7 @@ describe('schedules', () => {
patterns: [{ type: 'day', value: 25 }],
},
'MM/dd/yyyy',
+ enUS,
),
).toBe('Every month on the 25th');
@@ -124,6 +179,7 @@ describe('schedules', () => {
patterns: [{ type: 'day', value: 25 }],
},
'MM/dd/yyyy',
+ enUS,
),
).toBe('Every 2 months on the 25th');
@@ -136,6 +192,7 @@ describe('schedules', () => {
patterns: [{ type: 'day', value: 31 }],
},
'MM/dd/yyyy',
+ enUS,
),
).toBe('Every month on the 31st');
@@ -148,6 +205,7 @@ describe('schedules', () => {
patterns: [{ type: 'day', value: -1 }],
},
'MM/dd/yyyy',
+ enUS,
),
).toBe('Every month on the last day');
@@ -160,6 +218,7 @@ describe('schedules', () => {
patterns: [{ type: 'FR', value: 2 }],
},
'MM/dd/yyyy',
+ enUS,
),
).toBe('Every month on the 2nd Friday');
@@ -171,6 +230,7 @@ describe('schedules', () => {
patterns: [{ type: 'FR', value: -1 }],
},
'MM/dd/yyyy',
+ enUS,
),
).toBe('Every month on the last Friday');
});
@@ -189,6 +249,7 @@ describe('schedules', () => {
],
},
'MM/dd/yyyy',
+ enUS,
),
).toBe('Every month on the 3rd, 15th, and 20th');
@@ -204,6 +265,7 @@ describe('schedules', () => {
],
},
'MM/dd/yyyy',
+ enUS,
),
).toBe('Every month on the 3rd, 20th, and last day');
@@ -220,6 +282,7 @@ describe('schedules', () => {
],
},
'MM/dd/yyyy',
+ enUS,
),
).toBe('Every month on the 2nd Friday, 3rd, and last day');
@@ -237,6 +300,7 @@ describe('schedules', () => {
],
},
'MM/dd/yyyy',
+ enUS,
),
).toBe('Every month on the 1st Saturday, 3rd Friday, 2nd, and 10th');
});
@@ -246,6 +310,7 @@ describe('schedules', () => {
getRecurringDescription(
{ start: '2021-05-17', frequency: 'yearly' },
'MM/dd/yyyy',
+ enUS,
),
).toBe('Every year on May 17th');
@@ -257,6 +322,7 @@ describe('schedules', () => {
interval: 2,
},
'MM/dd/yyyy',
+ enUS,
),
).toBe('Every 2 years on May 17th');
});
@@ -272,6 +338,7 @@ describe('schedules', () => {
endOccurrences: 2,
},
'MM/dd/yyyy',
+ enUS,
),
).toBe('Every 2 weeks on Monday, 2 times');
@@ -285,6 +352,7 @@ describe('schedules', () => {
endOccurrences: 1,
},
'MM/dd/yyyy',
+ enUS,
),
).toBe('Every 2 weeks on Monday, once');
@@ -298,6 +366,7 @@ describe('schedules', () => {
endOccurrences: 2,
},
'MM/dd/yyyy',
+ enUS,
),
).toBe('Every 2 months on the 17th, 2 times');
@@ -311,6 +380,7 @@ describe('schedules', () => {
endOccurrences: 2,
},
'MM/dd/yyyy',
+ enUS,
),
).toBe('Every 2 years on May 17th, 2 times');
});
@@ -326,6 +396,7 @@ describe('schedules', () => {
endDate: '2021-06-01',
},
'MM/dd/yyyy',
+ enUS,
),
).toBe('Every 2 weeks on Monday, until 06/01/2021');
@@ -339,6 +410,7 @@ describe('schedules', () => {
endDate: '2021-06-01',
},
'yyyy-MM-dd',
+ enUS,
),
).toBe('Every 2 months on the 17th, until 2021-06-01');
});
diff --git a/packages/loot-core/src/shared/schedules.ts b/packages/loot-core/src/shared/schedules.ts
index d41370c2f2..4fbc9a8edf 100644
--- a/packages/loot-core/src/shared/schedules.ts
+++ b/packages/loot-core/src/shared/schedules.ts
@@ -1,6 +1,7 @@
// @ts-strict-ignore
import type { IRuleOptions } from '@rschedule/core';
import * as d from 'date-fns';
+import { t } from 'i18next';
import { Condition } from '../server/rules';
@@ -56,67 +57,79 @@ export function getHasTransactionsQuery(schedules) {
.select(['schedule', 'date']);
}
-function makeNumberSuffix(num: number) {
+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');
+ return monthUtils.format(new Date(2020, 0, num, 12), 'do', locale);
}
function prettyDayName(day) {
const days = {
- SU: 'Sunday',
- MO: 'Monday',
- TU: 'Tuesday',
- WE: 'Wednesday',
- TH: 'Thursday',
- FR: 'Friday',
- SA: 'Saturday',
+ 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, dateFormat) {
+export function getRecurringDescription(config, dateFormat, locale: Locale) {
const interval = config.interval || 1;
let endModeSuffix = '';
switch (config.endMode) {
case 'after_n_occurrences':
if (config.endOccurrences === 1) {
- endModeSuffix = `, once`;
+ endModeSuffix = t('once');
} else {
- endModeSuffix = `, ${config.endOccurrences} times`;
+ endModeSuffix = t('{{endOccurrences}} times', {
+ endOccurrences: config.endOccurrences,
+ });
}
break;
case 'on_date':
- endModeSuffix = `, until ${monthUtils.format(
- config.endDate,
- dateFormat,
- )}`;
+ endModeSuffix = t('until {{dateFormatted}}', {
+ dateFormatted: monthUtils.format(config.endDate, dateFormat),
+ });
break;
default:
}
- const weekendSolveSuffix = config.skipWeekend
- ? ` (${config.weekendSolveMode} weekend) `
+ const weekendSolveModeString = config.weekendSolveMode
+ ? config.weekendSolveMode === 'after'
+ ? t('(after weekend)')
+ : t('(before weekend)')
: '';
- const suffix = endModeSuffix + weekendSolveSuffix;
- switch (config.frequency) {
- case 'daily': {
- let desc = 'Every ';
- desc += interval !== 1 ? `${interval} days` : 'day';
- return desc + suffix;
- }
- case 'weekly': {
- let desc = 'Every ';
- desc += interval !== 1 ? `${interval} weeks` : 'week';
- desc += ' on ' + monthUtils.format(config.start, 'EEEE');
- return desc + suffix;
- }
- case 'monthly': {
- let desc = 'Every ';
- desc += interval !== 1 ? `${interval} months` : 'month';
+ 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
@@ -137,60 +150,81 @@ export function getRecurringDescription(config, dateFormat) {
// Add on all -1 values to the end
patterns = patterns.concat(config.patterns.filter(p => p.value === -1));
- desc += ' on the ';
-
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('last day');
+ strs.push(t('last day'));
} else {
// Example: 15th day
- strs.push(makeNumberSuffix(pattern.value));
+ strs.push(makeNumberSuffix(pattern.value, locale));
}
} else {
const dayName = isSameDay ? '' : ' ' + prettyDayName(pattern.type);
if (pattern.value === -1) {
// Example: last Monday
- strs.push('last' + dayName);
+ strs.push(t('last') + dayName);
} else {
// Example: 3rd Monday
- strs.push(makeNumberSuffix(pattern.value) + dayName);
+ strs.push(makeNumberSuffix(pattern.value, locale) + dayName);
}
}
}
+ let range = '';
if (strs.length > 2) {
- desc += strs.slice(0, strs.length - 1).join(', ');
- desc += ', and ';
- desc += strs[strs.length - 1];
+ range += strs.slice(0, strs.length - 1).join(', ');
+ range += `, ${t('and')} `;
+ range += strs[strs.length - 1];
} else {
- desc += strs.join(' and ');
+ range += strs.join(` ${t('and')} `);
}
if (isSameDay) {
- desc += ' ' + prettyDayName(patterns[0].type);
+ 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 += ' on the ' + monthUtils.format(config.start, 'do');
+ 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;
- return desc + suffix;
- }
- case 'yearly': {
- let desc = 'Every ';
- desc += interval !== 1 ? `${interval} years` : 'year';
- desc += ' on ' + monthUtils.format(config.start, 'LLL do');
- return desc + suffix;
- }
default:
- return 'Recurring error';
+ return t('Recurring error');
}
+
+ return `${desc}${suffix}`.trim();
}
export function recurConfigToRSchedule(config) {
@@ -346,7 +380,7 @@ export function describeSchedule(schedule, payee) {
if (payee) {
return `${payee.name} (${schedule.next_date})`;
} else {
- return `Next: ${schedule.next_date}`;
+ return `${t('Next:')} ${schedule.next_date}`;
}
}
diff --git a/packages/loot-core/src/shared/util.ts b/packages/loot-core/src/shared/util.ts
index 38e9c4f52a..3448da148e 100644
--- a/packages/loot-core/src/shared/util.ts
+++ b/packages/loot-core/src/shared/util.ts
@@ -1,6 +1,5 @@
// @ts-strict-ignore
import { formatDistanceToNow } from 'date-fns';
-import * as locales from 'date-fns/locale';
export function last<T>(arr: Array<T>) {
return arr[arr.length - 1];
@@ -489,7 +488,7 @@ export function sortByKey<T>(arr: T[], key: keyof T): T[] {
export function tsToRelativeTime(
ts: string | null,
- language: string,
+ locale: Locale,
options: {
capitalize: boolean;
} = { capitalize: false },
@@ -497,9 +496,6 @@ export function tsToRelativeTime(
if (!ts) return 'Unknown';
const parsed = new Date(parseInt(ts, 10));
- const locale =
- locales[language.replace('-', '') as keyof typeof locales] ??
- locales['enUS'];
let distance = formatDistanceToNow(parsed, { addSuffix: true, locale });
diff --git a/upcoming-release-notes/4211.md b/upcoming-release-notes/4211.md
new file mode 100644
index 0000000000..7dc2a719d3
--- /dev/null
+++ b/upcoming-release-notes/4211.md
@@ -0,0 +1,6 @@
+---
+category: Enhancements
+authors: [lelemm]
+---
+
+Translate dates to the selected language.
\ No newline at end of file