From c868da4de607d48d27d5cf9852871ed4698627f8 Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Mon, 27 May 2019 08:03:55 +0000 Subject: [PATCH] [FIX] tools: export UTF-8 characters MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Install Babel 2.3.4 as specified in the `requirements.txt` - In a Python file, do not add the line `# -*- coding: utf-8 -*-` - Create a translatable string with a non-ASCII character, e.g. `Amount in €` - Export the translation The exported term is incorrect: `Amount in â¬`. Since the default encoding for Python 3 is UTF-8, it is logical for the Babel extraction to use it as a default encoding. The issue was solved in Babel 2.4.0 with commit: https://github.com/python-babel/babel/commit/33a8fc40d417b401162e2d20021fcbebcc4ab7db opw-1984480 closes odoo/odoo#33671 Signed-off-by: Nicolas Martinelli (nim) --- odoo/tools/translate.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/odoo/tools/translate.py b/odoo/tools/translate.py index 5561aa082c7..5a11f004ada 100644 --- a/odoo/tools/translate.py +++ b/odoo/tools/translate.py @@ -953,8 +953,11 @@ def trans_generate(lang, modules, cr): extra_comments = extra_comments or [] if not module: return src_file = open(fabsolutepath, 'rb') + options = {} + if extract_method == 'python': + options['encoding'] = 'UTF-8' try: - for extracted in extract.extract(extract_method, src_file, keywords=extract_keywords): + for extracted in extract.extract(extract_method, src_file, keywords=extract_keywords, options=options): # Babel 0.9.6 yields lineno, message, comments # Babel 1.3 yields lineno, message, comments, context lineno, message, comments = extracted[:3]