Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/utils/po-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,11 @@ export function normalizeReferences(reference: string | string[]): string[] {
return normalized;
}

// gettext allows flags on one `#,` line or spread across several, and
// gettext-parser joins the latter with a newline rather than a comma.
function parsePoFlags(flag: string | undefined): string[] | undefined {
if (!flag) return undefined;
const flags = flag.split(/,\s*/).map(f => f.trim()).filter(Boolean);
const flags = flag.split(/[,\n]\s*/).map(f => f.trim()).filter(Boolean);
return flags.length > 0 ? flags : undefined;
}

Expand Down
26 changes: 26 additions & 0 deletions tests/utils/po-utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,32 @@ msgstr[1] "%(count)d items"
expect(result['Copyright notice'].metadata.source_references).toEqual(['src/components/Footer.tsx:9']);
});

// gettext allows flags on separate `#,` lines and gettext-parser joins them
// with a newline. Splitting on commas alone produced one bogus flag,
// "fuzzy\npython-format". Parsed from real PO text rather than a hand-built
// entry, so this guards the gettext-parser integration and not just the split.
it('should split flags spread across several #, lines', () => {
const content = `msgid ""
msgstr ""
"Content-Type: text/plain; charset=UTF-8\\n"

#, fuzzy
#, python-format
msgid "Welcome %(name)s"
msgstr "Bienvenue %(name)s"

#, fuzzy, c-format
msgid "Goodbye %(name)s"
msgstr "Au revoir %(name)s"
`;

const result = poEntriesToApiFormat(parsePoFile(content));

expect(result['Welcome %(name)s'].metadata.po_flags).toEqual(['fuzzy', 'python-format']);
// the single-line form must keep working
expect(result['Goodbye %(name)s'].metadata.po_flags).toEqual(['fuzzy', 'c-format']);
});

it('should preserve fuzzy flag in plural forms', () => {
const entries = [
{
Expand Down
Loading