Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Marked files for translation #3548

Merged
merged 27 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 41 additions & 23 deletions packages/desktop-client/src/components/reports/DateRange.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React, { type ReactElement } from 'react';
import { Trans } from 'react-i18next';

import * as d from 'date-fns';
import { t } from 'i18next';

import { theme } from '../../style';
import { styles } from '../../style/styles';
Expand All @@ -15,7 +17,7 @@ type DateRangeProps = {

function checkDate(date: string) {
const dateParsed = new Date(date);
if (dateParsed.toString() !== 'Invalid Date') {
if (dateParsed.toString() !== t('Invalid Date')) {
return d.format(dateParsed, 'yyyy-MM-dd');
} else {
return null;
Expand All @@ -34,43 +36,59 @@ export function DateRange({ start, end, type }: DateRangeProps): ReactElement {
} else {
return (
<Text style={{ ...styles.mediumText, color: theme.errorText }}>
There was a problem loading your date range
<Trans>There was a problem loading your date range</Trans>
</Text>
);
}

const formattedStartDate = d.format(startDate, 'MMM yyyy');
const formattedEndDate = d.format(endDate, 'MMM yyyy');
let typeOrFormattedEndDate: string;

if (type && ['budget', 'average'].includes(type)) {
typeOrFormattedEndDate = type;
} else {
typeOrFormattedEndDate = formattedEndDate;
}

let content: string | ReactElement;
if (['budget', 'average'].includes(type || '')) {
content = (
<div>
Compare {d.format(startDate, 'MMM yyyy')} to{' '}
{type === 'budget' ? 'budgeted' : 'average'}
</div>
);
} else if (startDate.getFullYear() !== endDate.getFullYear()) {
content = (
<div>
{type && 'Compare '}
{d.format(startDate, 'MMM yyyy')}
{type ? ' to ' : ' - '}
{['budget', 'average'].includes(type || '')
? type
: d.format(endDate, 'MMM yyyy')}
<Trans
values={{
startDate: formattedStartDate,
endDate: typeOrFormattedEndDate,
}}
>
Compare {{ startDate }} to {{ endDate }}
</Trans>
</div>
);
} else if (startDate.getMonth() !== endDate.getMonth()) {
} else if (
startDate.getFullYear() !== endDate.getFullYear() ||
startDate.getMonth() !== endDate.getMonth()
) {
content = (
<div>
{type && 'Compare '}
{d.format(startDate, 'MMM yyyy')}
{type ? ' to ' : ' - '}
{['budget', 'average'].includes(type || '')
? type
: d.format(endDate, 'MMM yyyy')}
{type ? (
<Trans
values={{
formattedStartDate,
endDate: typeOrFormattedEndDate,
}}
>
Compare {{ formattedStartDate }} to {{ endDate }}
</Trans>
) : (
<Trans>
{{ formattedStartDate }} - {{ formattedEndDate }}
</Trans>
)}
</div>
);
} else {
content = d.format(endDate, 'MMMM yyyy');
content = formattedEndDate;
}

return <Block style={{ color: theme.pageTextSubdued }}>{content}</Block>;
Expand Down
58 changes: 30 additions & 28 deletions packages/desktop-client/src/components/reports/ReportOptions.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { t } from 'i18next';

import * as monthUtils from 'loot-core/src/shared/months';
import {
type CustomReportEntity,
Expand All @@ -16,11 +18,11 @@ export const defaultReport: CustomReportEntity = {
startDate,
endDate,
isDateStatic: false,
dateRange: 'Last 6 months',
dateRange: t('Last 6 months'),
mode: 'total',
groupBy: 'Category',
interval: 'Monthly',
balanceType: 'Payment',
interval: t('Monthly'),
balanceType: t('Payment'),
showEmpty: false,
showOffBudget: false,
showHiddenCategories: false,
Expand All @@ -32,11 +34,11 @@ export const defaultReport: CustomReportEntity = {
};

const balanceTypeOptions = [
{ description: 'Payment', format: 'totalDebts' as const },
{ description: 'Deposit', format: 'totalAssets' as const },
{ description: 'Net', format: 'totalTotals' as const },
{ description: 'Net Payment', format: 'netDebts' as const },
{ description: 'Net Deposit', format: 'netAssets' as const },
{ description: t('Payment'), format: 'totalDebts' as const },
{ description: t('Deposit'), format: 'totalAssets' as const },
{ description: t('Net'), format: 'totalTotals' as const },
{ description: t('Net Payment'), format: 'netDebts' as const },
{ description: t('Net Deposit'), format: 'netAssets' as const },
];

const groupByOptions = [
Expand All @@ -59,7 +61,7 @@ export type dateRangeProps = {

const dateRangeOptions: dateRangeProps[] = [
{
description: 'This week',
description: t('This week'),
name: 0,
type: 'Week',
Daily: true,
Expand All @@ -68,7 +70,7 @@ const dateRangeOptions: dateRangeProps[] = [
Yearly: false,
},
{
description: 'Last week',
description: t('Last week'),
name: 1,
type: 'Week',
Daily: true,
Expand All @@ -77,7 +79,7 @@ const dateRangeOptions: dateRangeProps[] = [
Yearly: false,
},
{
description: 'This month',
description: t('This month'),
name: 0,
type: 'Month',
Daily: true,
Expand All @@ -86,7 +88,7 @@ const dateRangeOptions: dateRangeProps[] = [
Yearly: false,
},
{
description: 'Last month',
description: t('Last month'),
name: 1,
type: 'Month',
Daily: true,
Expand All @@ -95,7 +97,7 @@ const dateRangeOptions: dateRangeProps[] = [
Yearly: false,
},
{
description: 'Last 3 months',
description: t('Last 3 months'),
name: 3,
type: 'Month',
Daily: true,
Expand All @@ -104,7 +106,7 @@ const dateRangeOptions: dateRangeProps[] = [
Yearly: false,
},
{
description: 'Last 6 months',
description: t('Last 6 months'),
name: 6,
type: 'Month',
Daily: false,
Expand All @@ -113,7 +115,7 @@ const dateRangeOptions: dateRangeProps[] = [
Yearly: false,
},
{
description: 'Last 12 months',
description: t('Last 12 months'),
name: 12,
type: 'Month',
Daily: false,
Expand All @@ -122,7 +124,7 @@ const dateRangeOptions: dateRangeProps[] = [
Yearly: false,
},
{
description: 'Year to date',
description: t('Year to date'),
name: 'yearToDate',
type: 'Month',
Daily: false,
Expand All @@ -131,7 +133,7 @@ const dateRangeOptions: dateRangeProps[] = [
Yearly: true,
},
{
description: 'Last year',
description: t('Last year'),
name: 'lastYear',
type: 'Month',
Daily: false,
Expand All @@ -140,7 +142,7 @@ const dateRangeOptions: dateRangeProps[] = [
Yearly: true,
},
{
description: 'All time',
description: t('All time'),
name: 'allTime',
type: 'Month',
Daily: false,
Expand All @@ -163,27 +165,27 @@ type intervalOptionsProps = {

const intervalOptions: intervalOptionsProps[] = [
{
description: 'Daily',
description: t('Daily'),
name: 'Day',
format: 'yy-MM-dd',
range: 'dayRangeInclusive',
},
{
description: 'Weekly',
description: t('Weekly'),
name: 'Week',
format: 'yy-MM-dd',
range: 'weekRangeInclusive',
},
//{ value: 3, description: 'Fortnightly', name: 3},
{
description: 'Monthly',
description: t('Monthly'),
name: 'Month',
// eslint-disable-next-line rulesdir/typography
format: "MMM ''yy",
range: 'rangeInclusive',
},
{
description: 'Yearly',
description: t('Yearly'),
name: 'Year',
format: 'yyyy',
range: 'yearRangeInclusive',
Expand Down Expand Up @@ -251,7 +253,7 @@ export type UncategorizedEntity = Pick<

const uncategorizedCategory: UncategorizedEntity = {
id: '',
name: 'Uncategorized',
name: t('Uncategorized'),
uncategorized_id: '1',
hidden: false,
is_off_budget: false,
Expand All @@ -260,7 +262,7 @@ const uncategorizedCategory: UncategorizedEntity = {
};
const transferCategory: UncategorizedEntity = {
id: '',
name: 'Transfers',
name: t('Transfers'),
uncategorized_id: '2',
hidden: false,
is_off_budget: false,
Expand All @@ -269,7 +271,7 @@ const transferCategory: UncategorizedEntity = {
};
const offBudgetCategory: UncategorizedEntity = {
id: '',
name: 'Off Budget',
name: t('Off Budget'),
uncategorized_id: '3',
hidden: false,
is_off_budget: true,
Expand All @@ -285,7 +287,7 @@ type UncategorizedGroupEntity = Pick<
};

const uncategorizedGroup: UncategorizedGroupEntity = {
name: 'Uncategorized & Off Budget',
name: t('Uncategorized & Off Budget'),
id: 'uncategorized',
hidden: false,
categories: [uncategorizedCategory, transferCategory, offBudgetCategory],
Expand All @@ -302,7 +304,7 @@ export const categoryLists = (categories: {
const catGroupB = categories.grouped.find(f => f.id === b.cat_group);
//initial check that both a and b have a sort_order and category group
return a.sort_order && b.sort_order && catGroupA && catGroupB
? /*sorting by "is_income" because sort_order for this group is
? /*sorting by "is_income" because sort_order for this group is
separate from other groups*/
Number(catGroupA.is_income) - Number(catGroupB.is_income) ||
//Next, sorting by group sort_order
Expand Down Expand Up @@ -363,7 +365,7 @@ export const groupBySelections = (
groupByLabel = 'category';
break;
default:
throw new Error('Error loading data into the spreadsheet.');
throw new Error(t('Error loading data into the spreadsheet.'));
}
return [groupByList, groupByLabel];
};
Loading
Loading