Skip to content

Commit

Permalink
chore: update translations
Browse files Browse the repository at this point in the history
  • Loading branch information
chrismclarke committed Apr 16, 2023
1 parent 6562f34 commit 4e58be8
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 96 deletions.
141 changes: 45 additions & 96 deletions apps/picsa-tools/budget-tool/src/app/store/budget.store.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,33 @@
import { Injectable, OnDestroy } from '@angular/core';
import { toJS } from 'mobx';
import { observable, action, computed } from 'mobx-angular';
import { DomSanitizer, SafeResourceUrl } from '@angular/platform-browser';
import { marker as translateMarker } from '@biesbjerg/ngx-translate-extract-marker';
import { ConfigurationService, IConfiguration } from '@picsa/configuration';
import { APP_VERSION } from '@picsa/environments';
import { IAppMeta } from '@picsa/models';
import { generateDBMeta, PicsaDbService } from '@picsa/shared/services/core/db';
import { generateID } from '@picsa/shared/services/core/db/db.service';
import { PrintProvider } from '@picsa/shared/services/native/print';
import merge from 'deepmerge';
import { toJS } from 'mobx';
import { action, computed, observable } from 'mobx-angular';
import { BehaviorSubject, Subject, takeUntil } from 'rxjs';

import { BUDGET_CARDS } from '../data';
import {
IBudget,
IBudgetPeriodData,
IBudgetBalance,
IBudgetCard,
IBudgetMeta,
IBudgetCardDB,
IBudgetCardWithValues,
IBudgetValueScale,
IBudgetValueCounters,
IBudgetBalance,
IBudgetPeriodType,
IBudgetCodeDoc,
IBudgetMeta,
IBudgetPeriodData,
IBudgetPeriodType,
IBudgetValueCounters,
IBudgetValueScale,
} from '../models/budget-tool.models';
import { checkForBudgetUpgrades } from '../utils/budget.upgrade';
import { NEW_BUDGET_TEMPLATE, MONTHS } from './templates';
import { BUDGET_CARDS } from '../data';
import { PicsaDbService, generateDBMeta } from '@picsa/shared/services/core/db';
import { IAppMeta } from '@picsa/models';
import { APP_VERSION } from '@picsa/environments';
import { BehaviorSubject, Subject, takeUntil } from 'rxjs';
import { ConfigurationService, IConfiguration } from '@picsa/configuration';
import { PrintProvider } from '@picsa/shared/services/native/print';
import { DomSanitizer, SafeResourceUrl } from '@angular/platform-browser';
import { generateID } from '@picsa/shared/services/core/db/db.service';
import { MONTHS, NEW_BUDGET_TEMPLATE } from './templates';
const TYPE_CARDS_BASE: {
[key in IBudgetPeriodType | 'enterprise' | 'other']: IBudgetCard[];
} = {
Expand All @@ -39,20 +40,14 @@ const TYPE_CARDS_BASE: {
other: [],
};
const TYPE_LABELS: { [key in IBudgetPeriodType | 'summary']: string } = {
activities: 'Activities',
familyLabour: 'Family Labour',
inputs: 'Inputs',
outputs: 'Outputs',
produceConsumed: 'Produce Consumed',
summary: 'Summary',
activities: translateMarker('Activities'),
familyLabour: translateMarker('Family Labour'),
inputs: translateMarker('Inputs'),
outputs: translateMarker('Outputs'),
produceConsumed: translateMarker('Produce Consumed'),
summary: translateMarker('Summary'),
};
type IBudgetCounter =
| 'large'
| 'large-half'
| 'medium'
| 'medium-half'
| 'small'
| 'small-half';
type IBudgetCounter = 'large' | 'large-half' | 'medium' | 'medium-half' | 'small' | 'small-half';
export type IBudgetCounterSVGIcons = Record<IBudgetCounter, SafeResourceUrl>;

@Injectable({
Expand All @@ -76,9 +71,7 @@ export class BudgetStore implements OnDestroy {
// get unique list of types in enterprise cards
@computed get enterpriseTypeCards(): IBudgetCardDB[] {
console.log('get enterprisetype cards');
const enterpriseCards = this.budgetCards.filter(
(c) => c.type === 'enterprise'
);
const enterpriseCards = this.budgetCards.filter((c) => c.type === 'enterprise');
return this._createCardGroupCards(enterpriseCards);
}
@observable budgetCardsByType = TYPE_CARDS_BASE;
Expand Down Expand Up @@ -116,12 +109,9 @@ export class BudgetStore implements OnDestroy {
) {
this.counterSVGIcons = this.createBudgetCounterSVGs();
// TODO store never destroyed so would be good to limit listeners
this.configurationService.activeConfiguration$
.pipe(takeUntil(this.destroyed$))
.subscribe((v) => {
this.settings =
this.configurationService.activeConfiguration.budgetTool;
});
this.configurationService.activeConfiguration$.pipe(takeUntil(this.destroyed$)).subscribe((v) => {
this.settings = this.configurationService.activeConfiguration.budgetTool;
});
}
ngOnDestroy(): void {
this.destroyed$.next(true);
Expand All @@ -133,9 +123,7 @@ export class BudgetStore implements OnDestroy {
*
***************************************************************************/
getfilteredEnterprises(grouping: string) {
return this.budgetCards.filter(
(e) => e.type === 'enterprise' && e.groupings?.includes(grouping)
);
return this.budgetCards.filter((e) => e.type === 'enterprise' && e.groupings?.includes(grouping));
}
/**************************************************************************
* Budget Values
Expand All @@ -144,9 +132,7 @@ export class BudgetStore implements OnDestroy {
// merge current budget with added data, optionally can merge deep to include
// nested properties
patchBudget(patch: Partial<IBudget>, deepMerge = false) {
const budget = deepMerge
? merge(this.activeBudget, patch)
: { ...this.activeBudget, ...patch };
const budget = deepMerge ? merge(this.activeBudget, patch) : { ...this.activeBudget, ...patch };
this.setActiveBudget(budget);
this.saveBudget();
}
Expand Down Expand Up @@ -192,18 +178,14 @@ export class BudgetStore implements OnDestroy {
const svgPaths = {
large:
'M479.99952 480.00078c-149.33319.00002-298.66639.00002-447.999582 0C106.66653 330.6673 181.33313 181.33382 255.99974 32.00035c74.66661 149.33347 149.3332 298.66695 223.99978 448.00043Z',
medium:
'M41.695065 41.695068H470.30496c-.00001 142.869952 0 285.739912 0 428.609862H41.695065V41.695068z',
medium: 'M41.695065 41.695068H470.30496c-.00001 142.869952 0 285.739912 0 428.609862H41.695065V41.695068z',
small:
'M460.09621 256c5.02545 132.35505-139.57369 238.73445-264.41078 194.98057C67.841246 416.64296 8.7177668 247.12958 87.552104 140.7586 158.13858 28.727575 337.53963 22.374453 415.87405 129.13175 444.36362 164.8484 460.20746 210.31914 460.09621 256Z',
};
for (const [name, path] of Object.entries(svgPaths)) {
const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
svg.setAttribute('viewBox', '0 0 512 512');
const iconPath = document.createElementNS(
'http://www.w3.org/2000/svg',
'path'
);
const iconPath = document.createElementNS('http://www.w3.org/2000/svg', 'path');
iconPath.setAttribute('d', path);
iconPath.setAttribute('fill', '#c5ceb2');
iconPath.setAttribute('stroke', '#77933c');
Expand All @@ -214,9 +196,7 @@ export class BudgetStore implements OnDestroy {
// Create a half-style el where viewbox cuts off half of element
const halfEl = svg.cloneNode(true) as SVGElement;
halfEl.setAttribute('viewBox', '0 0 256 512');
svgs[`${name}-half`] = this.sanitizer.bypassSecurityTrustHtml(
halfEl.outerHTML
);
svgs[`${name}-half`] = this.sanitizer.bypassSecurityTrustHtml(halfEl.outerHTML);
}
return svgs;
}
Expand All @@ -235,11 +215,7 @@ export class BudgetStore implements OnDestroy {
this.setActiveBudget(budget);
}
async saveBudget() {
await this.db.setDoc(
'budgetTool/${GROUP}/budgets',
this.activeBudgetValue,
true
);
await this.db.setDoc('budgetTool/${GROUP}/budgets', this.activeBudgetValue, true);
await this.loadSavedBudgets();
}
async loadBudgetByKey(key: string) {
Expand All @@ -254,11 +230,7 @@ export class BudgetStore implements OnDestroy {
}
}
async loadBudgetByShareCode(code: string) {
const codeDoc = await this.db.getDoc<IBudgetCodeDoc>(
'budgetTool/default/shareCodes',
code,
'server'
);
const codeDoc = await this.db.getDoc<IBudgetCodeDoc>('budgetTool/default/shareCodes', code, 'server');
if (codeDoc) {
return this.importBudget(codeDoc.budget_key);
} else {
Expand All @@ -275,31 +247,21 @@ export class BudgetStore implements OnDestroy {
}

private async loadSavedBudgets(): Promise<void> {
const budgets = await this.db.getCollection<IBudget>(
'budgetTool/${GROUP}/budgets'
);
this.savedBudgets = budgets.sort((a, b) =>
b._modified > a._modified ? 1 : -1
);
const budgets = await this.db.getCollection<IBudget>('budgetTool/${GROUP}/budgets');
this.savedBudgets = budgets.sort((a, b) => (b._modified > a._modified ? 1 : -1));
}

async deleteBudget(budget: IBudget) {
await this.db.deleteDocs('budgetTool/${GROUP}/budgets', [budget._key]);
if (budget.shareCode) {
await this.db.deleteDocs('budgetTool/default/shareCodes', [
budget.shareCode,
]);
await this.db.deleteDocs('budgetTool/default/shareCodes', [budget.shareCode]);
}
this.loadSavedBudgets();
}

/** Duplicate a server budget and save locally */
private async importBudget(key: string): Promise<IBudget | undefined> {
const budget: IBudget = await this.db.getDoc(
'budgetTool/${GROUP}/budgets',
key,
'server'
);
const budget: IBudget = await this.db.getDoc('budgetTool/${GROUP}/budgets', key, 'server');
if (budget) {
// remove previous share code to allow re-share as new budget
if (budget.shareCode) {
Expand All @@ -317,11 +279,7 @@ export class BudgetStore implements OnDestroy {
}

public async shareAsImage() {
return this.printPrvdr.shareHtmlDom(
'#budget',
this.activeBudget.meta.title,
this.activeBudget.meta.title
);
return this.printPrvdr.shareHtmlDom('#budget', this.activeBudget.meta.title, this.activeBudget.meta.title);
}

public async shareAsLink() {
Expand All @@ -334,11 +292,7 @@ export class BudgetStore implements OnDestroy {
_key: code,
budget_key: this.activeBudget._key,
};
await this.db.setDoc(
'budgetTool/default/shareCodes',
budgetCodeDoc,
true
);
await this.db.setDoc('budgetTool/default/shareCodes', budgetCodeDoc, true);
this.activeBudget.shareCode = code;
}
await this.saveBudget();
Expand Down Expand Up @@ -457,14 +411,9 @@ export class BudgetStore implements OnDestroy {
}
// group all enterprise cards and create new parent card that will be used to reveal group
private _createCardGroupCards(cards: IBudgetCard[]): IBudgetCardDB[] {
const allGroupings: string[][] = cards.map(
(e) => toJS(e.groupings) as string[]
);
const allGroupings: string[][] = cards.map((e) => toJS(e.groupings) as string[]);
// eslint-disable-next-line prefer-spread
const mergedGroupings: string[] = ([] as any).concat.apply(
[],
allGroupings
);
const mergedGroupings: string[] = ([] as any).concat.apply([], allGroupings);
// NOTE - technically Array.from shouldn't be required but current issue with typescript
// see https://stackoverflow.com/questions/33464504/using-spread-syntax-and-new-set-with-typescript/33464709
const uniqueGroups = [...Array.from(new Set(mergedGroupings))].sort();
Expand Down
2 changes: 2 additions & 0 deletions libs/i18n/assets/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
"Description (optional)": "Description (optional)",
"Enterprise": "Enterprise",
"Family": "Family",
"Family Labour": "Family Labour",
"Female Member": "Female Member",
"How long is your budget for?": "How long is your budget for?",
"Import Budget Code": "Import Budget Code",
Expand All @@ -98,6 +99,7 @@
"Male Member": "Male Member",
"Next": "Next",
"Outputs": "Outputs",
"Produce Consumed": "Produce Consumed",
"Quantity": "Quantity",
"Save": "Save",
"Save your budget": "Save your budget",
Expand Down
2 changes: 2 additions & 0 deletions libs/i18n/assets/ny.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
{
"Add Female Member": "",
"Add Male Member": "",
"Family Labour": "",
"Female Member": "",
"Male Member": "",
"Produce Consumed": "",
"Select Country": "",
"Activities": "zochitika",
"add custom": "onjezani mwambo",
Expand Down
2 changes: 2 additions & 0 deletions libs/i18n/assets/sw.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
"End of Season": "Mwisho wa Msimu",
"End of season is defined as the last day in the season (1st October - 30th April) with more than 10mm of rainfall.": "Mwisho wa msimu hufafanuliwa kama siku ya mwisho msimu (1 Oktoba - 30 Aprili) na zaidi ya 10mm ya mvua.",
"Enterprise": "",
"Family Labour": "Kazi ya Familia",
"family labour": "",
"feed": "",
"feeding livestock": "",
Expand Down Expand Up @@ -116,6 +117,7 @@
"ploughing": "",
"post-harvest handling": "",
"pot for storage": "",
"Produce Consumed": "Kuzalisha Iliyotumiwa",
"protective equipment": "",
"provide supplements": "",
"provide water": "",
Expand Down
2 changes: 2 additions & 0 deletions libs/i18n/assets/tg.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
"End of Season": "Охири мавсим",
"End of season is defined as the last day in the season (1st October - 30th April) with more than 10mm of rainfall.": "Анҷоми мавсим ҳамчун рӯзи охир дар мавсими (1 октябр - 30 апрел) бо зиёда аз 10 миллион боришот муайян карда мешавад.",
"Enterprise": "Корхона",
"Family Labour": "Меҳнати оила",
"family labour": "меҳнати оила",
"feed": "таъом",
"feeding livestock": "таъом додани чорводорӣ",
Expand Down Expand Up @@ -116,6 +117,7 @@
"ploughing": "шудгор кардан",
"post-harvest handling": "Мавридҳои ҳосили пас аз",
"pot for storage": "дег барои нигаҳдошт",
"Produce Consumed": "Маҳсулоти истеъмолшуда",
"protective equipment": "Таҷҳизоти муҳофизатӣ",
"provide supplements": "лавозимотро таъмин кунед",
"provide water": "Таъмини об",
Expand Down
2 changes: 2 additions & 0 deletions libs/i18n/templates/_template.csv
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ tool,context,text
"budget",,"Description (optional)"
"budget",,"Enterprise"
"budget",,"Family"
"budget",,"Family Labour"
"budget",,"Female Member"
"budget",,"How long is your budget for?"
"budget",,"Import Budget Code"
Expand All @@ -98,6 +99,7 @@ tool,context,text
"budget",,"Male Member"
"budget",,"Next"
"budget",,"Outputs"
"budget",,"Produce Consumed"
"budget",,"Quantity"
"budget",,"Save"
"budget",,"Save your budget"
Expand Down
8 changes: 8 additions & 0 deletions libs/i18n/templates/_template.json
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,10 @@
"text": "Family",
"tool": "budget"
},
{
"text": "Family Labour",
"tool": "budget"
},
{
"text": "Female Member",
"tool": "budget"
Expand Down Expand Up @@ -473,6 +477,10 @@
"text": "Outputs",
"tool": "budget"
},
{
"text": "Produce Consumed",
"tool": "budget"
},
{
"text": "Quantity",
"tool": "budget"
Expand Down

0 comments on commit 4e58be8

Please sign in to comment.