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

[WIP] Translation: https://github.com/actualbudget/actual/pull/3839 #3839

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
16 changes: 12 additions & 4 deletions packages/loot-core/src/server/budget/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import * as sheet from '../sheet';
import { batchMessages } from '../sync';

import { useTranslation } from 'react-i18next';

Check warning on line 8 in packages/loot-core/src/server/budget/actions.ts

View workflow job for this annotation

GitHub Actions / lint

`react-i18next` import should occur before import of `../../shared/months`

Check warning on line 8 in packages/loot-core/src/server/budget/actions.ts

View workflow job for this annotation

GitHub Actions / lint

'useTranslation' is defined but never used. Allowed unused vars must match /^(_|React)/u

export async function getSheetValue(
sheetName: string,
cell: string,
Expand Down Expand Up @@ -512,17 +514,23 @@

const fromCategoryName =
from === 'to-be-budgeted'
? 'To Budget'
? t('To Budget')

Check failure on line 517 in packages/loot-core/src/server/budget/actions.ts

View workflow job for this annotation

GitHub Actions / typecheck

Cannot find name 't'.
: categories.find(c => c.id === from)?.name;

const toCategoryName =
to === 'to-be-budgeted'
? 'To Budget'
? t('To Budget')

Check failure on line 522 in packages/loot-core/src/server/budget/actions.ts

View workflow job for this annotation

GitHub Actions / typecheck

Cannot find name 't'.
: to === 'overbudgeted'
? 'Overbudgeted'
? t('Overbudgeted')

Check failure on line 524 in packages/loot-core/src/server/budget/actions.ts

View workflow job for this annotation

GitHub Actions / typecheck

Cannot find name 't'.
: categories.find(c => c.id === to)?.name;

const note = `Reassigned ${displayAmount} from ${fromCategoryName} → ${toCategoryName} on ${displayDay}`;
const note = t('Reassigned {{displayAmount}} from {{fromCategory}} → ' +

Check warning on line 527 in packages/loot-core/src/server/budget/actions.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `'Reassigned·{{displayAmount}}·from·{{fromCategory}}·→·'·+·⏎····'{{toCategory}}·on·{{displayDay}}',` with `⏎····'Reassigned·{{displayAmount}}·from·{{fromCategory}}·→·'·+⏎······'{{toCategory}}·on·{{displayDay}}',⏎···`

Check failure on line 527 in packages/loot-core/src/server/budget/actions.ts

View workflow job for this annotation

GitHub Actions / typecheck

Cannot find name 't'.
'{{toCategory}} on {{displayDay}}', {
displayAmount: displayAmount,

Check warning on line 529 in packages/loot-core/src/server/budget/actions.ts

View workflow job for this annotation

GitHub Actions / lint

Expected property shorthand
fromCategory: fromCategoryName,
toCategory: toCategoryName,
displayDay: displayDay

Check warning on line 532 in packages/loot-core/src/server/budget/actions.ts

View workflow job for this annotation

GitHub Actions / lint

Expected property shorthand

Check warning on line 532 in packages/loot-core/src/server/budget/actions.ts

View workflow job for this annotation

GitHub Actions / lint

Insert `,`
});

Check warning on line 533 in packages/loot-core/src/server/budget/actions.ts

View workflow job for this annotation

GitHub Actions / lint

Insert `,⏎··`

await db.update('notes', {
id: monthBudgetNotesId,
Expand Down
27 changes: 17 additions & 10 deletions packages/loot-core/src/server/budget/categoryTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import { getActiveSchedules } from './statements';
import { Template } from './types/templates';

import { useTranslation } from 'react-i18next';

Check warning on line 12 in packages/loot-core/src/server/budget/categoryTemplate.ts

View workflow job for this annotation

GitHub Actions / lint

`react-i18next` import should occur before import of `../../shared/months`

Check warning on line 12 in packages/loot-core/src/server/budget/categoryTemplate.ts

View workflow job for this annotation

GitHub Actions / lint

'useTranslation' is defined but never used. Allowed unused vars must match /^(_|React)/u

export class CategoryTemplate {
/*----------------------------------------------------------------------------
* Using This Class:
Expand Down Expand Up @@ -282,7 +284,9 @@
.filter(t => t.type === 'schedule')
.forEach(t => {
if (!scheduleNames.includes(t.name.trim())) {
throw new Error(`Schedule ${t.name.trim()} does not exist`);
throw new Error(t('Schedule {{name}} does not exist', {

Check warning on line 287 in packages/loot-core/src/server/budget/categoryTemplate.ts

View workflow job for this annotation

GitHub Actions / lint

Insert `⏎············`
name: t.name.trim()
}));
}
});
//find lowest priority
Expand All @@ -296,8 +300,9 @@
.filter(t => t.type === 'schedule' || t.type === 'by')
.forEach(t => {
if (t.priority !== lowestPriority) {
throw new Error(
`Schedule and By templates must be the same priority level. Fix by setting all Schedule and By templates to priority level ${lowestPriority}`,
throw new Error(t(
'Schedule and By templates must be the same priority level. Fix by setting all Schedule and By templates to priority level {{lowestPriority}}',
{ lowestPriority: lowestPriority}),
);
//t.priority = lowestPriority;
}
Expand All @@ -312,8 +317,8 @@
);
if (range < 0 && !(t.repeat || t.annual)) {
throw new Error(
`Target month has passed, remove or update the target month`,
);
t('Target month has passed, remove or update the target month'),
);
}
});
}
Expand All @@ -333,7 +338,9 @@
//skip the name check since these are special
} else if (!availNames.includes(n)) {
throw new Error(
`Category \x22${n}\x22 is not found in available income categories`,
t('Category \x22{{name}}\x22 is not found in available income categories', {

Check failure on line 341 in packages/loot-core/src/server/budget/categoryTemplate.ts

View workflow job for this annotation

GitHub Actions / typecheck

Cannot find name 't'.
name: n
}),
);
}
});
Expand All @@ -343,7 +350,7 @@
for (const t of this.templates) {
if (!t.limit) continue;
if (this.limitCheck) {
throw new Error('Only one `up to` allowed per category');
throw new Error(t('Only one `up to` allowed per category'));
} else if (t.limit) {
if (t.limit.period === 'daily') {
const numDays = monthUtils.differenceInCalendarDays(
Expand All @@ -364,7 +371,7 @@
} else if (t.limit.period === 'monthly') {
this.limitAmount = amountToInteger(t.limit.amount);
} else {
throw new Error('Invalid limit period. Check template syntax');
throw new Error(t('Invalid limit period. Check template syntax'));
}
//amount is good save the rest
this.limitCheck = true;
Expand All @@ -376,13 +383,13 @@
private checkSpend() {
const st = this.templates.filter(t => t.type === 'spend');
if (st.length > 1) {
throw new Error('Only one spend template is allowed per category');
throw new Error(t('Only one spend template is allowed per category'));

Check failure on line 386 in packages/loot-core/src/server/budget/categoryTemplate.ts

View workflow job for this annotation

GitHub Actions / typecheck

Cannot find name 't'.
}
}

private checkGoal() {
if (this.goals.length > 1) {
throw new Error(`Only one #goal is allowed per category`);
throw new Error(t('Only one #goal is allowed per category'));

Check failure on line 392 in packages/loot-core/src/server/budget/categoryTemplate.ts

View workflow job for this annotation

GitHub Actions / typecheck

Cannot find name 't'.
}
}

Expand Down
26 changes: 15 additions & 11 deletions packages/loot-core/src/server/budget/cleanup-template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import { setBudget, getSheetValue, setGoal } from './actions';
import { parse } from './cleanup-template.pegjs';
import { useTranslation } from 'react-i18next';

export function cleanupTemplate({ month }: { month: string }) {
return processCleanup(month);
Expand Down Expand Up @@ -113,7 +114,8 @@
});
}
} else {
warnings.push(groupName + ' has no matching sink categories.');
warnings.push(t('{{groupname}} has no matching sink categories.',

Check failure on line 117 in packages/loot-core/src/server/budget/cleanup-template.ts

View workflow job for this annotation

GitHub Actions / typecheck

Cannot find name 't'.
{ groupname: groupName }));
}
sourceGroups = sourceGroups.filter(c => c.group !== groupName);
groupLength = sourceGroups.length;
Expand Down Expand Up @@ -218,7 +220,8 @@
});
num_sources += 1;
} else {
warnings.push(category.name + ' does not have available funds.');
warnings.push(t('{{name}} does not have available funds.',

Check failure on line 223 in packages/loot-core/src/server/budget/cleanup-template.ts

View workflow job for this annotation

GitHub Actions / typecheck

Cannot find name 't'.
{ name: category.name }));
}
const carryover = await db.first(
`SELECT carryover FROM zero_budgets WHERE month = ? and category = ?`,
Expand Down Expand Up @@ -285,7 +288,7 @@

const budgetAvailable = await getSheetValue(sheetName, `to-budget`);
if (budgetAvailable <= 0) {
warnings.push('Global: No funds are available to reallocate.');
warnings.push(t('Global: No funds are available to reallocate.'));

Check failure on line 291 in packages/loot-core/src/server/budget/cleanup-template.ts

View workflow job for this annotation

GitHub Actions / typecheck

Cannot find name 't'.
}

//fill sinking categories
Expand Down Expand Up @@ -320,35 +323,36 @@
return {
type: 'error',
sticky: true,
message: 'There were errors interpreting some templates:',
message: t('There were errors interpreting some templates:'),
pre: errors.join('\n\n'),
};
} else if (warnings.length) {
return {
type: 'warning',
message: 'Global: Funds not available:',
message: t('Global: Funds not available:'),
pre: warnings.join('\n\n'),
};
} else {
return {
type: 'message',
message: 'All categories were up to date.',
message: t('All categories were up to date.'),
};
}
} else {
const applied = `Successfully returned funds from ${num_sources} ${
num_sources === 1 ? 'source' : 'sources'
} and funded ${num_sinks} sinking ${num_sinks === 1 ? 'fund' : 'funds'}.`;
const applied = t('Successfully returned funds from {{count}} sources ',
{ count: num_sources }) +
t(' and funded {{count}} sinking funds', { count: num_sinks });
if (errors.length) {
return {
sticky: true,
message: `${applied} There were errors interpreting some templates:`,
message: applied + ' ' +
t('There were errors interpreting some templates:'),
pre: errors.join('\n\n'),
};
} else if (warnings.length) {
return {
type: 'warning',
message: 'Global: Funds not available:',
message: t('Global: Funds not available:'),
pre: warnings.join('\n\n'),
};
} else {
Expand Down
8 changes: 6 additions & 2 deletions packages/loot-core/src/server/budget/goalsSchedule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import {

import { isReflectBudget } from './actions';

import { useTranslation } from 'react-i18next';

async function createScheduleList(template, current_month, category) {
const t = [];
const errors = [];
Expand Down Expand Up @@ -62,7 +64,8 @@ async function createScheduleList(template, current_month, category) {
);
if (num_months < 0) {
//non-repeating schedules could be negative
errors.push(`Schedule ${template[ll].name} is in the Past.`);
errors.push(t('Schedule {{name}} is in the past.', {
name: template[ll].name }));
} else {
t.push({
target,
Expand Down Expand Up @@ -126,7 +129,8 @@ async function createScheduleList(template, current_month, category) {
}
} else {
errors.push(
`Schedule ${t[ll].name} is not active during the month in question.`,
t('Schedule {{name}} is not active during the month in question.', {
name: t[ll].name }),
);
}
}
Expand Down
9 changes: 6 additions & 3 deletions packages/loot-core/src/server/budget/goaltemplates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { isReflectBudget, getSheetValue, setGoal, setBudget } from './actions';
import { CategoryTemplate } from './categoryTemplate';
import { checkTemplates, storeTemplates } from './template-notes';

import { useTranslation } from 'react-i18next';

export async function applyTemplate({ month }): Promise<Notification> {
await storeTemplates();
const categoryTemplates = await getTemplates(null);
Expand Down Expand Up @@ -188,13 +190,13 @@ async function processTemplate(
if (catObjects.length === 0 && errors.length === 0) {
return {
type: 'message',
message: 'Everything is up to date',
message: t('Everything is up to date'),
};
}
if (errors.length > 0) {
return {
sticky: true,
message: 'There were errors interpreting some templates:',
message: t('There were errors interpreting some templates:'),
pre: errors.join(`\n\n`),
};
}
Expand Down Expand Up @@ -245,6 +247,7 @@ async function processTemplate(

return {
type: 'message',
message: `Successfully applied templates to ${catObjects.length} categories`,
message: t('Successfully applied templates to {{count}} categories', {
count: catObjects.length }),
};
}
6 changes: 4 additions & 2 deletions packages/loot-core/src/server/budget/template-notes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import {
} from './statements';
import { Template } from './types/templates';

import { useTranslation } from 'react-i18next';

export const TEMPLATE_PREFIX = '#template';
export const GOAL_PREFIX = '#goal';

Expand Down Expand Up @@ -56,14 +58,14 @@ export async function checkTemplates(): Promise<Notification> {
if (errors.length) {
return {
sticky: true,
message: 'There were errors interpreting some templates:',
message: t('There were errors interpreting some templates:'),
pre: errors.join('\n\n'),
};
}

return {
type: 'message',
message: 'All templates passed! 🎉',
message: t('All templates passed!') + ' 🎉',
};
}

Expand Down
Loading