From 991d6b790170a5536fa11b5c03064c6cac9fc5f2 Mon Sep 17 00:00:00 2001 From: Artur Date: Fri, 20 Feb 2026 19:17:39 +0100 Subject: [PATCH] fix(cli): guard against empty translations in PO loader push When a .po file section contains only obsolete entries or no translations, Object.keys() on undefined csEntries throws a TypeError. Add guards to skip sections with empty translations in the currentSections.find() callback, matching the existing pattern used in the outer map. Co-Authored-By: Claude Opus 4.6 --- .changeset/fix-po-loader-crash.md | 5 +++++ packages/cli/src/cli/loaders/po/index.ts | 6 ++++++ 2 files changed, 11 insertions(+) create mode 100644 .changeset/fix-po-loader-crash.md diff --git a/.changeset/fix-po-loader-crash.md b/.changeset/fix-po-loader-crash.md new file mode 100644 index 000000000..d21bdcced --- /dev/null +++ b/.changeset/fix-po-loader-crash.md @@ -0,0 +1,5 @@ +--- +"lingo.dev": patch +--- + +Fix crash in PO loader when current section has no translations diff --git a/packages/cli/src/cli/loaders/po/index.ts b/packages/cli/src/cli/loaders/po/index.ts index 8363a426c..834d42e97 100644 --- a/packages/cli/src/cli/loaders/po/index.ts +++ b/packages/cli/src/cli/loaders/po/index.ts @@ -67,8 +67,14 @@ export function createPoDataLoader( // If the section is empty, try to find it in the current sections const currentSection = currentSections.find((cs) => { const csPo = gettextParser.po.parse(cs); + if (Object.keys(csPo.translations).length === 0) { + return false; + } const csContextKey = _.keys(csPo.translations)[0]; const csEntries = csPo.translations[csContextKey]; + if (!csEntries) { + return false; + } const csMsgid = Object.keys(csEntries).find( (key) => csEntries[key].msgid, );