@le-space/eigenbeleg 0.8.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -14,7 +14,8 @@
14
14
  import { asset, createPdfA, LOGOS, savePdfA, wrapText } from '@le-space/pdf';
15
15
  import { round } from '@le-space/ledger';
16
16
 
17
- import { DATA_SOURCES, conversionText, deDate, deFixed, deMoney, deNumber } from './document.js';
17
+ import { DATA_SOURCES, DATA_SOURCES_EN, conversionText, formats } from './document.js';
18
+ import { localizeSource, say } from './language.js';
18
19
  import { CREATOR, PRODUCER } from './pdf.js';
19
20
  import { isDust, reconciled } from './statement.js';
20
21
  import { drawScene, sceneMeasure } from './chart-pdf.js';
@@ -25,6 +26,7 @@ import { BLACK, GREY, INK, MARK_SIZE, TYPE, WARN, pageLayout } from './layout.js
25
26
  const M = 48;
26
27
 
27
28
  const MARKET_RATE = 'Tageskurs (Kurs 00:00 UTC: CoinGecko, sonst Kraken)';
29
+ const MARKET_RATE_EN = "the day's rate (rate at 00:00 UTC: CoinGecko, else Kraken)";
28
30
 
29
31
  /**
30
32
  * What a section's values are at, for its note: the market rate of the day, a
@@ -32,28 +34,39 @@ const MARKET_RATE = 'Tageskurs (Kurs 00:00 UTC: CoinGecko, sonst Kraken)';
32
34
  * rate's name for another currency.
33
35
  *
34
36
  * @param {{ marketRate?: boolean, referenceValues?: string[] }} s
37
+ * @param {import('./language.js').DocumentLanguage} [language]
35
38
  * @returns {[string, string]}
36
39
  */
37
- function marketOrReference({ marketRate = true, referenceValues = [] }) {
40
+ function marketOrReference({ marketRate = true, referenceValues = [] }, language = 'de') {
41
+ const en = language === 'en';
38
42
  const names = [
39
- ...(marketRate || !referenceValues.length ? [MARKET_RATE] : []),
40
- ...referenceValues
43
+ ...(marketRate || !referenceValues.length ? [en ? MARKET_RATE_EN : MARKET_RATE] : []),
44
+ ...referenceValues.map((r) => localizeSource(r, language))
41
45
  ];
42
- return [names.map((n) => `zum ${n}`).join(' und '), names.join(' und ')];
46
+ return en
47
+ ? [names.map((n) => `at ${n}`).join(' and '), names.join(' and ')]
48
+ : [names.map((n) => `zum ${n}`).join(' und '), names.join(' und ')];
43
49
  }
44
50
 
45
- /** The table of bookings; its last column names the statement's currency. @param {string} currency */
46
- const columns = (currency) => [
47
- { title: 'Buchungstag', width: 52 },
48
- { title: 'Vorgang', width: 167 },
49
- { title: 'Soll', width: 72, right: true },
50
- { title: 'Haben', width: 72, right: true },
51
- { title: 'Saldo', width: 80, right: true },
52
- { title: `Wert ${currency}`, width: 56, right: true }
53
- ];
54
-
55
- /** Quantities in the table: at most 12 decimals, the CSV keeps them all. @param {string} q */
56
- const qty = (q) => (q ? deNumber(round(q, 12)) : '');
51
+ /** The table of bookings; its last column names the statement's currency. @param {string} currency @param {import('./language.js').DocumentLanguage} [language] */
52
+ const columns = (currency, language = 'de') =>
53
+ language === 'en'
54
+ ? [
55
+ { title: 'Date', width: 52 },
56
+ { title: 'Transaction', width: 167 },
57
+ { title: 'Debit', width: 72, right: true },
58
+ { title: 'Credit', width: 72, right: true },
59
+ { title: 'Balance', width: 80, right: true },
60
+ { title: `Value ${currency}`, width: 56, right: true }
61
+ ]
62
+ : [
63
+ { title: 'Buchungstag', width: 52 },
64
+ { title: 'Vorgang', width: 167 },
65
+ { title: 'Soll', width: 72, right: true },
66
+ { title: 'Haben', width: 72, right: true },
67
+ { title: 'Saldo', width: 80, right: true },
68
+ { title: `Wert ${currency}`, width: 56, right: true }
69
+ ];
57
70
 
58
71
  /**
59
72
  * @param {import('./statement.js').Statement} st
@@ -74,12 +87,21 @@ export async function statementPdf(
74
87
  const pay = st.chain === 'filecoin-pay';
75
88
  // The statement's currency (EUR unless another): its code in the column heads and sums.
76
89
  const cur = st.currency ?? 'EUR';
77
- const COLS = columns(cur);
90
+ // The statement's language (German unless it says English) and its formats.
91
+ const L = st.language ?? 'de';
92
+ /** @param {string} de @param {string} en */
93
+ const t = (de, en) => say(L, de, en);
94
+ const { number: deNumber, fixed: deFixed, money: fmtMoney, date: deDate } = formats(L);
95
+ /** Quantities in the table: at most 12 decimals, the CSV keeps them all. @param {string} q */
96
+ const qty = (q) => (q ? deNumber(round(q, 12)) : '');
97
+ const COLS = columns(cur, L);
78
98
  /** @param {string} amount */
79
- const money = (amount) => deMoney(amount, cur);
99
+ const money = (amount) => fmtMoney(amount, cur);
80
100
  /** What the values are: in euro as it always said, or how they became another currency. @param {string} eur @param {string} rate */
81
101
  const valued = (eur, rate) =>
82
- cur === 'EUR' ? `Euro-Werte ${eur}` : `Werte in ${cur}: ${rate}, ${conversionText(cur)}`;
102
+ cur === 'EUR'
103
+ ? `${t('Euro-Werte', 'Euro values')} ${eur}`
104
+ : `${t('Werte in', 'Values in')} ${cur}: ${rate}, ${conversionText(cur, L)}`;
83
105
  const title = `${st.title} ${st.number}`;
84
106
  const subject = `${st.title} ${st.chainName} ${st.account}, ${deDate(st.period.from)} – ${deDate(st.period.to)}`;
85
107
  const { pdf, fonts } = await createPdfA();
@@ -109,18 +131,24 @@ export async function statementPdf(
109
131
 
110
132
  // ---- head: the title first, as on every document; below the rule the holder and the facts
111
133
  if (st.testnet) {
112
- text('TESTNET – keine echten Werte. Kurse des Mainnet-Assets nur zur Veranschaulichung.', {
113
- face: bold,
114
- size: TYPE.table,
115
- color: WARN
116
- });
134
+ text(
135
+ t(
136
+ 'TESTNET – keine echten Werte. Kurse des Mainnet-Assets nur zur Veranschaulichung.',
137
+ 'TESTNET – no real values. Rates of the mainnet asset for illustration only.'
138
+ ),
139
+ {
140
+ face: bold,
141
+ size: TYPE.table,
142
+ color: WARN
143
+ }
144
+ );
117
145
  l.y -= 6;
118
146
  }
119
147
  // The chain's mark, larger: a statement shows what the network's account did. The issuer's logo is
120
148
  // not on it: a statement is not the issuer's own receipt.
121
149
  l.head(st.title, { image: mark, mark: MARK_SIZE.large });
122
150
  const top = l.y;
123
- label('Kontoinhaber', { max: 250 });
151
+ label(t('Kontoinhaber', 'Account holder'), { max: 250 });
124
152
  text(st.holder.name, { face: bold, size: TYPE.lead, max: 250 });
125
153
  text(st.holder.address, { max: 250 });
126
154
  const leftEnd = l.y;
@@ -128,10 +156,10 @@ export async function statementPdf(
128
156
  const rx = M + width / 2 + 10;
129
157
  const facts = [
130
158
  // The label column is 72 pt wide: »Verbrauchsauszug« does not fit.
131
- [st.title === 'Kontoauszug' ? 'Kontoauszug' : 'Auszug-Nr.', st.number],
132
- ['Zeitraum', `${deDate(st.period.from)} – ${deDate(st.period.to)}`],
159
+ [st.title === 'Kontoauszug' ? 'Kontoauszug' : t('Auszug-Nr.', 'Statement no.'), st.number],
160
+ [t('Zeitraum', 'Period'), `${deDate(st.period.from)} – ${deDate(st.period.to)}`],
133
161
  ['Chain', `${st.chainName} (${st.network})`],
134
- ['Erstellt am', `${deDate(st.issuedAt)}, ${st.issuedAt.slice(11, 16)} UTC`]
162
+ [t('Erstellt am', 'Made on'), `${deDate(st.issuedAt)}, ${st.issuedAt.slice(11, 16)} UTC`]
135
163
  ];
136
164
  for (const [k, v] of facts) {
137
165
  regular.draw(l.page, k, { x: rx, y: l.y - TYPE.body, size: TYPE.small, color: GREY });
@@ -139,7 +167,7 @@ export async function statementPdf(
139
167
  l.y -= 13;
140
168
  }
141
169
  l.y = Math.min(l.y, leftEnd) - 8;
142
- label('Konto');
170
+ label(t('Konto', 'Account'));
143
171
  text(st.account, { face: mono, size: TYPE.body });
144
172
  l.y -= 10;
145
173
  l.note(st.note, TYPE.table);
@@ -148,7 +176,7 @@ export async function statementPdf(
148
176
  /** A booking's two lines of text, and the height of its row. @param {import('./statement.js').StatementRow} r */
149
177
  const rowText = (r) => {
150
178
  const detail = [
151
- r.counterparty && `${r.debit ? 'an' : 'von'} ${r.counterparty}`,
179
+ r.counterparty && `${r.debit ? t('an', 'to') : t('von', 'from')} ${r.counterparty}`,
152
180
  r.hash && `${r.hashLabel} ${r.hash.slice(0, 10)}…${r.hash.slice(-6)}`,
153
181
  r.beleg && `Eigenbeleg ${r.beleg}`
154
182
  ]
@@ -186,7 +214,10 @@ export async function statementPdf(
186
214
  // A section: its head on a hairline. No band, no fill. A token not in the list is named by its
187
215
  // contract; what it calls itself is the contract's own claim.
188
216
  if (s.contract) {
189
- text(`${s.asset} (laut Token-Vertrag)`, { face: bold, size: TYPE.lead });
217
+ text(`${s.asset} (${t('laut Token-Vertrag', 'as the token contract says')})`, {
218
+ face: bold,
219
+ size: TYPE.lead
220
+ });
190
221
  text(s.contract, { face: mono, size: TYPE.body });
191
222
  } else text(`${s.asset} · ${st.account}`, { face: bold, size: TYPE.lead });
192
223
  l.y -= 3;
@@ -194,7 +225,10 @@ export async function statementPdf(
194
225
  l.y -= 10;
195
226
  if (s.contract) {
196
227
  text(
197
- `Token außerhalb der Liste geprüfter Token dieser Chain: Name »${s.asset}« und Nachkommastellen nennt der Vertrag selbst; maßgeblich ist seine Adresse oben.`,
228
+ t(
229
+ `Token außerhalb der Liste geprüfter Token dieser Chain: Name »${s.asset}« und Nachkommastellen nennt der Vertrag selbst; maßgeblich ist seine Adresse oben.`,
230
+ `A token outside this chain's list of checked tokens: its name "${s.asset}" and decimals are what the contract says of itself; its address above is what counts.`
231
+ ),
198
232
  { size: TYPE.small, color: GREY }
199
233
  );
200
234
  l.y -= 6;
@@ -207,9 +241,9 @@ export async function statementPdf(
207
241
  .filter((x) => x !== null);
208
242
  if (lines.length) {
209
243
  l.ensure(14 + lines.length * 11 + 8);
210
- l.at('Monatsübersicht', M, TYPE.label, regular, GREY);
211
- l.right(pay ? s.asset : 'Credits', edge(CREDIT), TYPE.label, regular, GREY);
212
- l.right(`Wert ${cur}`, edge(VALUE), TYPE.label, regular, GREY);
244
+ l.at(t('Monatsübersicht', 'The month in sums'), M, TYPE.label, regular, GREY);
245
+ l.right(pay ? s.asset : t('Credits', 'Credits'), edge(CREDIT), TYPE.label, regular, GREY);
246
+ l.right(`${t('Wert', 'Value')} ${cur}`, edge(VALUE), TYPE.label, regular, GREY);
213
247
  l.y -= 11;
214
248
  l.strong();
215
249
  l.y -= 4;
@@ -250,7 +284,15 @@ export async function statementPdf(
250
284
  };
251
285
  head();
252
286
  // opening balance
253
- l.at(`Kontostand am ${deDate(st.period.from)} (Beginn)`, M + COLS[0].width, 8, bold);
287
+ l.at(
288
+ t(
289
+ `Kontostand am ${deDate(st.period.from)} (Beginn)`,
290
+ `Balance on ${deDate(st.period.from)} (start)`
291
+ ),
292
+ M + COLS[0].width,
293
+ 8,
294
+ bold
295
+ );
254
296
  l.right(qty(s.opening), edge(BALANCE), 8, bold);
255
297
  l.y -= 13;
256
298
  l.rule();
@@ -292,7 +334,13 @@ export async function statementPdf(
292
334
  l.y -= 1;
293
335
  }
294
336
  if (s.rows.length === 0) {
295
- l.at('Keine Buchungen in diesem Zeitraum.', M + COLS[0].width, 8, regular, GREY);
337
+ l.at(
338
+ t('Keine Buchungen in diesem Zeitraum.', 'No bookings in this period.'),
339
+ M + COLS[0].width,
340
+ 8,
341
+ regular,
342
+ GREY
343
+ );
296
344
  l.y -= 13;
297
345
  }
298
346
  // sums and closing balance
@@ -301,11 +349,16 @@ export async function statementPdf(
301
349
  l.y += 1;
302
350
  l.strong();
303
351
  l.y -= 5;
304
- l.at('Summe', M + COLS[0].width, 8, regular);
352
+ l.at(t('Summe', 'Total'), M + COLS[0].width, 8, regular);
305
353
  l.right(qty(s.debit), edge(DEBIT), 8, regular);
306
354
  l.right(qty(s.credit), edge(CREDIT), 8, regular);
307
355
  l.y -= 14;
308
- l.at(`Kontostand am ${deDate(st.period.to)} (Ende)`, M + COLS[0].width, TYPE.lead, bold);
356
+ l.at(
357
+ t(`Kontostand am ${deDate(st.period.to)} (Ende)`, `Balance on ${deDate(st.period.to)} (end)`),
358
+ M + COLS[0].width,
359
+ TYPE.lead,
360
+ bold
361
+ );
309
362
  l.right(`${qty(s.closing)} ${s.asset}`, edge(BALANCE), TYPE.lead, bold);
310
363
  l.y -= 17;
311
364
  l.strong();
@@ -319,52 +372,92 @@ export async function statementPdf(
319
372
  : '';
320
373
  text(
321
374
  ok && isDust(difference)
322
- ? `Abgestimmt: Der Kontostand laut Chain nach dem Zeitraum${when} ist ${qty(s.reported)} ${s.asset}; die Differenz von ${deNumber(difference)} ${s.asset} liegt unter der dargestellten Genauigkeit (das 1 yoctoNEAR, das ein Token-Transfer als Sicherheit mitgibt, zählt nicht als Zahlung).`
375
+ ? t(
376
+ `Abgestimmt: Der Kontostand laut Chain nach dem Zeitraum${when} ist ${qty(s.reported)} ${s.asset}; die Differenz von ${deNumber(difference)} ${s.asset} liegt unter der dargestellten Genauigkeit (das 1 yoctoNEAR, das ein Token-Transfer als Sicherheit mitgibt, zählt nicht als Zahlung).`,
377
+ `Reconciled: the balance the chain reports after the period${when} is ${qty(s.reported)} ${s.asset}; the difference of ${deNumber(difference)} ${s.asset} is below the precision shown (the 1 yoctoNEAR a token transfer attaches as its security deposit is no payment).`
378
+ )
323
379
  : ok
324
- ? `Abgestimmt: Der Kontostand laut Chain nach dem Zeitraum${when} ist ${qty(s.reported)} ${s.asset} und stimmt mit Anfangsstand plus Buchungen überein.`
325
- : `Nicht abgestimmt: Der Kontostand laut Chain${when} ist ${qty(s.reported)} ${s.asset}; Differenz ${deNumber(difference)} ${s.asset} (Bewegungen, die der Leser nicht sieht, etwa Auszahlungen eines Staking-Pools).`,
380
+ ? t(
381
+ `Abgestimmt: Der Kontostand laut Chain nach dem Zeitraum${when} ist ${qty(s.reported)} ${s.asset} und stimmt mit Anfangsstand plus Buchungen überein.`,
382
+ `Reconciled: the balance the chain reports after the period${when} is ${qty(s.reported)} ${s.asset} and equals the opening balance plus the bookings.`
383
+ )
384
+ : t(
385
+ `Nicht abgestimmt: Der Kontostand laut Chain${when} ist ${qty(s.reported)} ${s.asset}; Differenz ${deNumber(difference)} ${s.asset} (Bewegungen, die der Leser nicht sieht, etwa Auszahlungen eines Staking-Pools).`,
386
+ `Not reconciled: the balance the chain reports${when} is ${qty(s.reported)} ${s.asset}; difference ${deNumber(difference)} ${s.asset} (movements the reader does not see, such as payouts of a staking pool).`
387
+ ),
326
388
  // Reconciled is the normal case and reads as text; only a difference is a warning.
327
389
  { size: TYPE.small, color: ok ? INK : WARN }
328
390
  );
329
391
  } else {
330
392
  text(
331
- `Anfangs- und Endstand abgeleitet aus dem heutigen Kontostand abzüglich aller Bewegungen seither (${aleph ? 'die Aleph-API nennt den heutigen Stand und die Summen seither' : pay ? 'der Zahlungsvertrag nennt nur den heutigen Stand' : 'die Chain hält keine alten Kontostände vor'}).`,
393
+ t(
394
+ `Anfangs- und Endstand abgeleitet aus dem heutigen Kontostand abzüglich aller Bewegungen seither (${aleph ? 'die Aleph-API nennt den heutigen Stand und die Summen seither' : pay ? 'der Zahlungsvertrag nennt nur den heutigen Stand' : 'die Chain hält keine alten Kontostände vor'}).`,
395
+ `Opening and closing balance derived from today's balance less every movement since (${aleph ? "the Aleph API names today's balance and the sums since" : pay ? "the payment contract names only today's balance" : 'the chain keeps no old balances'}).`
396
+ ),
332
397
  { size: TYPE.small, color: GREY }
333
398
  );
334
399
  }
335
400
  l.y -= 4;
336
401
  text(
337
- pay
338
- ? `Ausgänge ${money(s.eurOut)} · Eingänge ${money(s.eurIn)} · davon Verbrauch (Aufwand) ${money(s.eurUsage)}${s.unvalued ? ` · ${s.unvalued} Buchung(en) ohne Kurs` : ''} – ${valued(`zum Tageskurs von USDC, an den US-Dollar gebunden wie ${s.asset} (Kurs 00:00 UTC: CoinGecko, sonst Kraken)`, `Tageskurs von USDC, an den US-Dollar gebunden wie ${s.asset} (Kurs 00:00 UTC: CoinGecko, sonst Kraken)`)}.`
339
- : aleph
340
- ? `Ausgänge ${money(s.eurOut)} · Eingänge ${money(s.eurIn)} · davon Verbrauch (Aufwand) ${money(s.eurUsage)}${s.unvalued ? ` · ${s.unvalued} Buchung(en) ohne Kurs` : ''} – ${
341
- cur === 'EUR'
342
- ? 'Euro-Werte: USD-Preis je Credit (letzter Kauf am oder vor dem Tag, sonst Listenpreis) × EZB-Referenzkurs USD/EUR des Tages'
343
- : `Werte in ${cur}: USD-Preis je Credit (letzter Kauf am oder vor dem Tag, sonst Listenpreis)${cur === 'USD' ? '' : `, ${conversionText(cur)}`}`
344
- }.`
345
- : `Ausgänge ${money(s.eurOut)} · Eingänge ${money(s.eurIn)} · davon Netzwerkgebühren (Aufwand) ${money(s.eurFees)}${s.unvalued ? ` · ${s.unvalued} Buchung(en) ohne Kurs` : ''} – ${
346
- !s.contract
347
- ? valued(...marketOrReference(s))
348
- : s.sources?.length
349
- ? valued(
350
- `zum Kurs nach der Vertragsadresse: ${s.sources.join(' und ')}`,
351
- `Kurs nach der Vertragsadresse: ${s.sources.join(' und ')}`
352
- )
353
- : 'für diesen Token nennt keine Kursquelle einen Kurs'
354
- }.`,
402
+ L === 'en'
403
+ ? pay
404
+ ? `Out ${money(s.eurOut)} · in ${money(s.eurIn)} · of which usage (expense) ${money(s.eurUsage)}${s.unvalued ? ` · ${s.unvalued} booking(s) without a rate` : ''} – ${valued(`at the day's rate of USDC, pegged to the US dollar like ${s.asset} (rate at 00:00 UTC: CoinGecko, else Kraken)`, `the day's rate of USDC, pegged to the US dollar like ${s.asset} (rate at 00:00 UTC: CoinGecko, else Kraken)`)}.`
405
+ : aleph
406
+ ? `Out ${money(s.eurOut)} · in ${money(s.eurIn)} · of which usage (expense) ${money(s.eurUsage)}${s.unvalued ? ` · ${s.unvalued} booking(s) without a rate` : ''} – ${
407
+ cur === 'EUR'
408
+ ? 'Euro values: the USD price per credit (the last purchase on or before the day, else the list price) × the ECB reference rate USD/EUR of the day'
409
+ : `Values in ${cur}: the USD price per credit (the last purchase on or before the day, else the list price)${cur === 'USD' ? '' : `, ${conversionText(cur, L)}`}`
410
+ }.`
411
+ : `Out ${money(s.eurOut)} · in ${money(s.eurIn)} · of which network fees (expense) ${money(s.eurFees)}${s.unvalued ? ` · ${s.unvalued} booking(s) without a rate` : ''} – ${
412
+ !s.contract
413
+ ? valued(...marketOrReference(s, L))
414
+ : s.sources?.length
415
+ ? valued(
416
+ `at the rate by the contract's address: ${s.sources.map((x) => localizeSource(x, L)).join(' and ')}`,
417
+ `rate by the contract's address: ${s.sources.map((x) => localizeSource(x, L)).join(' and ')}`
418
+ )
419
+ : 'no rate source names a rate for this token'
420
+ }.`
421
+ : pay
422
+ ? `Ausgänge ${money(s.eurOut)} · Eingänge ${money(s.eurIn)} · davon Verbrauch (Aufwand) ${money(s.eurUsage)}${s.unvalued ? ` · ${s.unvalued} Buchung(en) ohne Kurs` : ''} – ${valued(`zum Tageskurs von USDC, an den US-Dollar gebunden wie ${s.asset} (Kurs 00:00 UTC: CoinGecko, sonst Kraken)`, `Tageskurs von USDC, an den US-Dollar gebunden wie ${s.asset} (Kurs 00:00 UTC: CoinGecko, sonst Kraken)`)}.`
423
+ : aleph
424
+ ? `Ausgänge ${money(s.eurOut)} · Eingänge ${money(s.eurIn)} · davon Verbrauch (Aufwand) ${money(s.eurUsage)}${s.unvalued ? ` · ${s.unvalued} Buchung(en) ohne Kurs` : ''} – ${
425
+ cur === 'EUR'
426
+ ? 'Euro-Werte: USD-Preis je Credit (letzter Kauf am oder vor dem Tag, sonst Listenpreis) × EZB-Referenzkurs USD/EUR des Tages'
427
+ : `Werte in ${cur}: USD-Preis je Credit (letzter Kauf am oder vor dem Tag, sonst Listenpreis)${cur === 'USD' ? '' : `, ${conversionText(cur)}`}`
428
+ }.`
429
+ : `Ausgänge ${money(s.eurOut)} · Eingänge ${money(s.eurIn)} · davon Netzwerkgebühren (Aufwand) ${money(s.eurFees)}${s.unvalued ? ` · ${s.unvalued} Buchung(en) ohne Kurs` : ''} – ${
430
+ !s.contract
431
+ ? valued(...marketOrReference(s))
432
+ : s.sources?.length
433
+ ? valued(
434
+ `zum Kurs nach der Vertragsadresse: ${s.sources.join(' und ')}`,
435
+ `Kurs nach der Vertragsadresse: ${s.sources.join(' und ')}`
436
+ )
437
+ : 'für diesen Token nennt keine Kursquelle einen Kurs'
438
+ }.`,
355
439
  { size: TYPE.small, color: GREY }
356
440
  );
357
441
  l.y -= 20;
358
442
  }
359
443
  if (st.unlisted)
360
444
  text(
361
- `${st.unlisted} Bewegung(en) in Token ohne verlässlichen Kurs (oft Spam) sind nur in der CSV-Datei aufgeführt.`,
445
+ t(
446
+ `${st.unlisted} Bewegung(en) in Token ohne verlässlichen Kurs (oft Spam) sind nur in der CSV-Datei aufgeführt.`,
447
+ `${st.unlisted} movement(s) in tokens without a reliable rate (often spam) are listed in the CSV file only.`
448
+ ),
362
449
  { size: TYPE.small, color: GREY }
363
450
  );
364
451
 
365
452
  // page numbers and footer on every page
366
- const data = `Daten: ${st.dataSource ?? DATA_SOURCES[st.chain] ?? st.chainName} · kein Dokument eines Kreditinstituts`;
367
- l.pages.forEach((p, i) => l.foot(p, `${st.number} · Seite ${i + 1} von ${l.pages.length}`, data));
453
+ const data = `${t('Daten', 'Data')}: ${st.dataSource ?? (L === 'en' ? DATA_SOURCES_EN : DATA_SOURCES)[st.chain] ?? st.chainName} · ${t('kein Dokument eines Kreditinstituts', 'no document of a bank')}`;
454
+ l.pages.forEach((p, i) =>
455
+ l.foot(
456
+ p,
457
+ `${st.number} · ${t('Seite', 'Page')} ${i + 1} ${t('von', 'of')} ${l.pages.length}`,
458
+ data
459
+ )
460
+ );
368
461
 
369
462
  return savePdfA(pdf, {
370
463
  title,
package/src/statement.js CHANGED
@@ -31,6 +31,7 @@ import {
31
31
  kindText,
32
32
  sourceName
33
33
  } from './document.js';
34
+ import { documentLanguage, localizeLabel, say } from './language.js';
34
35
 
35
36
  /** Smaller than the twelve decimals the documents print (and not zero). @param {string} difference */
36
37
  export const isDust = (difference) => /^-?0\.0{12}\d*$/.test(difference);
@@ -64,14 +65,39 @@ export const USAGE_NOTES = /** @type {Record<string, string>} */ ({
64
65
  'filecoin-pay': FILECOIN_PAY_USAGE_NOTE
65
66
  });
66
67
 
68
+ /** The same notes in English (language.js). */
69
+ export const USAGE_NOTES_EN = /** @type {Record<string, string>} */ ({
70
+ aleph:
71
+ 'Verbrauchsauszug (usage statement) of an Aleph Cloud account (credits), made by the account holder from the public Aleph API. ' +
72
+ 'No document of a bank and no invoice of Aleph. Usage per day and resource; value: the USD price per credit ' +
73
+ "(the last purchase on or before the day, else Aleph's list price of 1 USD per 1,000,000 credits) at the ECB reference rate of the day.",
74
+ 'filecoin-pay':
75
+ 'Verbrauchsauszug (usage statement) of a balance in the Filecoin Pay payment contract (Filecoin Onchain Cloud), made by the payer from public chain data. ' +
76
+ 'No document of a bank and no invoice of a storage provider. Usage is every settlement of a rail to its provider; ' +
77
+ 'it pays up to the time it names, so it does not cover the month exactly. Only USDFC is read; what the payer takes in through rails is missing. ' +
78
+ 'Value: USDFC is pegged to the US dollar and valued at the rate of USDC of the day.'
79
+ });
80
+
67
81
  /**
68
82
  * The note of a Verbrauchsauszug in the document's currency: what its values
69
83
  * are, said for that currency. EUR: the notes above, as they were.
70
84
  *
71
85
  * @param {string} chain from USAGE_NOTES
72
86
  * @param {string} currency
87
+ * @param {import('./language.js').DocumentLanguage} [language]
73
88
  */
74
- export function usageNote(chain, currency) {
89
+ export function usageNote(chain, currency, language = 'de') {
90
+ if (language === 'en') {
91
+ const note = USAGE_NOTES_EN[chain];
92
+ if (currency === 'EUR') return note;
93
+ const head = note.slice(0, note.indexOf('Value:'));
94
+ if (chain === 'aleph') {
95
+ const price =
96
+ "the USD price per credit (the last purchase on or before the day, else Aleph's list price of 1 USD per 1,000,000 credits)";
97
+ return `${head}Value in ${currency}: ${price}${currency === 'USD' ? '' : `, ${conversionText(currency, 'en')}`}.`;
98
+ }
99
+ return `${head}Value in ${currency}: USDFC is pegged to the US dollar and valued at the rate of USDC of the day, ${conversionText(currency, 'en')}.`;
100
+ }
75
101
  const note = USAGE_NOTES[chain];
76
102
  if (currency === 'EUR') return note;
77
103
  const head = note.slice(0, note.indexOf('Euro-Wert:'));
@@ -113,6 +139,10 @@ export const STATEMENT_NOTE =
113
139
  'Kontoauszug eines Blockchain-Kontos, erstellt vom Kontoinhaber aus öffentlichen Chain-Daten. ' +
114
140
  'Kein Dokument eines Kreditinstituts. Jede Buchung ist über ihren Transaktions-Hash in einem öffentlichen Block-Explorer nachprüfbar.';
115
141
 
142
+ export const STATEMENT_NOTE_EN =
143
+ 'Kontoauszug (account statement) of a blockchain account, made by the account holder from public chain data. ' +
144
+ 'No document of a bank. Every booking can be checked by its transaction hash in a public block explorer.';
145
+
116
146
  /**
117
147
  * @typedef {object} StatementRow
118
148
  * @property {string} date YYYY-MM-DD
@@ -147,8 +177,11 @@ export const STATEMENT_NOTE =
147
177
  * credits bought, transfers in and out, fees. One booking each instead of the day's rows below.
148
178
  *
149
179
  * @param {StatementRow[]} rows
180
+ * @param {import('./language.js').DocumentLanguage} [language]
150
181
  */
151
- export function monthly(rows) {
182
+ export function monthly(rows, language = 'de') {
183
+ /** @param {string} de @param {string} en */
184
+ const t = (de, en) => say(language, de, en);
152
185
  /** @param {StatementRow[]} rs @param {string} label @param {'debit' | 'credit'} side @returns {MonthlyLine} */
153
186
  const line = (rs, label, side) => ({
154
187
  label,
@@ -160,7 +193,7 @@ export function monthly(rows) {
160
193
  const byResource = [...new Set(rows.filter((r) => r.usage).map((r) => r.label))].map((label) =>
161
194
  line(
162
195
  rows.filter((r) => r.usage && r.label === label),
163
- `Verbrauch ${label.replace(/^Aleph Cloud \((.*)\)$/, '$1').replace(/^storage$/, 'Speicher (storage)')}`,
196
+ `${t('Verbrauch', 'Usage')} ${label.replace(/^Aleph Cloud \((.*)\)$/, '$1').replace(/^storage$/, t('Speicher (storage)', 'storage'))}`,
164
197
  'debit'
165
198
  )
166
199
  );
@@ -171,17 +204,32 @@ export function monthly(rows) {
171
204
  const fees = rows.filter((r) => r.fee);
172
205
  return {
173
206
  usage: byResource,
174
- usageTotal: usage.length ? line(usage, 'Verbrauch gesamt (Aufwand)', 'debit') : null,
207
+ usageTotal: usage.length
208
+ ? line(usage, t('Verbrauch gesamt (Aufwand)', 'Usage in all (expense)'), 'debit')
209
+ : null,
175
210
  purchases: purchases.length
176
- ? line(purchases, 'Käufe von Guthaben (Vorauszahlung; Eigenbeleg je Kauf)', 'credit')
211
+ ? line(
212
+ purchases,
213
+ t(
214
+ 'Käufe von Guthaben (Vorauszahlung; Eigenbeleg je Kauf)',
215
+ 'Purchases of credits (prepayment; an Eigenbeleg per purchase)'
216
+ ),
217
+ 'credit'
218
+ )
177
219
  : null,
178
220
  transfersIn: transfersIn.length
179
- ? line(transfersIn, 'Eingänge von anderen Konten', 'credit')
221
+ ? line(
222
+ transfersIn,
223
+ t('Eingänge von anderen Konten', 'Incoming from other accounts'),
224
+ 'credit'
225
+ )
180
226
  : null,
181
227
  transfersOut: transfersOut.length
182
- ? line(transfersOut, 'Ausgänge an andere Konten', 'debit')
228
+ ? line(transfersOut, t('Ausgänge an andere Konten', 'Outgoing to other accounts'), 'debit')
183
229
  : null,
184
- fees: fees.length ? line(fees, 'Netzwerkgebühren (Aufwand)', 'debit') : null
230
+ fees: fees.length
231
+ ? line(fees, t('Netzwerkgebühren (Aufwand)', 'Network fees (expense)'), 'debit')
232
+ : null
185
233
  };
186
234
  }
187
235
 
@@ -206,6 +254,7 @@ export function monthly(rows) {
206
254
  * @param {Record<string, string>} [p.contracts] asset → contract of a token not in the
207
255
  * chain's list whose balance is in `opening`/`closing` (the reader's balances, #93);
208
256
  * for one that moved in the period its entries name it already
257
+ * @param {import('./language.js').DocumentLanguage} [p.language] `de` (the default) or `en` (language.js)
209
258
  */
210
259
  export function buildStatement({
211
260
  payer,
@@ -223,9 +272,11 @@ export function buildStatement({
223
272
  issuedAt,
224
273
  dataSource,
225
274
  currency: asked,
226
- contracts = {}
275
+ contracts = {},
276
+ language: askedLanguage
227
277
  }) {
228
278
  const currency = documentCurrency(asked);
279
+ const L = documentLanguage(askedLanguage);
229
280
  checkValued(entries, currency);
230
281
  // An Aleph credit purchase (kind `swap`) is the payment on another chain; the
231
282
  // credits it bought are the incoming row. Only that row belongs on the statement.
@@ -254,9 +305,9 @@ export function buildStatement({
254
305
  date: e.date,
255
306
  time: e.time.slice(11, 19),
256
307
  // Filecoin Pay: up to when a settlement paid its rail (the entry's memo).
257
- text: `${kindText(e)}${e.type === 'received' ? ' (Eingang)' : ''}${e.chain === 'filecoin-pay' && e.kind === 'usage' && e.memo ? `, ${e.memo}` : ''}`,
308
+ text: `${kindText(e, L)}${e.type === 'received' ? say(L, ' (Eingang)', ' (incoming)') : ''}${e.chain === 'filecoin-pay' && e.kind === 'usage' && e.memo ? `, ${localizeLabel(e.memo, L)}` : ''}`,
258
309
  counterparty: e.counterpartyLabel
259
- ? `${e.counterpartyLabel} · ${e.counterparty}`
310
+ ? `${localizeLabel(e.counterpartyLabel, L)} · ${e.counterparty}`
260
311
  : e.counterparty,
261
312
  hash: e.hash,
262
313
  explorerUrl: e.explorerUrl,
@@ -271,7 +322,8 @@ export function buildStatement({
271
322
  purchase: e.type === 'received' && e.counterparty === 'aleph',
272
323
  label: e.counterpartyLabel,
273
324
  // Aleph's usage names a resource; a Filecoin Pay settlement is a transaction.
274
- hashLabel: e.kind === 'usage' && e.chain === 'aleph' ? 'Ressource' : 'Tx'
325
+ hashLabel:
326
+ e.kind === 'usage' && e.chain === 'aleph' ? say(L, 'Ressource', 'Resource') : 'Tx'
275
327
  });
276
328
  }
277
329
  const debit = sum(rows.map((r) => r.debit || '0'));
@@ -291,7 +343,7 @@ export function buildStatement({
291
343
  debit,
292
344
  credit,
293
345
  rows,
294
- monthly: monthly(rows),
346
+ monthly: monthly(rows, L),
295
347
  eurOut: sum(rows.filter((r) => r.debit && r.eur).map((r) => r.eur.replace(/^-/, ''))),
296
348
  eurIn: sum(rows.filter((r) => r.credit && r.eur).map((r) => r.eur)),
297
349
  eurFees: sum(rows.filter((r) => r.fee && r.eur).map((r) => r.eur.replace(/^-/, ''))),
@@ -313,7 +365,12 @@ export function buildStatement({
313
365
  const usage = Object.hasOwn(USAGE_NOTES, chain);
314
366
  return {
315
367
  kind: 'kontoauszug',
316
- title: usage ? 'Verbrauchsauszug' : 'Kontoauszug',
368
+ // The German name stays the document's name; an English one adds what it is.
369
+ title: usage
370
+ ? say(L, 'Verbrauchsauszug', 'Usage statement (Verbrauchsauszug)')
371
+ : say(L, 'Kontoauszug', 'Account statement (Kontoauszug)'),
372
+ usage,
373
+ language: L,
317
374
  number: number || `KA-${period.from}`,
318
375
  issuedAt: issuedAt ?? new Date().toISOString(),
319
376
  holder: { name: payer.name.trim(), address: payer.address.trim() },
@@ -323,7 +380,8 @@ export function buildStatement({
323
380
  dataSource: dataSourceOf(
324
381
  chain,
325
382
  CHAIN_NAMES[/** @type {keyof typeof CHAIN_NAMES} */ (chain)] ?? chain,
326
- dataSource
383
+ dataSource,
384
+ L
327
385
  ),
328
386
  network,
329
387
  testnet: network !== 'mainnet',
@@ -333,7 +391,7 @@ export function buildStatement({
333
391
  at,
334
392
  sections,
335
393
  unlisted: mine.filter((e) => !e.priceAs && !assets.includes(e.asset)).length,
336
- note: usage ? usageNote(chain, currency) : STATEMENT_NOTE
394
+ note: usage ? usageNote(chain, currency, L) : L === 'en' ? STATEMENT_NOTE_EN : STATEMENT_NOTE
337
395
  };
338
396
  }
339
397