Skip to content

Commit 56d0a47

Browse files
cherkanovartclaude
andauthored
fix(cli): guard against empty translations in PO loader push (#2000)
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 <noreply@anthropic.com>
1 parent 588d3d8 commit 56d0a47

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

.changeset/fix-po-loader-crash.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"lingo.dev": patch
3+
---
4+
5+
Fix crash in PO loader when current section has no translations

packages/cli/src/cli/loaders/po/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,14 @@ export function createPoDataLoader(
6767
// If the section is empty, try to find it in the current sections
6868
const currentSection = currentSections.find((cs) => {
6969
const csPo = gettextParser.po.parse(cs);
70+
if (Object.keys(csPo.translations).length === 0) {
71+
return false;
72+
}
7073
const csContextKey = _.keys(csPo.translations)[0];
7174
const csEntries = csPo.translations[csContextKey];
75+
if (!csEntries) {
76+
return false;
77+
}
7278
const csMsgid = Object.keys(csEntries).find(
7379
(key) => csEntries[key].msgid,
7480
);

0 commit comments

Comments
 (0)