@le-space/eigenbeleg 0.7.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.
package/README.md CHANGED
@@ -1,17 +1,23 @@
1
1
  # @le-space/eigenbeleg
2
2
 
3
- The Eigenbeleg and the Kontoauszug of Le Space's tools – [Belege](https://github.com/Le-Space/belege) and the [Eigenbeleg](https://github.com/Le-Space/eigenbeleg-agent) API and web UI: what they say, drawn as PDF/A-2b ([`@le-space/pdf`](../pdf), text in any script) and written as CSV. Runs in a browser and in Node; the same document is the same file in both. The documents are German, for German bookkeeping.
3
+ The Eigenbeleg and the Kontoauszug of Le Space's tools – [Belege](https://github.com/Le-Space/belege) and the [Eigenbeleg](https://github.com/Le-Space/eigenbeleg-agent) API and web UI: what they say, drawn as PDF/A-2b ([`@le-space/pdf`](../pdf), text in any script) and written as CSV. Runs in a browser and in Node; the same document is the same file in both. The documents are German, for German bookkeeping, or English when asked for (below).
4
4
 
5
5
  An Eigenbeleg is a receipt the payer writes for a payment that has no receipt from the other side. It is never an invoice, and never one written for somebody else.
6
6
 
7
- - **A period's Eigenbeleg** (Eigenbeleg's): `valueEntries(entries, rates)` values [`@le-space/ledger`](../ledger) entries at the day's rate (`rates.rateFor(asset, day)`, e.g. from [`@le-space/rates`](../rates); `fixedRates` for tests; Aleph credits at their USD price per credit). `buildDocument({ payer, chain, network, period, entries, number, includeKinds, layout })` puts the payments to the network on it (fees, storage deposits; transfers only when included) and says of every other movement why not; `layout: 'collective'` (one Sammel-Eigenbeleg) or `'single'` (one per transaction, numbered up from the first, `nthNumber`). `eigenbelegPdf(doc, { logo })`, `eigenbelegCsv(doc)` (semicolons, decimal commas, BOM; formulas defused).
8
- - **The Kontoauszug** (Eigenbeleg's): `buildStatement({ payer, account, chain, period, entries, opening, closing, method, belege })` – opening balance, each booking with debit, credit and running balance, closing balance checked against the chain (`reconciled(difference)`: exactly, or but for dust below the twelve decimals the documents print, `isDust`, such as NEAR's 1 yocto deposit of a token transfer); Aleph credits and a payer's balance in Filecoin Pay (chain `filecoin-pay`, the entries of `@le-space/chains/filecoin-pay`'s `filecoinPayEntries`) as a monthly **Verbrauchsauszug**, each with its own note (`USAGE_NOTES`). `statementPdf(st, { logo, chart })`. Above each list of bookings stands a small diagram ([#889](https://github.com/Le-Space/belege/issues/889)), drawn as vectors from [`@le-space/charts`](../charts): the balance over the period on a Kontoauszug, the consumption per resource on a Verbrauchsauszug, per day (per month where the period is longer than a quarter), in the asset's own unit; `chart: false` leaves it out. `statementChart(st, section)` gives its series and its scene, for an API's answer or `svg(scene)`; `drawScene(page, scene, { x, top, fonts })` draws any scene on a PDF page. `logo: true` draws the chain's mark, small, beside the title (NEAR, Akash, Filecoin, Aleph; from `@le-space/pdf`'s `LOGOS`, sources and terms in its `assets/README.md`); off unless asked for.
7
+ - **A period's Eigenbeleg** (Eigenbeleg's): `valueEntries(entries, rates)` values [`@le-space/ledger`](../ledger) entries at the day's rate (`rates.rateFor(asset, day)`, e.g. from [`@le-space/rates`](../rates); `fixedRates` for tests; Aleph credits at their USD price per credit; an EVM token not in the chain's list – `listed: false`, by its contract – only through `rates.tokenRateFor({ asset, contract, chain, block, decimals }, day)`, e.g. `@le-space/rates` `rate(asset, day, { contract, chain, block, decimals })`: CoinGecko by contract, else a DEX pool at the block; without it such a token stays unvalued, and its symbol, the token's own claim, is never asked for as a market asset, #93). `buildDocument({ payer, chain, network, period, entries, number, includeKinds, layout })` puts the payments to the network on it (fees, storage deposits; transfers only when included) and says of every other movement why not; `layout: 'collective'` (one Sammel-Eigenbeleg) or `'single'` (one per transaction, numbered up from the first, `nthNumber`). `eigenbelegPdf(doc, { logo })`, `eigenbelegCsv(doc)` (semicolons, decimal commas, BOM; formulas defused).
8
+ - **The Kontoauszug** (Eigenbeleg's): `buildStatement({ payer, account, chain, period, entries, opening, closing, method, belege })` – opening balance, each booking with debit, credit and running balance, closing balance checked against the chain (`reconciled(difference)`: exactly, or but for dust below the twelve decimals the documents print, `isDust`, such as NEAR's 1 yocto deposit of a token transfer); Aleph credits and a payer's balance in Filecoin Pay (chain `filecoin-pay`, the entries of `@le-space/chains/filecoin-pay`'s `filecoinPayEntries`) as a monthly **Verbrauchsauszug**, each with its own note (`USAGE_NOTES`). An EVM token not in the chain's list (`listed: false`, #93) gets a section of its own, named by its contract (`section.contract`; for one with a balance and no booking in the period from `contracts: { asset: '0x…' }`): _XYZ (laut Token-Vertrag)_ with the address below, the symbol and decimals marked as the contract's own claim, and its values said to be at a rate by contract address (`section.sources`), or that no source has one. A section that does not fit on the rest of the page starts on a new one. `statementPdf(st, { logo, chart })`. Above each list of bookings stands a small diagram ([#889](https://github.com/Le-Space/belege/issues/889)), drawn as vectors from [`@le-space/charts`](../charts): the balance over the period on a Kontoauszug, the consumption per resource on a Verbrauchsauszug, per day (per month where the period is longer than a quarter), in the asset's own unit; `chart: false` leaves it out. `statementChart(st, section)` gives its series and its scene, for an API's answer or `svg(scene)`; `drawScene(page, scene, { x, top, fonts })` draws any scene on a PDF page. `logo: true` draws the chain's mark, small, beside the title (NEAR, Akash, Filecoin, Aleph; from `@le-space/pdf`'s `LOGOS`, sources and terms in its `assets/README.md`); off unless asked for.
9
9
  - **Another currency than the euro** ([eigenbeleg-agent#72](https://github.com/Le-Space/eigenbeleg-agent/issues/72)): `valueEntries(entries, rates, { currency })`, `buildDocument({ …, currency })` and `buildStatement({ …, currency })` take the document's currency, EUR when none is given – `DOCUMENT_CURRENCIES`: EUR, USD, CHF, GBP, SEK, NOK, DKK, PLN, CZK, HUF, RON, ISK, TRY (through the ECB's reference rate) and RUB (the Bank of Russia's official rate). The rates handed in are in that currency and say so (`{ rate, source, date, currency }`; `@le-space/rates` `rate(asset, date, { currency })`), `source` naming both legs; a value in one currency under a head in another is refused. The documents then say _Kurs CHF_, _Wert CHF_, amounts as `1.234,56 CHF`, sums rounded to the currency's own decimals (ISK: none), and how the value came about (`conversionText`, `usageNote`); Aleph credits in USD are Aleph's own USD price, without a rate. The fields named `eur…` (`entry.eur`, `totals.eur`, `eurOut` …) keep their names and hold the value in the document's currency, with `currency` beside them. An EUR document is the same file as before. `bookingPdf` is Belege's own booking and stays in euro.
10
10
  - **The Eigenbeleg of one booking** (Belege's, `@le-space/eigenbeleg/booking`, `/booking-pdf`): `bookingPdf(doc)` for a `BookingEigenbeleg` – a bank booking or a crypto payment, with an own wallet's transaction in full (whole hash, both addresses, every movement with the gas, the explorer link as a QR code). The booking's context is the caller's to gather. `nextSelfNumber(receipts, year)` – the range EB-YYYY-NNN.
11
11
  - **A statement Eigenbeleg** (Belege's Aleph, Akash and travel statements, `@le-space/eigenbeleg/statement-layout`): `statementLayout({ title, created, continuation })` → `head`, `field`, `rule`, `heading`, `table` (the header repeats on a new page), `signature`, `save`.
12
12
 
13
13
  Every PDF has Eigenbeleg's look (`layout.js`, [#951](https://github.com/Le-Space/belege/issues/951)): A4 with 48 pt margins, the title first and a strong rule under the head, small grey labels, rules in two weights and no fills or boxes, a total between two rules, colour for a warning only, page numbers at the foot, a line to sign. The sizes, colours and rule weights are tokens (`TYPE`, `INK`, `GREY`, `RULE`, `WARN`, `STROKE`); nothing is set outside them. `creator` names the program in the metadata (`eigenbeleg` for the period's documents, `Belege` for a booking's and a statement's unless given).
14
14
 
15
+ ## English documents
16
+
17
+ `buildDocument({ …, language: 'en' })` and `buildStatement({ …, language: 'en' })` make the same documents in English (`language.js`; `de` is the default, and a German document is the same file as before). The PDF and the CSV read the language from the document (`doc.language`, `st.language`): English words, a decimal point and thousands commas (`1,234.5`), the currency's code after an amount (`12.34 EUR`) and ISO dates (`2026-10-05`). The German names of the documents stay beside the English ones – _Eigenbeleg (self-issued receipt)_, _Account statement (Kontoauszug)_, _Usage statement (Verbrauchsauszug)_ – since that is what they are and what a German bookkeeper looks for. The CSV keeps its semicolons (texts hold commas) and takes decimal points.
18
+
19
+ The rates' sources and the readers' labels come as German text (the caller's rates, [`@le-space/rates`](../rates)' reference value, [`@le-space/chains`](../chains)' counterparty labels); an English document names them in English through `localizeSource` and `localizeLabel`, rule by known wording – what no rule knows, such as an account's own name, stays as it is. A German tax office may ask for a translation of a document in another language (§ 87 AO): English documents are for books kept in English and for readers who need them.
20
+
15
21
  ## The issuer's own logo
16
22
 
17
23
  An Eigenbeleg is issued by the payer, so the logo that belongs on it is the payer's ([#906](https://github.com/Le-Space/belege/issues/906)). `eigenbelegPdf(doc, { issuerLogo })`, `bookingPdf(doc, { issuerLogo })` and `statementLayout({ …, issuerLogo })` take the bytes of a PNG or JPEG file and draw it large, as a letterhead: top right, fitted into about 70 × 25 mm (`ISSUER_LOGO_BOX`, 200 × 70 pt) with its proportions kept, the text below it and not above 45 mm from the top edge (`LETTERHEAD`, the head zone of DIN 5008 form B). Without a logo the page is as before. The chain's mark (`logo: true`) is the network's, not the issuer's: on an Eigenbeleg it stays very small beside the title (`MARK_SIZE.small`); on a Kontoauszug or Verbrauchsauszug, which shows what the account did and is not the issuer's own receipt, it is larger (`MARK_SIZE.large`) and the statement carries no issuer's logo. The package ships no such picture and fetches none: the caller hands it in.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@le-space/eigenbeleg",
3
- "version": "0.7.0",
3
+ "version": "0.9.0",
4
4
  "description": "The Eigenbeleg and the Kontoauszug of Le Space's tools: a payer's own receipt for payments without one from the other side (a period's network fees, one booking in any script), a blockchain account's statement (Aleph credits as a Verbrauchsauszug), as PDF/A-2b and CSV. Browser and Node; the rates handed in.",
5
5
  "license": "AGPL-3.0-or-later",
6
6
  "type": "module",
@@ -37,15 +37,15 @@
37
37
  "pdf-lib": "1.17.1",
38
38
  "uqr": "0.1.3",
39
39
  "@le-space/charts": "^0.2.0",
40
- "@le-space/pdf": "^0.3.0",
41
- "@le-space/ledger": "^0.3.1"
40
+ "@le-space/ledger": "^0.3.1",
41
+ "@le-space/pdf": "^0.3.0"
42
42
  },
43
43
  "devDependencies": {
44
44
  "@noble/hashes": "2.4.0",
45
45
  "prettier": "3.6.2",
46
46
  "unpdf": "1.8.1",
47
- "@le-space/browser-test": "0.1.0",
48
- "@le-space/chains": "^0.8.0"
47
+ "@le-space/chains": "^0.9.1",
48
+ "@le-space/browser-test": "0.1.0"
49
49
  },
50
50
  "scripts": {
51
51
  "test": "node --test --test-reporter=spec \"test/*.test.js\"",
package/src/csv.js CHANGED
@@ -6,9 +6,13 @@
6
6
  // A cell that starts like a formula (= + - @) is prefixed with ' so a
7
7
  // spreadsheet shows it as text: account names and memos come from the chain,
8
8
  // where anyone can write anything.
9
+ //
10
+ // In English (`doc.language`, language.js): English heads and words, decimal
11
+ // points; still semicolons, since texts hold commas.
9
12
 
10
13
  import { round } from '@le-space/ledger';
11
14
  import { currencyPlaces, kindText } from './document.js';
15
+ import { localizeLabel, localizeSource } from './language.js';
12
16
 
13
17
  /** The head; rate and value name the document's currency. @param {string} currency */
14
18
  const header = (currency) => [
@@ -34,7 +38,32 @@ const header = (currency) => [
34
38
  'Hinweis'
35
39
  ];
36
40
 
41
+ /** The head in English. @param {string} currency */
42
+ const headerEn = (currency) => [
43
+ 'Receipt number',
44
+ 'Position',
45
+ 'Date (UTC)',
46
+ 'Time (UTC)',
47
+ 'Chain',
48
+ 'Network',
49
+ 'Own address',
50
+ 'Kind',
51
+ 'Direction',
52
+ 'Counterparty',
53
+ 'Asset',
54
+ 'Token contract',
55
+ 'Amount',
56
+ `Rate ${currency}`,
57
+ `Value ${currency}`,
58
+ 'Rate source',
59
+ 'Transaction hash',
60
+ 'Explorer',
61
+ 'On Eigenbeleg',
62
+ 'Note'
63
+ ];
64
+
37
65
  const DIRECTION = { sent: 'Ausgang', received: 'Eingang', fee: 'Gebühr' };
66
+ const DIRECTION_EN = { sent: 'out', received: 'in', fee: 'fee' };
38
67
 
39
68
  /** `-0.5` → `-0,5` (a plain number for a spreadsheet: no grouping). @param {string} s */
40
69
  const num = (s) => String(s).replace('.', ',');
@@ -42,7 +71,7 @@ const num = (s) => String(s).replace('.', ',');
42
71
  /** @param {unknown} v */
43
72
  function cell(v) {
44
73
  let s = String(v ?? '');
45
- if (/^[=+\-@\t\r]/.test(s) && !/^-?\d+(,\d+)?$/.test(s)) s = `'${s}`;
74
+ if (/^[=+\-@\t\r]/.test(s) && !/^-?\d+([,.]\d+)?$/.test(s)) s = `'${s}`;
46
75
  return /[;"\r\n]/.test(s) ? `"${s.replace(/"/g, '""')}"` : s;
47
76
  }
48
77
 
@@ -52,8 +81,12 @@ function cell(v) {
52
81
  */
53
82
  export function eigenbelegCsv(doc) {
54
83
  const currency = doc.currency ?? 'EUR';
84
+ const en = doc.language === 'en';
85
+ /** A plain number in the document's language: a decimal comma, or a point. @param {string} x */
86
+ const n = (x) => (en ? String(x) : num(x));
87
+ const yes = en ? 'yes' : 'ja';
55
88
  /** @type {unknown[][]} */
56
- const rows = [header(currency)];
89
+ const rows = [(en ? headerEn : header)(currency)];
57
90
  const places = currencyPlaces(currency);
58
91
  const numberOf = (/** @type {number | string} */ pos) =>
59
92
  doc.layout === 'single' ? (doc.transactions[Number(pos) - 1]?.number ?? '') : doc.number;
@@ -66,18 +99,20 @@ export function eigenbelegCsv(doc) {
66
99
  e.chain,
67
100
  e.network,
68
101
  e.account,
69
- kindText(e),
70
- DIRECTION[e.type],
71
- e.counterpartyLabel ? `${e.counterpartyLabel} (${e.counterparty})` : e.counterparty,
102
+ kindText(e, doc.language),
103
+ (en ? DIRECTION_EN : DIRECTION)[e.type],
104
+ e.counterpartyLabel
105
+ ? `${localizeLabel(e.counterpartyLabel, doc.language)} (${e.counterparty})`
106
+ : e.counterparty,
72
107
  e.asset,
73
108
  e.contract,
74
- num(e.amount),
75
- e.eur ? num(e.eur.rate) : '',
76
- e.eur ? num(e.eur.value) : '',
77
- e.eur?.source ?? '',
109
+ n(e.amount),
110
+ e.eur ? n(e.eur.rate) : '',
111
+ e.eur ? n(e.eur.value) : '',
112
+ localizeSource(e.eur?.source ?? '', doc.language),
78
113
  e.hash,
79
114
  e.explorerUrl,
80
- on ? 'ja' : 'nein',
115
+ on ? yes : en ? 'no' : 'nein',
81
116
  why
82
117
  ];
83
118
  for (const p of doc.positions) rows.push(line(p.entry, p.pos, true, ''));
@@ -85,7 +120,7 @@ export function eigenbelegCsv(doc) {
85
120
  rows.push([]);
86
121
  rows.push([
87
122
  doc.layout === 'single' ? '' : doc.number,
88
- 'Summe',
123
+ en ? 'Total' : 'Summe',
89
124
  '',
90
125
  '',
91
126
  doc.chain,
@@ -98,11 +133,13 @@ export function eigenbelegCsv(doc) {
98
133
  '',
99
134
  '',
100
135
  '',
101
- num(round(`-${doc.totals.eurExact}`, places)),
102
- `${currency === 'EUR' ? 'gerundet auf Cent' : places ? `gerundet auf ${places} Nachkommastellen` : 'gerundet auf ganze Beträge'}, ungerundet ${doc.totals.eurExact === '0' ? '0' : '-' + num(doc.totals.eurExact)}`,
136
+ n(round(`-${doc.totals.eurExact}`, places)),
137
+ en
138
+ ? `${currency === 'EUR' ? 'rounded to cents' : places ? `rounded to ${places} decimals` : 'rounded to whole amounts'}, unrounded ${doc.totals.eurExact === '0' ? '0' : '-' + doc.totals.eurExact}`
139
+ : `${currency === 'EUR' ? 'gerundet auf Cent' : places ? `gerundet auf ${places} Nachkommastellen` : 'gerundet auf ganze Beträge'}, ungerundet ${doc.totals.eurExact === '0' ? '0' : '-' + num(doc.totals.eurExact)}`,
103
140
  '',
104
141
  '',
105
- 'ja',
142
+ yes,
106
143
  ''
107
144
  ]);
108
145
  return '\uFEFF' + rows.map((r) => r.map(cell).join(';')).join('\r\n') + '\r\n';
package/src/document.js CHANGED
@@ -26,7 +26,17 @@
26
26
 
27
27
  import { normalize, round, sum } from '@le-space/ledger';
28
28
 
29
- /* The document is German: it is for German bookkeeping. */
29
+ import {
30
+ documentLanguage,
31
+ enDate,
32
+ enFixed,
33
+ enNumber,
34
+ localizeLabel,
35
+ localizeSource,
36
+ say
37
+ } from './language.js';
38
+
39
+ /* The document is German unless asked for in English (language.js): it is for German bookkeeping. */
30
40
 
31
41
  export const NOTE =
32
42
  'Eigenbeleg. Für diese Zahlung gibt es keinen Fremdbeleg: Empfänger ist ein Peer-to-Peer-Netzwerk ohne rechnungsstellende Organisation. ' +
@@ -37,13 +47,35 @@ export const ALEPH_NOTE =
37
47
  'Eigenbeleg. Für diese Zahlung gibt es keinen Fremdbeleg: Aleph-Cloud-Guthaben (Credits) wird per Token-Zahlung an das Aleph-Netzwerk gekauft; Aleph stellt dafür keine Rechnung aus. ' +
38
48
  'Ausgestellt vom Zahlenden auf Grundlage der öffentlichen Transaktion; jede Position ist über ihren Transaktions-Hash in einem öffentlichen Block-Explorer nachprüfbar.';
39
49
 
50
+ /** The notes in English (language.js). */
51
+ export const NOTE_EN =
52
+ 'Eigenbeleg (self-issued receipt). There is no receipt from the other side for this payment: the recipient is a peer-to-peer network without an organisation that issues invoices. ' +
53
+ 'Issued by the payer from the public transaction; every position can be checked by its transaction hash in a public block explorer.';
54
+
55
+ export const ALEPH_NOTE_EN =
56
+ 'Eigenbeleg (self-issued receipt). There is no receipt from the other side for this payment: Aleph Cloud credits are bought by a token payment to the Aleph network; Aleph issues no invoice for it. ' +
57
+ 'Issued by the payer from the public transaction; every position can be checked by its transaction hash in a public block explorer.';
58
+
40
59
  /**
41
60
  * Why there is no invoice for a payment on this chain: the recipient line and the reason, as the Eigenbeleg prints them.
42
61
  *
43
62
  * @param {string} chain
44
63
  * @param {string} chainName
64
+ * @param {import('./language.js').DocumentLanguage} [language]
45
65
  */
46
- export function noInvoice(chain, chainName) {
66
+ export function noInvoice(chain, chainName, language = 'de') {
67
+ if (language === 'en')
68
+ return chain === 'aleph'
69
+ ? {
70
+ recipient: `${chainName}: purchase of credits by a token payment to the network, without an invoice`,
71
+ why: 'Aleph Cloud credits are bought by a token payment to the Aleph network; Aleph issues no invoice for it.',
72
+ note: ALEPH_NOTE_EN
73
+ }
74
+ : {
75
+ recipient: `${chainName}: peer-to-peer network without an organisation that issues invoices`,
76
+ why: 'The recipient is a peer-to-peer network without an organisation that issues invoices; it issues none.',
77
+ note: NOTE_EN
78
+ };
47
79
  if (chain === 'aleph')
48
80
  return {
49
81
  recipient: `${chainName}: Kauf von Guthaben per Token-Zahlung an das Netzwerk, ohne Rechnung`,
@@ -60,6 +92,9 @@ export function noInvoice(chain, chainName) {
60
92
  export const NOT_AN_INVOICE =
61
93
  'Dies ist keine Rechnung und kein Beleg eines Dritten. Le Space stellt keine Rechnungen für andere aus.';
62
94
 
95
+ export const NOT_AN_INVOICE_EN =
96
+ 'This is no invoice and no receipt of a third party. Le Space issues no invoices for others.';
97
+
63
98
  /**
64
99
  * The currencies a document can be kept in (Le-Space/eigenbeleg-agent#72),
65
100
  * each with the decimals its totals are rounded to (ISO 4217) and where its
@@ -104,10 +139,15 @@ export const currencyPlaces = (currency) => DOCUMENT_CURRENCIES[documentCurrency
104
139
  * is: the ECB's reference rate, or the Bank of Russia's official rate.
105
140
  *
106
141
  * @param {string} currency
142
+ * @param {import('./language.js').DocumentLanguage} [language]
107
143
  */
108
- export function conversionText(currency) {
109
- const ecb = 'zum Euro-Referenzkurs der EZB des Tages oder des letzten davor';
144
+ export function conversionText(currency, language = 'de') {
110
145
  if (documentCurrency(currency) === 'EUR') return '';
146
+ if (language === 'en')
147
+ return DOCUMENT_CURRENCIES[currency].via === 'cbr'
148
+ ? `converted through the euro into ${currency} at the official rate of the Bank of Russia valid on the day`
149
+ : `converted through the euro into ${currency} at the ECB's euro reference rate of the day or the last one before it`;
150
+ const ecb = 'zum Euro-Referenzkurs der EZB des Tages oder des letzten davor';
111
151
  if (DOCUMENT_CURRENCIES[currency].via === 'cbr')
112
152
  return `über den Euro in ${currency} umgerechnet zum amtlichen Kurs der Bank von Russland, gültig am Tag`;
113
153
  return `über den Euro in ${currency} umgerechnet ${ecb}`;
@@ -162,16 +202,32 @@ export const KIND_TEXT = {
162
202
  usage: 'Verbrauch (aus Guthaben abgerechnet)'
163
203
  };
164
204
 
205
+ export const KIND_TEXT_EN = {
206
+ fee: 'Network fee (gas)',
207
+ storage: 'Storage deposit',
208
+ transfer: 'Transfer',
209
+ call: 'Payment to a contract',
210
+ stake: 'Staking (no payment)',
211
+ unstake: 'Unstaking',
212
+ reward: 'Staking reward',
213
+ swap: 'Swap',
214
+ escrow: 'Deposit for a deployment (escrow)',
215
+ usage: 'Usage (billed from the balance)'
216
+ };
217
+
165
218
  /**
166
219
  * What an entry's kind is called on the documents. An Aleph credit purchase is a swap
167
220
  * of a token for credits in the ledger; for the books it is the purchase of a balance.
168
221
  *
169
222
  * @param {{ chain: string, kind: string }} e
223
+ * @param {import('./language.js').DocumentLanguage} [language]
170
224
  */
171
- export const kindText = (e) =>
225
+ export const kindText = (e, language = 'de') =>
172
226
  e.chain === 'aleph' && e.kind === 'swap'
173
- ? 'Kauf von Guthaben (Credits)'
174
- : (KIND_TEXT[/** @type {keyof typeof KIND_TEXT} */ (e.kind)] ?? e.kind);
227
+ ? say(language, 'Kauf von Guthaben (Credits)', 'Purchase of credits')
228
+ : ((language === 'en' ? KIND_TEXT_EN : KIND_TEXT)[
229
+ /** @type {keyof typeof KIND_TEXT} */ (e.kind)
230
+ ] ?? e.kind);
175
231
 
176
232
  /** The chains Eigenbeleg makes documents for, by id (as @le-space/chains names them). */
177
233
  export const CHAIN_NAMES = {
@@ -203,6 +259,18 @@ export const DATA_SOURCES = /** @type {Record<string, string>} */ ({
203
259
  doichain: 'ElectrumX-Server des Doichain-Netzes'
204
260
  });
205
261
 
262
+ export const DATA_SOURCES_EN = /** @type {Record<string, string>} */ ({
263
+ near: 'NearBlocks.io APIs, NEAR archival RPC',
264
+ filecoin: 'Filfox',
265
+ akash: 'Akash RPC, Akash Console',
266
+ aleph: 'Aleph API (api2.aleph.im)',
267
+ 'filecoin-pay': 'Filecoin Pay index (Goldsky), Blockscout, Filfox',
268
+ ethereum: 'Alchemy APIs (Ethereum Mainnet)',
269
+ base: 'Alchemy APIs (Base Mainnet)',
270
+ bitcoin: 'Esplora API of mempool.space',
271
+ doichain: 'ElectrumX servers of the Doichain network'
272
+ });
273
+
206
274
  /**
207
275
  * The data source a document names: the one the caller read from when it
208
276
  * says so (an own Esplora, say), else the chain's usual one.
@@ -210,9 +278,10 @@ export const DATA_SOURCES = /** @type {Record<string, string>} */ ({
210
278
  * @param {string} chain
211
279
  * @param {string} chainName
212
280
  * @param {string} [given]
281
+ * @param {import('./language.js').DocumentLanguage} [language]
213
282
  */
214
- export const dataSourceOf = (chain, chainName, given) =>
215
- given?.trim() || DATA_SOURCES[chain] || chainName;
283
+ export const dataSourceOf = (chain, chainName, given, language = 'de') =>
284
+ given?.trim() || (language === 'en' ? DATA_SOURCES_EN : DATA_SOURCES)[chain] || chainName;
216
285
 
217
286
  /**
218
287
  * @typedef {object} Payer who pays and issues the Eigenbeleg
@@ -265,6 +334,7 @@ export const dataSourceOf = (chain, chainName, given) =>
265
334
  * @param {string} [p.currency] the document's currency (DOCUMENT_CURRENCIES), EUR when not
266
335
  * given; the entries are valued in it. The fields named `eur…` hold the values in this
267
336
  * currency: they keep the name they had when every document was in euro.
337
+ * @param {import('./language.js').DocumentLanguage} [p.language] `de` (the default) or `en` (language.js)
268
338
  */
269
339
  export function buildDocument({
270
340
  payer,
@@ -277,11 +347,13 @@ export function buildDocument({
277
347
  issuedAt,
278
348
  layout = 'collective',
279
349
  dataSource,
280
- currency: asked
350
+ currency: asked,
351
+ language: askedLanguage
281
352
  }) {
282
353
  if (layout !== 'collective' && layout !== 'single')
283
354
  throw new Error('layout: collective or single');
284
355
  const currency = documentCurrency(asked);
356
+ const L = documentLanguage(askedLanguage);
285
357
  checkValued(entries, currency);
286
358
  checkPayer(payer);
287
359
  const kinds = new Set(includeKinds);
@@ -293,29 +365,45 @@ export function buildDocument({
293
365
  for (const e of entries) {
294
366
  const why =
295
367
  e.type === 'received'
296
- ? 'Eingang, keine Zahlung'
368
+ ? say(L, 'Eingang, keine Zahlung', 'incoming, no payment')
297
369
  : !e.success
298
- ? 'fehlgeschlagen, nichts gezahlt'
370
+ ? say(L, 'fehlgeschlagen, nichts gezahlt', 'failed, nothing paid')
299
371
  : own.has(e.counterparty)
300
- ? 'Umbuchung zwischen eigenen Adressen'
372
+ ? say(L, 'Umbuchung zwischen eigenen Adressen', 'transfer between own addresses')
301
373
  : !kinds.has(e.kind)
302
374
  ? e.kind === 'transfer' || e.kind === 'call'
303
- ? 'Zahlung an ein Konto: Fremdbeleg anfordern oder bewusst einbeziehen'
375
+ ? say(
376
+ L,
377
+ 'Zahlung an ein Konto: Fremdbeleg anfordern oder bewusst einbeziehen',
378
+ 'payment to an account: ask for its receipt or include it on purpose'
379
+ )
304
380
  : e.kind === 'escrow'
305
- ? 'Hinterlegung (Escrow), noch kein Endbetrag'
381
+ ? say(
382
+ L,
383
+ 'Hinterlegung (Escrow), noch kein Endbetrag',
384
+ 'deposit (escrow), no final amount yet'
385
+ )
306
386
  : e.kind === 'usage'
307
- ? 'Verbrauch aus Guthaben: steht im Verbrauchsauszug'
308
- : 'keine Zahlung an das Netzwerk'
387
+ ? say(
388
+ L,
389
+ 'Verbrauch aus Guthaben: steht im Verbrauchsauszug',
390
+ 'usage from a balance: on the usage statement'
391
+ )
392
+ : say(L, 'keine Zahlung an das Netzwerk', 'no payment to the network')
309
393
  : !e.eur
310
- ? 'kein verlässlicher Kurs (unbekannter Token)'
394
+ ? say(
395
+ L,
396
+ 'kein verlässlicher Kurs (unbekannter Token)',
397
+ 'no reliable rate (unknown token)'
398
+ )
311
399
  : '';
312
400
  if (why) excluded.push({ entry: e, why });
313
401
  else
314
402
  positions.push({
315
403
  pos: 0,
316
404
  entry: e,
317
- what: kindText(e),
318
- recipient: e.counterpartyLabel || e.counterparty
405
+ what: kindText(e, L),
406
+ recipient: localizeLabel(e.counterpartyLabel, L) || e.counterparty
319
407
  });
320
408
  }
321
409
  const first = number || `EB-${period.to.slice(0, 4)}-001`;
@@ -334,13 +422,13 @@ export function buildDocument({
334
422
  hash: p.entry.hash,
335
423
  time: p.entry.time,
336
424
  explorerUrl: p.entry.explorerUrl,
337
- from: { address: p.entry.account, label: 'eigene Adresse' },
338
- to: { address: main.counterparty, label: main.counterpartyLabel },
425
+ from: { address: p.entry.account, label: say(L, 'eigene Adresse', 'own address') },
426
+ to: { address: main.counterparty, label: localizeLabel(main.counterpartyLabel, L) },
339
427
  movements: all.map((e) => {
340
428
  const x = excluded.find((y) => y.entry === e);
341
429
  return {
342
430
  entry: e,
343
- what: kindText(e),
431
+ what: kindText(e, L),
344
432
  onIt: !x,
345
433
  why: x?.why ?? ''
346
434
  };
@@ -382,11 +470,12 @@ export function buildDocument({
382
470
  },
383
471
  chain,
384
472
  chainName,
385
- dataSource: dataSourceOf(chain, chainName, dataSource),
473
+ dataSource: dataSourceOf(chain, chainName, dataSource, L),
386
474
  network,
387
475
  testnet: network !== 'mainnet',
388
476
  period,
389
477
  currency,
478
+ language: L,
390
479
  positions,
391
480
  excluded,
392
481
  totals: {
@@ -397,10 +486,12 @@ export function buildDocument({
397
486
  },
398
487
  // The rate's name without its day (`… vom 2026-08-10`): the day is each position's.
399
488
  sources: [
400
- ...new Set(positions.map((p) => sourceName(/** @type {any} */ (p.entry.eur).source)))
489
+ ...new Set(
490
+ positions.map((p) => localizeSource(sourceName(/** @type {any} */ (p.entry.eur).source), L))
491
+ )
401
492
  ],
402
- note: noInvoice(chain, chainName).note,
403
- notInvoice: NOT_AN_INVOICE
493
+ note: noInvoice(chain, chainName, L).note,
494
+ notInvoice: L === 'en' ? NOT_AN_INVOICE_EN : NOT_AN_INVOICE
404
495
  };
405
496
  }
406
497
 
@@ -496,3 +587,30 @@ export function deDate(date) {
496
587
  const [y, m, d] = date.slice(0, 10).split('-');
497
588
  return `${d}.${m}.${y}`;
498
589
  }
590
+
591
+ // ---- the formats of a document's language -------------------------------------
592
+
593
+ /**
594
+ * The number and date formats of a document's language: German as above, or
595
+ * English (language.js). Same names, so a drawing reads `f.money(…)` either way.
596
+ *
597
+ * @param {import('./language.js').DocumentLanguage} [language]
598
+ */
599
+ export function formats(language = 'de') {
600
+ if (language !== 'en')
601
+ return { number: deNumber, rate: deRate, fixed: deFixed, money: deMoney, date: deDate };
602
+ /** @param {string} rate @param {number} [digits] */
603
+ const rate = (rate, digits = 6) => {
604
+ const s = normalize(String(rate)).replace(/^-/, '');
605
+ const [int, frac = ''] = s.split('.');
606
+ const places =
607
+ int !== '0'
608
+ ? Math.max(0, digits - int.length)
609
+ : frac.length - frac.replace(/^0+/, '').length + digits;
610
+ return enNumber(normalize(round(String(rate), places)));
611
+ };
612
+ /** @param {string} amount @param {string} currency @param {number} [places] */
613
+ const money = (amount, currency, places = currencyPlaces(currency)) =>
614
+ `${enFixed(amount, places)} ${currency}`;
615
+ return { number: enNumber, rate, fixed: enFixed, money, date: enDate };
616
+ }
package/src/index.js CHANGED
@@ -24,8 +24,15 @@ export {
24
24
  DOCUMENT_CURRENCIES,
25
25
  documentCurrency,
26
26
  currencyPlaces,
27
- conversionText
27
+ conversionText,
28
+ formats,
29
+ NOTE_EN,
30
+ ALEPH_NOTE_EN,
31
+ NOT_AN_INVOICE_EN,
32
+ KIND_TEXT_EN,
33
+ DATA_SOURCES_EN
28
34
  } from './document.js';
35
+ export { DOCUMENT_LANGUAGES, documentLanguage, localizeLabel, localizeSource } from './language.js';
29
36
  export { eigenbelegCsv } from './csv.js';
30
37
  export { eigenbelegPdf, CREATOR, PRODUCER } from './pdf.js';
31
38
  export {