diff options
| author | Dan Halbert <halbert@halwitz.org> | 2018-08-09 20:00:18 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-08-09 20:00:18 -0400 |
| commit | bbc034cd3dfc46ee7938faedc915fec91610c6a3 (patch) | |
| tree | 4fe11d359088e41790030fce0763471b76ab3fb4 /py/makeqstrdata.py | |
| parent | b735b9dbed2132f07793324a40770f4bd96d9ae8 (diff) | |
| parent | 24e53ad5911f42efb6508b4a8dcf4a196a81494a (diff) | |
Merge pull request #1104 from tannewt/more_strings
Fixes and translate more strings.
Diffstat (limited to 'py/makeqstrdata.py')
| -rw-r--r-- | py/makeqstrdata.py | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/py/makeqstrdata.py b/py/makeqstrdata.py index 719bc62fa..4be71a8d9 100644 --- a/py/makeqstrdata.py +++ b/py/makeqstrdata.py @@ -54,6 +54,18 @@ codepoint2name[ord('^')] = 'caret' codepoint2name[ord('|')] = 'pipe' codepoint2name[ord('~')] = 'tilde' +C_ESCAPES = { + "\a": "\\a", + "\b": "\\b", + "\f": "\\f", + "\n": "\\r", + "\r": "\\r", + "\t": "\\t", + "\v": "\\v", + "\'": "\\'", + "\"": "\\\"" +} + # this must match the equivalent function in qstr.c def compute_hash(qstr, bytes_hash): hash = 5381 @@ -66,7 +78,13 @@ def translate(translation_file, i18ns): with open(translation_file, "rb") as f: table = gettext.GNUTranslations(f) - return [(x, table.gettext(x)) for x in i18ns] + translations = [] + for original in i18ns: + unescaped = original + for s in C_ESCAPES: + unescaped = unescaped.replace(C_ESCAPES[s], s) + translations.append((original, table.gettext(unescaped))) + return translations def qstr_escape(qst): def esc_char(m): @@ -181,6 +199,10 @@ def print_qstr_data(qcfgs, qstrs, i18ns): total_text_size = 0 for original, translation in i18ns: + # Add in carriage returns to work in terminals + translation = translation.replace("\n", "\r\n") + for s in C_ESCAPES: + translation = translation.replace(s, C_ESCAPES[s]) print("TRANSLATION(\"{}\", \"{}\")".format(original, translation)) total_text_size += len(translation) |
