Skip to content

Beautiful, AI-native markdown IDE and LLM wiki

Guard i18n catalog re-tracking and check drift on the working tree (#6545)

Nick Gomezc11b78cd0841
diff --git a/package.json b/package.json
index c4c728474..6474f1636 100644
--- a/package.json
+++ b/package.json
@@ -27,7 +27,7 @@
"check:doc-links": "pnpm --dir docs run validate-link",
"check:server-test-inputs": "node scripts/check-server-test-inputs.mjs",
"check:drift": "pnpm run check:drift:guards && vitest run --config vitest.scripts.config.ts",
- "check:drift:guards": "bash scripts/check-husky-prepare-guard.sh && bash scripts/check-knip-clean.sh && bash scripts/check-notices-clean.sh && bash scripts/check-schema-snapshot-clean.sh && bash scripts/check-i18n-drift.sh && node scripts/check-i18n-new-string-translations.mjs && node scripts/check-i18n-picker-completeness.mjs && bash scripts/check-no-major-changeset.sh && node scripts/check-override-floors.mjs && node scripts/check-typescript-resolution.mjs",
+ "check:drift:guards": "bash scripts/check-husky-prepare-guard.sh && bash scripts/check-knip-clean.sh && bash scripts/check-notices-clean.sh && bash scripts/check-schema-snapshot-clean.sh && bash scripts/check-i18n-drift.sh && node scripts/check-i18n-compiled-catalogs-untracked.mjs && node scripts/check-i18n-new-string-translations.mjs && node scripts/check-i18n-picker-completeness.mjs && bash scripts/check-no-major-changeset.sh && node scripts/check-override-floors.mjs && node scripts/check-typescript-resolution.mjs",
"typecheck": "turbo run typecheck",
"test": "turbo run test test:uncached",
"test:uncached": "vitest run --config vitest.uncached.config.ts",
diff --git a/packages/app/src/locales/REVIEW.md b/packages/app/src/locales/REVIEW.md
index d5b16e510..448b12b17 100644
--- a/packages/app/src/locales/REVIEW.md
+++ b/packages/app/src/locales/REVIEW.md
@@ -151,10 +151,6 @@ is that a model checking another model's translation tells us nothing new.
A review that comes back with corrections is still a review. What decides the status is that a
reader of the language read it, not that they had nothing to say.
-`git add` this file before running `pnpm check`. The catalog-drift guard diffs the whole of
-`src/locales/` against the index, so an unstaged edit to this file or to `GLOSSARY.md` is
-reported as catalog drift and sends you off to re-run an extractor that will change nothing.
-
## Offering a locale
One line, in `packages/core/src/i18n/locales.ts` — adding the tag to `PICKER_LOCALES`. Everything
diff --git a/scripts/check-i18n-compiled-catalogs-untracked.mjs b/scripts/check-i18n-compiled-catalogs-untracked.mjs
new file mode 100644
index 000000000..620b923ea
--- /dev/null
+++ b/scripts/check-i18n-compiled-catalogs-untracked.mjs
@@ -0,0 +1,71 @@
+#!/usr/bin/env node
+
+import { spawnSync } from 'node:child_process';
+import { realpathSync } from 'node:fs';
+import { fileURLToPath, pathToFileURL } from 'node:url';
+import { gitCleanEnv } from './git-clean-env.mjs';
+
+const OK_ROOT = fileURLToPath(new URL('..', import.meta.url));
+const LOCALES_DIR = 'packages/app/src/locales';
+const GENERATED_CATALOG =
+ /^packages\/app\/src\/locales\/(?:[^/]+\/messages\.json|pseudo\/messages\.po)$/;
+
+function git(args) {
+ return spawnSync('git', args, { cwd: OK_ROOT, env: gitCleanEnv(), encoding: 'utf8' });
+}
+
+function failureOf(result) {
+ if (result.error) return result.error.message;
+ if (result.signal) return `was killed by ${result.signal}`;
+ return `exited ${result.status}: ${(result.stderr ?? '').trim()}`;
+}
+
+function shellQuote(text) {
+ return `'${text.replaceAll("'", "'\\''")}'`;
+}
+
+function main() {
+ const listed = git(['ls-files', '-z', '--', LOCALES_DIR]);
+ if (listed.error || listed.status !== 0) {
+ console.error(
+ `ERROR: could not list the tracked paths under ${LOCALES_DIR}, so whether git tracks a generated i18n catalog is unknown.`,
+ );
+ console.error(` git ls-files ${failureOf(listed)}`);
+ return 2;
+ }
+ const tracked = [...new Set(listed.stdout.split('\0').filter(Boolean))];
+ if (tracked.length === 0) {
+ console.error(
+ `ERROR: git lists no tracked path under ${LOCALES_DIR}, so this check has nothing to examine. Run it from an Open Knowledge checkout.`,
+ );
+ return 2;
+ }
+
+ const generated = tracked.filter((path) => GENERATED_CATALOG.test(path));
+ if (generated.length === 0) {
+ console.log(
+ `i18n: git tracks no generated catalog among ${tracked.length} tracked path(s) under ${LOCALES_DIR}.`,
+ );
+ return 0;
+ }
+
+ console.error('ERROR: git tracks generated i18n catalogs.');
+ console.error('');
+ console.error(' The catalog compile writes every locale messages.json and derives the');
+ console.error(' pseudo locale from en, so packages/app/.gitignore ignores both and only');
+ console.error(' the other messages.po catalogs are committed. Tracked here:');
+ for (const path of generated) console.error(` ${path}`);
+ console.error('');
+ console.error(' Fix: take them out of the index, keeping the files on disk,');
+ console.error(
+ ` git -C ${shellQuote(OK_ROOT)} rm --cached -- ${generated.map(shellQuote).join(' ')}`,
+ );
+ console.error(' then commit.');
+ console.error(' A merge conflict on these paths resolved with git add keeps them tracked;');
+ console.error(' git rm --cached is the resolution.');
+ return 1;
+}
+
+if (process.argv[1] && import.meta.url === pathToFileURL(realpathSync(process.argv[1])).href) {
+ process.exit(main());
+}
diff --git a/scripts/check-i18n-compiled-catalogs-untracked.test.mjs b/scripts/check-i18n-compiled-catalogs-untracked.test.mjs
new file mode 100644
index 000000000..f2864cb7b
--- /dev/null
+++ b/scripts/check-i18n-compiled-catalogs-untracked.test.mjs
@@ -0,0 +1,361 @@
+import { spawnSync } from 'node:child_process';
+import {
+ copyFileSync,
+ existsSync,
+ mkdirSync,
+ mkdtempSync,
+ readFileSync,
+ rmSync,
+ writeFileSync,
+} from 'node:fs';
+import { tmpdir } from 'node:os';
+import { dirname, join } from 'node:path';
+import { fileURLToPath } from 'node:url';
+import { afterEach, describe, expect, test } from 'vitest';
+import { configureTestGitRepository } from '../test-support/configure-git-fixture.test-helper.ts';
+import { gitCleanEnv } from './git-clean-env.mjs';
+
+const OK_ROOT = fileURLToPath(new URL('..', import.meta.url));
+const GUARD = 'scripts/check-i18n-compiled-catalogs-untracked.mjs';
+const GUARD_IMPORTS = ['scripts/git-clean-env.mjs'];
+const LOCALES = 'packages/app/src/locales';
+const APP_GITIGNORE = 'packages/app/.gitignore';
+const REAL_APP_GITIGNORE = readFileSync(join(OK_ROOT, APP_GITIGNORE), 'utf8');
+const SCRATCH_PREFIX_WITH_A_QUOTE = "i18n-compiled-untracked-quote'd-";
+
+const scratch = [];
+
+afterEach(() => {
+ while (scratch.length) rmSync(scratch.pop(), { recursive: true, force: true });
+});
+
+function isolatedEnv(extra = {}) {
+ return {
+ ...Object.fromEntries(Object.entries(process.env).filter(([name]) => !name.startsWith('GIT_'))),
+ GIT_CONFIG_GLOBAL: '/dev/null',
+ GIT_CONFIG_NOSYSTEM: '1',
+ GIT_AUTHOR_NAME: 'fixture',
+ GIT_AUTHOR_EMAIL: '[email protected]',
+ GIT_COMMITTER_NAME: 'fixture',
+ GIT_COMMITTER_EMAIL: '[email protected]',
+ ...extra,
+ };
+}
+
+function git(root, ...args) {
+ return spawnSync('git', args, { cwd: root, env: isolatedEnv(), encoding: 'utf8' });
+}
+
+function gitOk(root, ...args) {
+ const result = git(root, ...args);
+ expect(result.status, `git ${args.join(' ')}\n${result.stderr}`).toBe(0);
+ return result.stdout;
+}
+
+function write(root, files) {
+ for (const [path, body] of Object.entries(files)) {
+ mkdirSync(dirname(join(root, path)), { recursive: true });
+ writeFileSync(join(root, path), body);
+ }
+}
+
+function scratchDir(okDir = '.') {
+ const root = mkdtempSync(join(tmpdir(), SCRATCH_PREFIX_WITH_A_QUOTE));
+ scratch.push(root);
+ for (const script of [GUARD, ...GUARD_IMPORTS]) {
+ mkdirSync(dirname(join(root, okDir, script)), { recursive: true });
+ copyFileSync(join(OK_ROOT, script), join(root, okDir, script));
+ }
+ return root;
+}
+
+function repo(files, okDir = '.') {
+ const root = scratchDir(okDir);
+ write(root, files);
+ gitOk(root, 'init', '-q', '-b', 'main');
+ configureTestGitRepository(root, (args) => gitOk(root, ...args));
+ gitOk(root, 'add', '-A');
+ gitOk(root, 'commit', '-q', '-m', 'base');
+ return root;
+}
+
+function runGuard(root, extraEnv = {}, okDir = '.') {
+ return spawnSync(process.execPath, [join(root, okDir, GUARD)], {
+ cwd: root,
+ env: isolatedEnv(extraEnv),
+ encoding: 'utf8',
+ });
+}
+
+function named(result) {
+ return result.stderr
+ .split('\n')
+ .filter((line) => /^ {4}packages\/\S+$/.test(line))
+ .map((line) => line.trim())
+ .sort();
+}
+
+function printedFix(result) {
+ return result.stderr
+ .split('\n')
+ .filter((line) => /^ {4}git /.test(line))
+ .map((line) => line.trim());
+}
+
+function trackedUnder(root, dir) {
+ return gitOk(root, 'ls-files', '-z', '--', dir).split('\0').filter(Boolean);
+}
+
+const PO = 'msgid "Save"\nmsgstr "Save"\n';
+const JSON_CATALOG = '{"messages":{}}\n';
+
+function mergeMainThatStoppedTrackingGeneratedCatalogs() {
+ const root = repo({
+ [`${LOCALES}/en/messages.po`]: PO,
+ [`${LOCALES}/en/messages.json`]: JSON_CATALOG,
+ [`${LOCALES}/pseudo/messages.po`]: PO,
+ [`${LOCALES}/pseudo/messages.json`]: JSON_CATALOG,
+ });
+ gitOk(root, 'checkout', '-q', '-b', 'side');
+ write(root, {
+ [`${LOCALES}/en/messages.json`]: '{"messages":{"a":"b"}}\n',
+ [`${LOCALES}/pseudo/messages.po`]: `${PO}msgid "New"\nmsgstr "New"\n`,
+ });
+ gitOk(root, 'commit', '-q', '-am', 'side edits generated catalogs');
+ gitOk(root, 'checkout', '-q', 'main');
+ gitOk(
+ root,
+ 'rm',
+ '-q',
+ '--',
+ `${LOCALES}/en/messages.json`,
+ `${LOCALES}/pseudo/messages.json`,
+ `${LOCALES}/pseudo/messages.po`,
+ );
+ write(root, { [APP_GITIGNORE]: REAL_APP_GITIGNORE });
+ gitOk(root, 'add', '-A');
+ gitOk(root, 'commit', '-q', '-m', 'main stops tracking generated catalogs');
+ gitOk(root, 'checkout', '-q', 'side');
+
+ const merge = git(root, 'merge', '--no-edit', 'main');
+ expect(merge.status).toBe(1);
+ expect(
+ gitOk(root, 'diff', '--name-only', '--diff-filter=U').split('\n').filter(Boolean).sort(),
+ ).toEqual([`${LOCALES}/en/messages.json`, `${LOCALES}/pseudo/messages.po`]);
+ return root;
+}
+
+describe('check-i18n-compiled-catalogs-untracked fails when git tracks a generated catalog', () => {
+ test('a messages.json and the pseudo messages.po added with git add -f fail the check, and the fix it prints un-tracks both from an unrelated directory and keeps them on disk, with Open Knowledge below the repository root in a path holding a quote', () => {
+ const ok = 'public/open-knowledge';
+ const compiled = [`${LOCALES}/fr/messages.json`, `${LOCALES}/pseudo/messages.po`];
+ const root = repo(
+ {
+ [`${ok}/${APP_GITIGNORE}`]: REAL_APP_GITIGNORE,
+ [`${ok}/${LOCALES}/en/messages.po`]: PO,
+ [`${ok}/${LOCALES}/fr/messages.po`]: PO,
+ [`${ok}/${LOCALES}/GLOSSARY.md`]: '# Glossary\n',
+ },
+ ok,
+ );
+ expect(root).toContain("'");
+ write(root, Object.fromEntries(compiled.map((path) => [`${ok}/${path}`, JSON_CATALOG])));
+ gitOk(root, 'add', '-f', '--', ...compiled.map((path) => `${ok}/${path}`));
+ gitOk(root, 'commit', '-q', '-m', 'track compiled catalogs');
+ const unrelated = mkdtempSync(join(tmpdir(), 'i18n-compiled-untracked-unrelated-'));
+ scratch.push(unrelated);
+
+ const result = runGuard(root, {}, ok);
+
+ expect(result.status, result.stderr).toBe(1);
+ expect(named(result)).toEqual(compiled);
+ const fix = printedFix(result);
+ expect(fix).toHaveLength(1);
+ const removed = spawnSync('bash', ['-c', fix[0]], {
+ cwd: unrelated,
+ env: isolatedEnv(),
+ encoding: 'utf8',
+ });
+ expect(removed.status, removed.stderr).toBe(0);
+ expect(trackedUnder(root, `${ok}/${LOCALES}`).sort()).toEqual([
+ `${ok}/${LOCALES}/GLOSSARY.md`,
+ `${ok}/${LOCALES}/en/messages.po`,
+ `${ok}/${LOCALES}/fr/messages.po`,
+ ]);
+ expect(compiled.every((path) => existsSync(join(root, ok, path)))).toBe(true);
+ expect(runGuard(root, {}, ok).status).toBe(0);
+ });
+
+ test('a staged pseudo-locale messages.po fails the check before it is committed', () => {
+ const root = repo({
+ [APP_GITIGNORE]: REAL_APP_GITIGNORE,
+ [`${LOCALES}/en/messages.po`]: PO,
+ });
+ write(root, { [`${LOCALES}/pseudo/messages.po`]: PO });
+ gitOk(root, 'add', '-f', `${LOCALES}/pseudo/messages.po`);
+
+ const result = runGuard(root);
+
+ expect(result.status, result.stderr).toBe(1);
+ expect(named(result)).toEqual([`${LOCALES}/pseudo/messages.po`]);
+ });
+
+ test('a merge that conflicts on catalogs main stopped tracking, resolved with git add -A, fails the check naming each re-tracked catalog', () => {
+ const root = mergeMainThatStoppedTrackingGeneratedCatalogs();
+ gitOk(root, 'add', '-A');
+ gitOk(root, 'commit', '-q', '--no-edit');
+
+ const result = runGuard(root);
+
+ expect(result.status, result.stderr).toBe(1);
+ expect(named(result)).toEqual([`${LOCALES}/en/messages.json`, `${LOCALES}/pseudo/messages.po`]);
+ });
+});
+
+describe('check-i18n-compiled-catalogs-untracked passes a tree that tracks only source catalogs', () => {
+ test('tracked messages.po catalogs pass while compiled catalogs sit untracked on disk, and the pass line counts every tracked path it examined', () => {
+ const tracked = [
+ `${LOCALES}/GLOSSARY.md`,
+ `${LOCALES}/en/messages.po`,
+ `${LOCALES}/fr/messages.po`,
+ `${LOCALES}/zh-Hans/messages.po`,
+ ];
+ const root = repo({
+ [APP_GITIGNORE]: REAL_APP_GITIGNORE,
+ 'packages/app/src/messages.json': JSON_CATALOG,
+ ...Object.fromEntries(tracked.map((path) => [path, PO])),
+ });
+ const untracked = [
+ `${LOCALES}/en/messages.json`,
+ `${LOCALES}/fr/messages.json`,
+ `${LOCALES}/pseudo/messages.json`,
+ ];
+ write(root, Object.fromEntries(untracked.map((path) => [path, JSON_CATALOG])));
+ expect(untracked.every((path) => existsSync(join(root, path)))).toBe(true);
+ expect(trackedUnder(root, LOCALES).sort()).toEqual(tracked);
+
+ const result = runGuard(root);
+
+ expect(result.status, result.stderr).toBe(0);
+ expect(result.stderr).toBe('');
+ expect(result.stdout).toContain(`among ${tracked.length} tracked path(s) under ${LOCALES}`);
+ });
+
+ test('a GIT_DIR, GIT_WORK_TREE or GIT_INDEX_FILE inherited from a hook is scrubbed rather than redirecting the listing', () => {
+ const root = repo({ [APP_GITIGNORE]: REAL_APP_GITIGNORE, [`${LOCALES}/en/messages.po`]: PO });
+
+ const result = runGuard(root, {
+ GIT_DIR: '/nonexistent/.git',
+ GIT_WORK_TREE: '/nonexistent',
+ GIT_INDEX_FILE: '/nonexistent/index',
+ });
+
+ expect(result.status, result.stderr).toBe(0);
+ expect(result.stdout).toContain(`among 1 tracked path(s) under ${LOCALES}`);
+ });
+});
+
+describe('check-i18n-compiled-catalogs-untracked fails rather than passing when it cannot examine the catalogs', () => {
+ test('a tree that tracks nothing under the locales directory fails with 2 instead of passing an empty listing', () => {
+ const root = repo({ 'README.md': '# fixture\n' });
+ write(root, { [`${LOCALES}/en/messages.json`]: JSON_CATALOG });
+
+ const result = runGuard(root);
+
+ expect(result.status).toBe(2);
+ expect(result.stderr).toContain(`git lists no tracked path under ${LOCALES}`);
+ });
+
+ test('a checkout git cannot open fails with 2 and says the listing could not be read', () => {
+ const root = scratchDir();
+ write(root, {
+ '.git': `gitdir: ${join(root, 'missing-gitdir')}\n`,
+ [`${LOCALES}/en/messages.json`]: JSON_CATALOG,
+ });
+
+ const result = runGuard(root);
+
+ expect(result.status).toBe(2);
+ expect(result.stderr).toContain(`could not list the tracked paths under ${LOCALES}`);
+ });
+});
+
+describe('the paths the check rejects are exactly the ones packages/app/.gitignore ignores', () => {
+ test('replaying the real ignore file through git agrees with the check on every locale path, both ways', () => {
+ const realTracked = spawnSync('git', ['ls-files', '-z', '--', LOCALES], {
+ cwd: OK_ROOT,
+ env: gitCleanEnv(),
+ encoding: 'utf8',
+ })
+ .stdout.split('\0')
+ .filter(Boolean);
+ const localeDirs = [
+ ...new Set(
+ [...realTracked, `${LOCALES}/pseudo/messages.po`]
+ .map((path) => /^packages\/app\/src\/locales\/([^/]+)\/[^/]+$/.exec(path)?.[1])
+ .filter(Boolean),
+ ),
+ ];
+ expect(localeDirs).toContain('en');
+ expect(localeDirs).toContain('pseudo');
+ const ignoreLines = REAL_APP_GITIGNORE.split('\n').filter((line) =>
+ line.startsWith('src/locales/'),
+ );
+ expect(ignoreLines.length).toBeGreaterThan(0);
+ const candidates = new Set([
+ ...realTracked,
+ ...localeDirs.flatMap((dir) => [
+ `${LOCALES}/${dir}/messages.json`,
+ `${LOCALES}/${dir}/messages.po`,
+ ]),
+ ...ignoreLines.flatMap((line) =>
+ localeDirs.map((dir) => `packages/app/${line.replaceAll(/\*+/g, dir)}`),
+ ),
+ `${LOCALES}/messages.json`,
+ `${LOCALES}/messages.po`,
+ `${LOCALES}/en/nested/messages.json`,
+ `${LOCALES}/pseudo/messages.po.orig`,
+ 'packages/app/src/messages.json',
+ ]);
+ const root = repo({ [APP_GITIGNORE]: REAL_APP_GITIGNORE, 'README.md': '# fixture\n' });
+ write(root, Object.fromEntries([...candidates].map((path) => [path, PO])));
+ gitOk(root, 'add', '-f', '--', ...candidates);
+ expect(
+ trackedUnder(root, '.')
+ .filter((path) => candidates.has(path))
+ .sort(),
+ ).toEqual([...candidates].sort());
+
+ const ignored = git(root, 'check-ignore', '--no-index', '--', ...candidates)
+ .stdout.split('\n')
+ .filter(Boolean)
+ .sort();
+ expect(ignored.length).toBeGreaterThan(0);
+ const result = runGuard(root);
+
+ expect(result.status, result.stderr).toBe(1);
+ expect(named(result)).toEqual(ignored);
+ });
+});
+
+describe('this tree', () => {
+ test('tracks no generated catalog, and the check examines every tracked path under the locales directory', () => {
+ const tracked = spawnSync('git', ['ls-files', '-z', '--', LOCALES], {
+ cwd: OK_ROOT,
+ env: gitCleanEnv(),
+ encoding: 'utf8',
+ })
+ .stdout.split('\0')
+ .filter(Boolean);
+ expect(tracked).toContain(`${LOCALES}/en/messages.po`);
+
+ const result = spawnSync(process.execPath, [join(OK_ROOT, GUARD)], {
+ cwd: OK_ROOT,
+ env: gitCleanEnv(),
+ encoding: 'utf8',
+ });
+
+ expect(result.status, result.stderr).toBe(0);
+ expect(result.stdout).toContain(`among ${tracked.length} tracked path(s) under ${LOCALES}`);
+ });
+});
diff --git a/scripts/check-i18n-drift.sh b/scripts/check-i18n-drift.sh
index 6a8bf3c14..43195dfd8 100755
--- a/scripts/check-i18n-drift.sh
+++ b/scripts/check-i18n-drift.sh
@@ -43,6 +43,28 @@ writeFileSync(out, [
].join("\n"));
' "$APP_DIR/lingui.config.ts" "$APP_DIR" "$CATALOGS" "$WORK_ROOT/lingui.config.mjs"
+cd "$REPO_ROOT"
+git ls-files -z -- "$LOCALES_DIR" >"$WORK_ROOT/tracked"
+catalog_ids() {
+ while IFS= read -r -d '' tracked; do
+ case "$tracked" in
+ */messages.po) ;;
+ *) continue ;;
+ esac
+ copy="$CATALOGS/${tracked#"$LOCALES_DIR"/}"
+ if [ -f "$copy" ]; then
+ git hash-object --path="$tracked" "$copy"
+ else
+ echo missing
+ fi
+ done <"$WORK_ROOT/tracked"
+}
+catalog_ids >"$WORK_ROOT/before"
+if [ ! -s "$WORK_ROOT/before" ]; then
+ echo "ERROR: git lists no tracked catalog under $LOCALES_DIR, so the i18n drift check has nothing to compare." >&2
+ exit 1
+fi
+
cd "$APP_DIR"
in_copy() {
LINGUI_CONFIG="$WORK_ROOT/lingui.config.mjs" node "$SCRIPT_DIR/run-in-own-process-group.mjs" "$@" >/dev/null &
@@ -55,42 +77,35 @@ in_copy() {
in_copy pnpm run --silent i18n:extract || exit $?
cd "$REPO_ROOT"
-git ls-files -z -- "$LOCALES_DIR" >"$WORK_ROOT/tracked"
-COMPARED=0
+catalog_ids >"$WORK_ROOT/after"
DIFFERING=""
+exec 3<"$WORK_ROOT/before" 4<"$WORK_ROOT/after"
while IFS= read -r -d '' tracked; do
case "$tracked" in
*/messages.po) ;;
*) continue ;;
esac
- COMPARED=$((COMPARED + 1))
- copy="$CATALOGS/${tracked#"$LOCALES_DIR"/}"
- if [ ! -f "$copy" ]; then
+ IFS= read -r before_id <&3
+ IFS= read -r after_id <&4
+ if [ "$before_id" != missing ] && [ "$before_id" != "$after_id" ]; then
DIFFERING="$DIFFERING$tracked"$'\n'
- continue
fi
- indexed_id="$(git rev-parse ":./$tracked")"
- copy_id="$(git hash-object --path="$tracked" "$copy")"
- [ "$copy_id" = "$indexed_id" ] || DIFFERING="$DIFFERING$tracked"$'\n'
done <"$WORK_ROOT/tracked"
-if [ "$COMPARED" -eq 0 ]; then
- echo "ERROR: git lists no tracked catalog under $LOCALES_DIR, so the i18n drift check has nothing to compare." >&2
- exit 1
-fi
+exec 3<&- 4<&-
CREATED="$(comm -13 <(printf '%s\n' "$SEEDED") <(cd "$CATALOGS" && find . -type f | LC_ALL=C sort) | sed "s|^\./|$LOCALES_DIR/|")"
if [ -n "$DIFFERING" ] || [ -n "$CREATED" ]; then
echo "ERROR: i18n catalog drift detected." >&2
echo "" >&2
- echo " <Trans> or t\`...\` macros under packages/app/src have changed without" >&2
- echo " regenerating the Lingui catalogs. Running the extractor on a copy of" >&2
- echo " $LOCALES_DIR produced catalogs that differ from the index." >&2
+ echo " The Lingui catalogs in the working tree are not what the extractor writes" >&2
+ echo " for the <Trans> and t\`...\` macros under packages/app/src: running it on a" >&2
+ echo " copy of $LOCALES_DIR changed them." >&2
echo "" >&2
echo " Fix:" >&2
echo " cd public/open-knowledge/packages/app && pnpm run i18n" >&2
echo " then commit the updated .po catalogs." >&2
if [ -n "$DIFFERING" ]; then
echo "" >&2
- echo " Catalog files that differ from the index:" >&2
+ echo " Catalog files the extractor changed:" >&2
printf '%s' "$DIFFERING" | sed 's/^/ /' >&2
fi
if [ -n "$CREATED" ]; then