From 96ebf5bc3fb455162286b9bc31e763f3c4f1c457 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Wed, 8 Aug 2018 18:24:49 -0700 Subject: Two fixes and translate more strings. * Fix finding translations with escaped characters. * Add back \r to translations since its needed by screen. --- py/makeqstrdata.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'py/makeqstrdata.py') diff --git a/py/makeqstrdata.py b/py/makeqstrdata.py index 719bc62fa..fd41e3b0e 100644 --- a/py/makeqstrdata.py +++ b/py/makeqstrdata.py @@ -66,7 +66,7 @@ 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] + return [(x, table.gettext(x.decode('string_escape'))) for x in i18ns] def qstr_escape(qst): def esc_char(m): @@ -181,6 +181,8 @@ 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") print("TRANSLATION(\"{}\", \"{}\")".format(original, translation)) total_text_size += len(translation) -- cgit v1.2.3 From 24e53ad5911f42efb6508b4a8dcf4a196a81494a Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Thu, 9 Aug 2018 15:58:45 -0700 Subject: Rework escaping and fix ESP build. --- ports/atmel-samd/Makefile | 4 ---- ports/esp8266/esp8266_common.ld | 1 + py/makeqstrdata.py | 24 ++++++++++++++++++++++-- py/mkenv.mk | 3 +++ py/mkrules.mk | 4 ++-- py/py.mk | 4 ++-- 6 files changed, 30 insertions(+), 10 deletions(-) (limited to 'py/makeqstrdata.py') diff --git a/ports/atmel-samd/Makefile b/ports/atmel-samd/Makefile index 37bae87f4..459a90478 100755 --- a/ports/atmel-samd/Makefile +++ b/ports/atmel-samd/Makefile @@ -1,7 +1,3 @@ -# Set default python interpreters -PYTHON2 ?= $(which python2 || which python2.7) -PYTHON3 ?= python3 - # Select the board to build for. ifeq ($(BOARD),) $(error You must provide a BOARD parameter) diff --git a/ports/esp8266/esp8266_common.ld b/ports/esp8266/esp8266_common.ld index b247e3ffd..c76b83bc4 100644 --- a/ports/esp8266/esp8266_common.ld +++ b/ports/esp8266/esp8266_common.ld @@ -89,6 +89,7 @@ SECTIONS *common-hal/*.o*(.literal* .text*) *shared-bindings/*.o*(.literal* .text*) *shared-module/*.o*(.literal* .text*) + *supervisor/*.o*(.literal* .text*) *py/argcheck.o*(.literal* .text*) *py/asm*.o*(.literal* .text*) diff --git a/py/makeqstrdata.py b/py/makeqstrdata.py index fd41e3b0e..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.decode('string_escape'))) 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): @@ -182,7 +200,9 @@ 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") + 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) diff --git a/py/mkenv.mk b/py/mkenv.mk index 1b316c39d..facb8a3c2 100644 --- a/py/mkenv.mk +++ b/py/mkenv.mk @@ -49,6 +49,9 @@ CP = cp FIND = find MKDIR = mkdir PYTHON = python +# Set default python interpreters +PYTHON2 ?= $(which python2 || which python2.7) +PYTHON3 ?= python3 RM = rm RSYNC = rsync SED = sed diff --git a/py/mkrules.mk b/py/mkrules.mk index 0a37eadef..e619f2bdd 100644 --- a/py/mkrules.mk +++ b/py/mkrules.mk @@ -83,12 +83,12 @@ $(HEADER_BUILD)/qstr.i.last: $(SRC_QSTR) $(SRC_QSTR_PREPROCESSOR) $(QSTR_GLOBAL_ $(HEADER_BUILD)/qstr.split: $(HEADER_BUILD)/qstr.i.last $(PY_SRC)/makeqstrdefs.py $(STEPECHO) "GEN $@" - $(Q)$(PYTHON) $(PY_SRC)/makeqstrdefs.py split $(HEADER_BUILD)/qstr.i.last $(HEADER_BUILD)/qstr $(QSTR_DEFS_COLLECTED) + $(Q)$(PYTHON3) $(PY_SRC)/makeqstrdefs.py split $(HEADER_BUILD)/qstr.i.last $(HEADER_BUILD)/qstr $(QSTR_DEFS_COLLECTED) $(Q)touch $@ $(QSTR_DEFS_COLLECTED): $(HEADER_BUILD)/qstr.split $(PY_SRC)/makeqstrdefs.py $(STEPECHO) "GEN $@" - $(Q)$(PYTHON) $(PY_SRC)/makeqstrdefs.py cat $(HEADER_BUILD)/qstr.i.last $(HEADER_BUILD)/qstr $(QSTR_DEFS_COLLECTED) + $(Q)$(PYTHON3) $(PY_SRC)/makeqstrdefs.py cat $(HEADER_BUILD)/qstr.i.last $(HEADER_BUILD)/qstr $(QSTR_DEFS_COLLECTED) # $(sort $(var)) removes duplicates # diff --git a/py/py.mk b/py/py.mk index ecd66531b..dcaa0e805 100644 --- a/py/py.mk +++ b/py/py.mk @@ -307,7 +307,7 @@ $(HEADER_BUILD)/qstrdefs.preprocessed.h: $(PY_QSTR_DEFS) $(QSTR_DEFS) $(QSTR_DEF # qstr data $(HEADER_BUILD)/qstrdefs.enum.h: $(PY_SRC)/makeqstrdata.py $(HEADER_BUILD)/qstrdefs.preprocessed.h $(STEPECHO) "GEN $@" - $(PYTHON) $(PY_SRC)/makeqstrdata.py $(HEADER_BUILD)/qstrdefs.preprocessed.h > $@ + $(PYTHON3) $(PY_SRC)/makeqstrdata.py $(HEADER_BUILD)/qstrdefs.preprocessed.h > $@ # Adding an order only dependency on $(HEADER_BUILD) causes $(HEADER_BUILD) to get # created before we run the script to generate the .h @@ -315,7 +315,7 @@ $(HEADER_BUILD)/qstrdefs.enum.h: $(PY_SRC)/makeqstrdata.py $(HEADER_BUILD)/qstrd # the lines in "" and then unwrap after the preprocessor is finished. $(HEADER_BUILD)/qstrdefs.generated.h: $(PY_SRC)/makeqstrdata.py $(HEADER_BUILD)/$(TRANSLATION).mo $(HEADER_BUILD)/qstrdefs.preprocessed.h $(STEPECHO) "GEN $@" - $(Q)$(PYTHON) $(PY_SRC)/makeqstrdata.py --translation $(HEADER_BUILD)/$(TRANSLATION).mo $(HEADER_BUILD)/qstrdefs.preprocessed.h > $@ + $(PYTHON3) $(PY_SRC)/makeqstrdata.py --translation $(HEADER_BUILD)/$(TRANSLATION).mo $(HEADER_BUILD)/qstrdefs.preprocessed.h > $@ $(PY_BUILD)/qstr.o: $(HEADER_BUILD)/qstrdefs.generated.h -- cgit v1.2.3