From d3c1ec7308af7c5b25467bada2336b5cbdecb810 Mon Sep 17 00:00:00 2001 From: signedav Date: Wed, 19 Apr 2023 09:40:47 +0200 Subject: [PATCH] Set encoding of `request.get` result to `utf-8` (#222) * set encoding of result to utf-8. This fixes that the encoding of umlauts where broken in the ts files. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * comment why we set the encoding hardcoded * check if request response encoding is None before setting it static to utf-8 --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- qgispluginci/translation_clients/transifex.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/qgispluginci/translation_clients/transifex.py b/qgispluginci/translation_clients/transifex.py index 9b4bb745..8252d457 100644 --- a/qgispluginci/translation_clients/transifex.py +++ b/qgispluginci/translation_clients/transifex.py @@ -133,7 +133,11 @@ def get_translation( resource=self.get_resource(), language=language ) - translated_content = requests.get(url).text + r = requests.get(url) + # transifex returns None encoding and the apparent_encoding is Windows-1254 what leads to malformed result strings. So we set the encoding hardcoded to utf-8. + if not r.encoding: + r.encoding = "utf-8" + translated_content = r.text with open(path_to_output_file, "w") as fh: fh.write(translated_content)