From 81d5cc29d574a221e72b4ab0da3dfb109c65a87b Mon Sep 17 00:00:00 2001 From: matejcik Date: Wed, 12 Jun 2024 11:21:34 +0200 Subject: [PATCH] fix(core/translations): properly update stored json version --- core/translations/cli.py | 64 ++++++++++++++++++++------------------- core/translations/cs.json | 2 +- core/translations/de.json | 2 +- core/translations/en.json | 4 +-- core/translations/es.json | 2 +- core/translations/fr.json | 2 +- 6 files changed, 38 insertions(+), 38 deletions(-) diff --git a/core/translations/cli.py b/core/translations/cli.py index b0c59651b1..5a10441e85 100644 --- a/core/translations/cli.py +++ b/core/translations/cli.py @@ -71,7 +71,7 @@ def _version_from_version_h() -> VersionTuple: ) -def _version_str(version: VersionTuple) -> str: +def _version_str(version: tuple[int, ...]) -> str: return ".".join(str(v) for v in version) @@ -128,46 +128,47 @@ class TranslationsDir: return json.loads(self._lang_path(lang).read_text()) def save_lang(self, lang: str, data: translations.JsonDef) -> None: - self._lang_path(lang).write_text(json.dumps(data, indent=2) + "\n") + self._lang_path(lang).write_text( + json.dumps( + data, + indent=2, + ensure_ascii=False, + ) + + "\n" + ) def all_languages(self) -> t.Iterable[str]: return (lang_file.stem for lang_file in self.path.glob("??.json")) + def update_version_from_h(self) -> VersionTuple: + version = _version_from_version_h() + for lang in self.all_languages(): + blob_json = self.load_lang(lang) + blob_version = translations.version_from_json( + blob_json["header"]["version"] + ) + if blob_version != version: + blob_json["header"]["version"] = _version_str(version[:3]) + self.save_lang(lang, blob_json) + return version + def generate_single_blob( self, lang: str, model: models.TrezorModel, version: VersionTuple | None, - write_version: bool = False, ) -> translations.TranslationsBlob: blob_json = self.load_lang(lang) blob_version = translations.version_from_json(blob_json["header"]["version"]) - - if version is None: - version = blob_version - - if write_version and blob_version != version: - blob_json["header"]["version"] = _version_str(version) - self.save_lang(lang, blob_json) - return translations.blob_from_defs( - blob_json, self.order, model, version, self.fonts_dir + blob_json, self.order, model, version or blob_version, self.fonts_dir ) def generate_all_blobs( - self, - version: VersionTuple | t.Literal["auto"] | t.Literal["json"], + self, version: VersionTuple | None ) -> list[translations.TranslationsBlob]: - current_version = _version_from_version_h() common_version = None - if version == "auto": - used_version = current_version - elif version == "json": - used_version = None - else: - used_version = version - all_blobs: list[translations.TranslationsBlob] = [] for lang in self.all_languages(): if lang == "en": @@ -175,7 +176,7 @@ class TranslationsDir: for model in ALL_MODELS: try: - blob = self.generate_single_blob(lang, model, used_version) + blob = self.generate_single_blob(lang, model, version) blob_version = blob.header.firmware_version if common_version is None: common_version = blob_version @@ -214,7 +215,7 @@ def build_all_blobs( blob.proof = proof header = blob.header model = header.model.value.decode("ascii") - version = ".".join(str(v) for v in header.firmware_version[:3]) + version = _version_str(header.firmware_version[:3]) if production: suffix = "" else: @@ -239,12 +240,13 @@ def gen(signed: bool | None, version_str: str | None) -> None: The generated blobs will be signed with the development keys. """ - if version_str is not None: - version = translations.version_from_json(version_str) - else: - version = "auto" - tdir = TranslationsDir() + + if version_str is None: + version = tdir.update_version_from_h() + else: + version = translations.version_from_json(version_str) + all_blobs = tdir.generate_all_blobs(version) tree = merkle_tree.MerkleTree(b.header_bytes for b in all_blobs) root = tree.get_root_hash() @@ -284,7 +286,7 @@ def gen(signed: bool | None, version_str: str | None) -> None: def merkle_root(version_str: str | None) -> None: """Print the Merkle root of all language blobs.""" if version_str is None: - version = "json" + version = None else: version = translations.version_from_json(version_str) @@ -320,7 +322,7 @@ def merkle_root(version_str: str | None) -> None: def sign(signature_hex: str, force: bool | None, version_str: str | None) -> None: """Insert a signature into language blobs.""" if version_str is None: - version = "json" + version = None else: version = translations.version_from_json(version_str) diff --git a/core/translations/cs.json b/core/translations/cs.json index df085e210c..85afc615bd 100644 --- a/core/translations/cs.json +++ b/core/translations/cs.json @@ -33,7 +33,7 @@ }, "header": { "language": "cs-CZ", - "version": "2.7.1" + "version": "2.7.3" }, "translations": { "addr_mismatch__contact_support_at": "Kontaktujte naši podporu na", diff --git a/core/translations/de.json b/core/translations/de.json index 169f99644d..577acc603f 100644 --- a/core/translations/de.json +++ b/core/translations/de.json @@ -33,7 +33,7 @@ }, "header": { "language": "de-DE", - "version": "2.7.1" + "version": "2.7.3" }, "translations": { "addr_mismatch__contact_support_at": "Kontaktiere den Trezor Support unter", diff --git a/core/translations/en.json b/core/translations/en.json index bcf55d7237..3baeca142b 100644 --- a/core/translations/en.json +++ b/core/translations/en.json @@ -1,7 +1,7 @@ { "header": { "language": "en-US", - "version": "2.7.1" + "version": "2.7.3" }, "translations": { "addr_mismatch__contact_support_at": "Please contact Trezor support at", @@ -389,8 +389,6 @@ "instructions__swipe_up": "Swipe up", "instructions__tap_to_confirm": "Tap to confirm", "instructions__tap_to_start": "Tap to start", - "instructions__hold_to_confirm": "Hold to confirm", - "instructions__continue_holding": "Continue\nholding", "joint__title": "Joint transaction", "joint__to_the_total_amount": "To the total amount:", "joint__you_are_contributing": "You are contributing:", diff --git a/core/translations/es.json b/core/translations/es.json index d1781165e6..add221e892 100644 --- a/core/translations/es.json +++ b/core/translations/es.json @@ -33,7 +33,7 @@ }, "header": { "language": "es-ES", - "version": "2.7.1" + "version": "2.7.3" }, "translations": { "addr_mismatch__contact_support_at": "Contacta con atención al cliente de Trezor en", diff --git a/core/translations/fr.json b/core/translations/fr.json index e11614f3a9..97ac56bdba 100644 --- a/core/translations/fr.json +++ b/core/translations/fr.json @@ -33,7 +33,7 @@ }, "header": { "language": "fr-FR", - "version": "2.7.1" + "version": "2.7.3" }, "translations": { "addr_mismatch__contact_support_at": "Contactez l'assistance Trezor à l'adr.",