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 18 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
49 changes: 28 additions & 21 deletions packages/desktop-client/src/components/reports/DateRange.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { type ReactElement } from 'react';
import { Trans } from 'react-i18next';

import * as d from 'date-fns';

Expand Down Expand Up @@ -34,39 +35,45 @@ 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 === 'budget' ? 'budgeted' : 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>
Compare {{ formattedStartDate }} to {{ typeOrFormattedEndDate }}
</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>
Compare {{ formattedStartDate }} to {{ typeOrFormattedEndDate }}
</Trans>
) : (
<Trans>
{{ formattedStartDate }} - {{ formattedEndDate }}
</Trans>
)}
</div>
);
} else {
Expand Down
50 changes: 26 additions & 24 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 Down Expand Up @@ -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
28 changes: 15 additions & 13 deletions packages/desktop-client/src/components/reports/disabledList.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,43 @@
import { t } from 'i18next';

const intervalOptions = [
{
description: 'Daily',
defaultRange: 'This month',
description: t('Daily'),
defaultRange: t('This month'),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @carkom should these be translated?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bump @carkom

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's difficult to know. If you capture all of them then it should be fine. If it's translated then saved then all the options to reference are also translated then it should be fine as long as we capture them all.

However, if you save a report while the app is being translated and then switch back to English (or any other language) then the report will error out.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are any of these things stored in the DB? If tgey are then we definitely shouldn't be translating them.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@a-gradina would you mind removing the translations from all the defaultRange values? I'm happy yo merge once we have that done :)

Sorry for this PR taking so long

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bump @a-gradina . I think there was a misunderstanding. You can keep the translations for description. But remove from defaultRange.

},
{
description: 'Weekly',
defaultRange: 'Last 3 months',
description: t('Weekly'),
defaultRange: t('Last 3 months'),
},
{
description: 'Monthly',
defaultRange: 'Last 6 months',
description: t('Monthly'),
defaultRange: t('Last 6 months'),
},
{
description: 'Yearly',
defaultRange: 'Year to date',
description: t('Yearly'),
defaultRange: t('Year to date'),
},
];

const currentIntervalOptions = [
{
description: 'This week',
description: t('This week'),
disableInclude: true,
},
{
description: 'This month',
description: t('This month'),
disableInclude: true,
},
{
description: 'Year to date',
description: t('Year to date'),
disableInclude: true,
},
{
description: 'Last year',
description: t('Last year'),
disableInclude: true,
},
{
description: 'All time',
description: t('All time'),
disableInclude: true,
},
];
Expand Down
6 changes: 5 additions & 1 deletion packages/desktop-client/src/components/reports/index.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import { useTranslation } from 'react-i18next';

import { View } from '../common/View';
import { LoadComponent } from '../util/LoadComponent';

export function Reports() {
const { t } = useTranslation();

return (
<View style={{ flex: 1 }} data-testid="reports-page">
<LoadComponent
name="ReportRouter"
message="Loading reports..."
message={t('Loading reports...')}
importer={() =>
import(/* webpackChunkName: 'reports' */ './ReportRouter')
}
Expand Down
6 changes: 6 additions & 0 deletions upcoming-release-notes/3548.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Maintenance
authors: [a-gradina]
---

Support translations in various files.