чување bf611cfc279002803a275d3f8efc20cf21315a7a
родитељ 63c0bfe26127445e77b898d992cace8aa29e4f03
Аутор: Страхиња Радић <sr@strahinja.org>
Датум: Sun, 26 Jul 2026 21:16:41 +0000
po.c: Parse and write out wrapped Plural-Forms properly
Diffstat:
| M | po.c | | | 26 | ++++++++++++++++++++------ |
| M | po.h | | | 3 | ++- |
измењених датотека: 2, додавања: 22(+), брисања: 7(-)
diff --git a/po.c b/po.c
@@ -614,13 +614,26 @@ parse_po_line(const char* line, struct DrawState* dstate,
/* first entry */
if (*current_entry == dstate->entries)
{
- if (starts_with(token, "Plural-Forms: "))
+ if (*pstate & PS_PLURAL_FORMS)
{
if (set_plural_forms(dstate, *current_entry,
+ token, 1))
+ goto parse_po_line_alloc_error;
+ if (strstr(token, "\\n"))
+ {
+ *pstate &= ~PS_PLURAL_FORMS;
+ if (set_nplurals(dstate, *current_entry))
+ goto parse_po_cleanup;
+ }
+ }
+ else
+ {
+ if (starts_with(token, "Plural-Forms: ")
+ && !strstr(token, "\\n"))
+ *pstate |= PS_PLURAL_FORMS;
+ if (set_plural_forms(dstate, *current_entry,
token + strlen("Plural-Forms: "), 0))
goto parse_po_line_alloc_error;
- if (set_nplurals(dstate, *current_entry))
- goto parse_po_cleanup;
}
}
@@ -1193,8 +1206,9 @@ save_msgstrs(FILE* output, struct DrawState* state,
&& starts_with(u8_msgstr, "Plural-Forms: "))
{
seen_plural_forms = 1;
- fprintf(output, "\"Plural-Forms: %s\\n\"\n",
- plural_string);
+ fprintf(output, "\"%s\"\n", u8_msgstr);
+ /*fprintf(output, "\"Plural-Forms: %s\\n\"\n",
+ plural_string);*/
}
else
fprintf(output, "\"%s\"\n", u8_msgstr);
@@ -1678,7 +1692,7 @@ u32_set_plural_forms(struct DrawState* state, struct PoEntry* entry,
if (!entry->plural_forms)
goto u32_set_plural_forms_alloc_error;
}
- else if (entry->plural_forms_size + plural_forms_len
+ else if (entry->plural_forms_len + plural_forms_len
>= entry->plural_forms_size)
{
entry->plural_forms_size += MSGDELTA;
diff --git a/po.h b/po.h
@@ -21,7 +21,8 @@ typedef enum {
PS_MSGID_PLURAL = 1 << 6,
PS_MSGSTR = 1 << 7,
PS_MSGSTR_ARRAY = 1 << 8,
- PS_STRING = 1 << 9 /* string literal */
+ PS_STRING = 1 << 9, /* string literal */
+ PS_PLURAL_FORMS = 1 << 10 /* Plural-Forms: */
} ParseState;
#define PS_COMMENT \