poe

Уређивач .po фајлова
Дневник | Датотеке | Референце | ПРОЧИТАЈМЕ | ЛИЦЕНЦА

чување 8834e27fb0ca71c52c3589d346cd854f93f4fb42
родитељ 50acc6280cd1049c8303f99cb922084dc082c817
Аутор: Страхиња Радић <contact@strahinja.org>
Датум:   Fri, 29 Oct 2021 23:23:17 +0200

Automatically add msgstr[] if msgid_plural is present

Signed-off-by: Страхиња Радић <contact@strahinja.org>

Diffstat:
MTODO | 6+++---
Mdraw.c | 3++-
Mpo.c | 17++++++++++++++++-
Mutil.h | 3++-
измењених датотека: 4, додавања: 23(+), брисања: 6(-)

diff --git a/TODO b/TODO @@ -5,9 +5,9 @@ [x] canceling dirty edit box [x] copying msgid to msgstr if msgstr nonempty - [ ] Plural forms QoL - [ ] Warn if Plural-Forms not present - [ ] Automatically add msgstr[] if nplurals>1 + [x] Plural forms QoL + [x] Warn if Plural-Forms not present + [x] Automatically add msgstr[] if msgid_plural is present [x] Avoid adding extra lines at the end of file diff --git a/draw.c b/draw.c @@ -41,7 +41,8 @@ const char* errors[] = { [ERR_CANT_ALLOC] = "Memory allocation failed", [ERR_CANT_SAVE] = "File is not writeable", [ERR_CANT_MOVE] = "Cannot move temporary file", - [ERR_ILLEGAL_ON_FIRST] = "Not allowed on first entry"}; + [ERR_ILLEGAL_ON_FIRST] = "Not allowed on first entry", + [ERR_NO_PLURAL_FORMS] = "No Plural-Forms (add manually)"}; const char* flag_strings[] = { [FL_C_FORMAT] = "c-format", [FL_NO_C_FORMAT] = "no-c-format", diff --git a/po.c b/po.c @@ -9,6 +9,7 @@ #include "util.h" #include "version.h" +extern const char* errors[]; extern const char* flag_strings[]; char* @@ -392,6 +393,7 @@ load_file(struct DrawState* dstate, long* lineno, long* col) struct PoEntry* newchunk = calloc(ALLOC_DELTA, sizeof(struct PoEntry)); struct PoEntry* entry = NULL; ParseState pstate = PS_NONE; + int has_plural_msgid = 0; dstate->msgid_size = 0; if (!newchunk) @@ -422,6 +424,10 @@ load_file(struct DrawState* dstate, long* lineno, long* col) int result; result = parse_po_line(input_line, dstate, &entry, &pstate, col, &msgstr_index); + + if (entry && entry->msgid_plural) + has_plural_msgid = 1; + if (result == PARSE_ERR_NONE) { if (pstate & PS_MSGID) @@ -454,6 +460,8 @@ load_file(struct DrawState* dstate, long* lineno, long* col) else if (entry->comment_lines > 0) /* obsolete entry */ entry->obsolete = 1; + if (has_plural_msgid && !dstate->entries->plural_forms) + strcpy(dstate->error, errors[ERR_NO_PLURAL_FORMS]); } /* file has < PO_DETECTION_LINES */ @@ -559,7 +567,7 @@ save_loop_entries_start: if (current->msgid) { - size_t msgid_size = current->msgid_size * UTF8REPMAX; + size_t msgid_size = current->msgid_size * UTF8REPMAX; size_t actual_lines = 0; size_t num_lines = u32_lines_in_string(current->msgid, &actual_lines); @@ -1032,7 +1040,13 @@ parse_po_line(const char* line, struct DrawState* dstate, if (*pstate & PS_MSGID) set_msgid(*current_entry, token, 1); else if (*pstate & PS_MSGID_PLURAL) + { set_msgid_plural(*current_entry, token, 1); + if (*current_entry != dstate->entries) + for (int i = 0; i < dstate->nplurals; i++) + set_msgstr(*current_entry, NULL, i, 0, + dstate); + } else if (*pstate & PS_MSGSTR) { /* first entry */ @@ -1046,6 +1060,7 @@ parse_po_line(const char* line, struct DrawState* dstate, set_nplurals(dstate, *current_entry); } } + set_msgstr(*current_entry, token, 0, 1, dstate); } else if (*pstate & PS_MSGSTR_ARRAY) diff --git a/util.h b/util.h @@ -14,7 +14,8 @@ enum { ERR_CANT_ALLOC, ERR_CANT_SAVE, ERR_CANT_MOVE, - ERR_ILLEGAL_ON_FIRST + ERR_ILLEGAL_ON_FIRST, + ERR_NO_PLURAL_FORMS }; #define MAXBUFLINE 4096