mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-19 00:12:18 +00:00
The PHQ-9, GAD-7, WHO-5 and SCI now have text in every app language instead of falling back to the English original. Each instrument and language is one file under src/lib/mental-health/wording/ that declares what it is: a published validated translation reproduced word for word, with its source and terms in `source`, or a translation written for HealthLog, faithful to the English and on the same scale. Validated versions added: the Pfizer PHQ-9 for France, the Netherlands, Korea and Brazil, the Pfizer GAD-7 for the Netherlands, Korea and Brazil, the PRU Dutch WHO-5, the Korean WHO-5 validation (J Korean Geriatr Psychiatry 2010) and the Polish SCI validation (Sci Rep 2026). The SCI in the other languages and the WHO-5 in Brazilian Portuguese carry HealthLog's own translation; each file names any validated version found and why it is not used. Where the text is unvalidated, the check-in shows a note that the result is orientation and a one-tap switch to the English original. Each language loads as its own chunk when a questionnaire surface needs it. The item text, answers, stems and the PHQ-9 follow-up leave every message bundle, so a translator never sees them; the i18n guard now requires that no bundle carries them, and the registry test requires every instrument in every language with the item count and anchor scores the scoring expects. CONTRIBUTING explains where the wording lives and how to propose a validated version.
82 lines
2.9 KiB
TypeScript
82 lines
2.9 KiB
TypeScript
import { describe, it, expect } from "vitest";
|
||
import { readFileSync, readdirSync } from "node:fs";
|
||
import { join } from "node:path";
|
||
|
||
/**
|
||
* No middle-dot or dash separator in visible strings.
|
||
*
|
||
* A value like "Added {date} · {size}" or "Weight · body fat · muscle" reads
|
||
* as a list of fragments rather than as the app's plain voice, and so does
|
||
* "{what} — tomorrow" or "Could not save — try again": the dash stands in
|
||
* for a comma, a colon or a full stop the sentence should have said. Facts
|
||
* are joined with a comma, a colon or a real phrase instead. This guard
|
||
* walks every bundle under `messages/` and fails on any string that contains
|
||
* a space, then U+00B7 (middle dot), U+2014 (em dash) or U+2013 (en dash),
|
||
* then a space. A middle dot inside a unit ("mL/(kg·min)") and a range
|
||
* ("70–100 mmHg", "{start}–{end}") have no surrounding spaces and are not
|
||
* matched: an unspaced en dash is how a range is written, not a pause.
|
||
*
|
||
* A key that genuinely needs the pattern goes into `ALLOWED` with the reason
|
||
* written next to it. An allowed key that no longer contains the pattern
|
||
* fails too, so the list cannot go stale.
|
||
*/
|
||
|
||
const MESSAGES_DIR = join(__dirname, "../../messages");
|
||
const SEPARATORS = [" · ", " — ", " – "] as const;
|
||
|
||
const hasSeparator = (value: string) =>
|
||
SEPARATORS.some((separator) => value.includes(separator));
|
||
|
||
/** Key path -> why the separator is right there. Empty by intent. */
|
||
const ALLOWED: Record<string, string> = {};
|
||
|
||
function flatten(
|
||
obj: unknown,
|
||
prefix: string,
|
||
out: Map<string, string>,
|
||
): Map<string, string> {
|
||
if (obj == null || typeof obj !== "object") return out;
|
||
for (const [k, v] of Object.entries(obj as Record<string, unknown>)) {
|
||
const key = prefix ? `${prefix}.${k}` : k;
|
||
if (typeof v === "string") out.set(key, v);
|
||
else if (typeof v === "object") flatten(v, key, out);
|
||
}
|
||
return out;
|
||
}
|
||
|
||
const bundles = readdirSync(MESSAGES_DIR)
|
||
.filter((file) => file.endsWith(".json"))
|
||
.sort();
|
||
|
||
describe("message bundles carry no ' · ', ' — ' or ' – ' separator", () => {
|
||
it("finds the bundles", () => {
|
||
expect(bundles.length).toBeGreaterThanOrEqual(7);
|
||
});
|
||
|
||
for (const file of bundles) {
|
||
const values = flatten(
|
||
JSON.parse(readFileSync(join(MESSAGES_DIR, file), "utf8")),
|
||
"",
|
||
new Map(),
|
||
);
|
||
|
||
it(`${file} walks a non-empty set of strings`, () => {
|
||
expect(values.size).toBeGreaterThan(1000);
|
||
});
|
||
|
||
it(`${file} has no dot or dash separator outside the allowlist`, () => {
|
||
const offenders = [...values]
|
||
.filter(([key, value]) => hasSeparator(value) && !(key in ALLOWED))
|
||
.map(([key, value]) => `${key} = ${JSON.stringify(value)}`);
|
||
expect(offenders).toEqual([]);
|
||
});
|
||
|
||
it(`${file} has no stale allowlist entry`, () => {
|
||
const stale = Object.keys(ALLOWED).filter(
|
||
(key) => !hasSeparator(values.get(key) ?? ""),
|
||
);
|
||
expect(stale).toEqual([]);
|
||
});
|
||
}
|
||
});
|