From 3a6532ef83e771438f463c1acb437651e15afbb0 Mon Sep 17 00:00:00 2001 From: harshita-jangra Date: Thu, 26 Nov 2026 01:58:43 +0530 Subject: [PATCH 1/2] Fix German separator note --- packages/pivotkit-core/src/import-csv.js | 3 +-- packages/pivotkit-core/src/import-table.js | 6 ++++-- packages/pivotkit-react/src/import-labels.js | 12 +++++++++--- packages/pivotkit-react/test/import.test.js | 10 ++++++++++ 4 files changed, 24 insertions(+), 7 deletions(-) diff --git a/packages/pivotkit-core/src/import-csv.js b/packages/pivotkit-core/src/import-csv.js index 162210712..8b7bfd737 100644 --- a/packages/pivotkit-core/src/import-csv.js +++ b/packages/pivotkit-core/src/import-csv.js @@ -15,7 +15,6 @@ import { decodeText } from "./import-text.js"; import { localeDecimal } from "./locale-decimal.js"; const CANDIDATES = [",", ";", "\t", "|"]; -const SEPARATOR_NAMES = { ",": "commas", ";": "semicolons", "\t": "tabs", "|": "vertical bars" }; /** Characters of the start of a file the separator is guessed from. */ const SAMPLE_CHARS = 65_536; const SAMPLE_ROWS = 100; @@ -187,7 +186,7 @@ export async function read(file, options) { hints: { decimal: sep === ";" ? "," : localeDecimal(o.locale) } }); table.note("ENCODING", { encoding }); - table.note("SEPARATOR", { separator: sep, name: SEPARATOR_NAMES[sep] ?? `"${sep}"` }); + table.note("SEPARATOR", { separator: sep }); // splitRows runs synchronously; between steps of ROW_STEP rows the event loop gets a turn let at = start; diff --git a/packages/pivotkit-core/src/import-table.js b/packages/pivotkit-core/src/import-table.js index 1deb199f0..2c7bb1a93 100644 --- a/packages/pivotkit-core/src/import-table.js +++ b/packages/pivotkit-core/src/import-table.js @@ -193,8 +193,10 @@ export function noteMessage(code, p) { switch (code) { case "ENCODING": return `Read as ${p.encoding}.`; - case "SEPARATOR": - return `Values separated by ${p.name}.`; + case "SEPARATOR": { + const names = { ",": "commas", ";": "semicolons", "\t": "tabs", "|": "vertical bars" }; + return `Values separated by ${names[p.separator] ?? `"${p.separator}"`}.`; + } case "LINES_SKIPPED": return `${n(p.count)} line(s) above the column names were skipped (a title block).`; case "COLUMN_RENAMED": diff --git a/packages/pivotkit-react/src/import-labels.js b/packages/pivotkit-react/src/import-labels.js index a6c326187..35e4b8a68 100644 --- a/packages/pivotkit-react/src/import-labels.js +++ b/packages/pivotkit-react/src/import-labels.js @@ -59,9 +59,10 @@ export const en = { // the preview of a sheet a saved view needs: which view and sheet; another sheet loaded there does not open the view sheetForView: "Opening “{name}” needs the sheet “{sheet}”.", sheetOther: "“{name}” was not opened: it was made for the sheet “{sheet}”.", + separatorNames: { ",": "commas", ";": "semicolons", "\t": "tabs", "|": "vertical bars" }, notes: { ENCODING: "Read as {encoding}.", - SEPARATOR: "Values separated by {name}.", + SEPARATOR: "Values separated by {separatorName}.", LINES_SKIPPED: { one: "{count} line above the column names was skipped (a title block).", other: "{count} lines above the column names were skipped (a title block)." }, COLUMN_RENAMED: "Column “{from}” is named “{to}”.", COLUMN_UNNAMED: "Column {position} has no name; it is named “{to}”.", @@ -133,9 +134,10 @@ export const de = { sheetRefused: "„{name}“ wurde nicht geöffnet: das Blatt „{sheet}“ wurde nicht geladen.", sheetForView: "Zum Öffnen von „{name}“ wird das Blatt „{sheet}“ gebraucht.", sheetOther: "„{name}“ wurde nicht geöffnet: es wurde für das Blatt „{sheet}“ gemacht.", + separatorNames: { ",": "Kommas", ";": "Semikolons", "\t": "Tabs", "|": "senkrechte Striche" }, notes: { ENCODING: "Gelesen als {encoding}.", - SEPARATOR: "Werte getrennt durch {name}.", + SEPARATOR: "Werte getrennt durch {separatorName}.", LINES_SKIPPED: { one: "{count} Zeile über den Spaltennamen wurde übersprungen (ein Titelblock).", other: "{count} Zeilen über den Spaltennamen wurden übersprungen (ein Titelblock)." }, COLUMN_RENAMED: "Die Spalte „{from}“ heißt jetzt „{to}“.", COLUMN_UNNAMED: "Spalte {position} hat keinen Namen; sie heißt jetzt „{to}“.", @@ -205,7 +207,11 @@ export function noteText(note, texts, where) { return String(note.message ?? code); } const values = Object.fromEntries(Object.entries(p).map(([k, v]) => [k, typeof v === "number" ? v.toLocaleString(where.locale) : String(v ?? "")])); - if (code === "DATE_ORDER") { + if (code === "SEPARATOR") { + values.separatorName = Object.hasOwn(texts.separatorNames, String(p.separator)) + ? texts.separatorNames[String(p.separator)] + : `"${p.separator}"`; + } else if (code === "DATE_ORDER") { values.order = Object.hasOwn(texts.dateOrders, String(p.order)) ? /** @type {any} */ (texts.dateOrders)[String(p.order)] : values.order; } else if (code === "VALUES_NOT_CONVERTED") { values.type = Object.hasOwn(texts.types, String(p.type)) ? /** @type {any} */ (texts.types)[String(p.type)] : values.type; diff --git a/packages/pivotkit-react/test/import.test.js b/packages/pivotkit-react/test/import.test.js index fe24dee25..69c677dbc 100644 --- a/packages/pivotkit-react/test/import.test.js +++ b/packages/pivotkit-react/test/import.test.js @@ -130,6 +130,16 @@ test("every note code of the readers has a text in English and German; German ha test("a note in the report's language: counts in their plural form and the locale's digits, the variants of a code, a plugin's own code in its words", () => { const where = { lang: "en", locale: "en-US" }; + const separators = [ + [",", "commas", "Kommas"], + [";", "semicolons", "Semikolons"], + ["\t", "tabs", "Tabs"], + ["|", "vertical bars", "senkrechte Striche"], + ]; + for (const [separator, enName, deName] of separators) { + assert.equal(noteText({ code: "SEPARATOR", params: { separator } }, en, where), `Values separated by ${enName}.`); + assert.equal(noteText({ code: "SEPARATOR", params: { separator } }, de, { lang: "de", locale: "de-DE" }), `Werte getrennt durch ${deName}.`); + } assert.equal(noteText({ code: "ROWS_EMPTY", params: { count: 1 } }, en, where), "1 empty row was left out."); assert.equal(noteText({ code: "ROWS_EMPTY", params: { count: 12345 } }, en, where), "12,345 empty rows were left out."); assert.equal(noteText({ code: "ROWS_EMPTY", params: { count: 12345 } }, de, { lang: "de", locale: "de-DE" }), "12.345 leere Zeilen wurden weggelassen."); From 9e21cce13d46178c39cdc13da7756549626065c1 Mon Sep 17 00:00:00 2001 From: harshita-jangra Date: Thu, 26 Nov 2026 14:06:39 +0530 Subject: [PATCH 2/2] Fix separator note parameters and names --- docs/reference/import.md | 2 +- packages/pivotkit-core/src/import-table.js | 13 +++++++++---- packages/pivotkit-core/test/import.test.js | 10 +++++++++- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/docs/reference/import.md b/docs/reference/import.md index 96768ab0f..0b2c0e1e2 100644 --- a/docs/reference/import.md +++ b/docs/reference/import.md @@ -234,7 +234,7 @@ file had it. A field that is given must be right. This holds for `hints` too: `d | Note `code` | When | `params` | | --- | --- | --- | | `ENCODING` | Always, for text | `encoding` | -| `SEPARATOR` | Always, for delimited text | `separator`, `name` | +| `SEPARATOR` | Always, for delimited text | `separator` | | `LINES_SKIPPED` | A title block above the header | `count` | | `COLUMN_RENAMED` | An empty or repeated name | `position`, `from`, `to` | | `COLUMNS_RENAMED_MORE` | More than 20 renamed | `count` | diff --git a/packages/pivotkit-core/src/import-table.js b/packages/pivotkit-core/src/import-table.js index 2c7bb1a93..0a63374b9 100644 --- a/packages/pivotkit-core/src/import-table.js +++ b/packages/pivotkit-core/src/import-table.js @@ -16,6 +16,13 @@ import { resolveLimits } from "./limits.js"; import { isDateMs, parseIso } from "./time.js"; import { CONTROLS, HIDDEN } from "./util.js"; +const SEPARATOR_NAMES = Object.freeze({ + ",": "commas", + ";": "semicolons", + "\t": "tabs", + "|": "vertical bars" +}); + /** The column types a loaded table can have (`encode`'s, without "null"). */ export const IMPORT_TYPES = Object.freeze(["string", "number", "date", "boolean"]); @@ -193,10 +200,8 @@ export function noteMessage(code, p) { switch (code) { case "ENCODING": return `Read as ${p.encoding}.`; - case "SEPARATOR": { - const names = { ",": "commas", ";": "semicolons", "\t": "tabs", "|": "vertical bars" }; - return `Values separated by ${names[p.separator] ?? `"${p.separator}"`}.`; - } + case "SEPARATOR": + return `Values separated by ${SEPARATOR_NAMES[p.separator] ?? `"${p.separator}"`}.`; case "LINES_SKIPPED": return `${n(p.count)} line(s) above the column names were skipped (a title block).`; case "COLUMN_RENAMED": diff --git a/packages/pivotkit-core/test/import.test.js b/packages/pivotkit-core/test/import.test.js index 862090818..d46ee7be0 100644 --- a/packages/pivotkit-core/test/import.test.js +++ b/packages/pivotkit-core/test/import.test.js @@ -7,7 +7,7 @@ import { readFileSync } from "node:fs"; import { BUILT_IN_READERS, PLUGIN_API_VERSION, csvReader, jsonReader, loadReader, readFile, readerFor, retype, validatePlugin } from "pivotkit-core/import"; import { LIMITS, PivotkitError, computePivot, encode, toGrid } from "pivotkit-core"; -import { fileName } from "../src/import-table.js"; +import { fileName, noteMessage } from "../src/import-table.js"; import { cpuClock } from "../../../tests/cpu-time.js"; const fixture = (name) => readFileSync(new URL(`./import-fixtures/${name}`, import.meta.url)); @@ -18,6 +18,14 @@ const typeOf = (table, name) => table.types[table.columns.indexOf(name)]; const codes = (table) => table.notes.map((n) => n.code); const rejects = (promise, check) => assert.rejects(promise, (e) => e instanceof PivotkitError && check(e)); +test("separator note names", () => { + assert.equal(noteMessage("SEPARATOR", { separator: "," }), "Values separated by commas."); + assert.equal(noteMessage("SEPARATOR", { separator: ";" }), "Values separated by semicolons."); + assert.equal(noteMessage("SEPARATOR", { separator: "\t" }), "Values separated by tabs."); + assert.equal(noteMessage("SEPARATOR", { separator: "|" }), "Values separated by vertical bars."); + assert.equal(noteMessage("SEPARATOR", { separator: ":" }), 'Values separated by ":".'); +}); + test("German election results: BOM, semicolons, a title block, German numbers and dates, leading zeros", async () => { const t = await readFile(fileOf("kerg2-btw25.csv")); assert.equal(t.columns[0], "Wahlart");