Fix encoding/decoding issues (Windows) for i18n import script.

part of CURA-6663
This commit is contained in:
Remco Burema 2019-08-08 15:47:05 +02:00
parent 2d4fd5649d
commit 0b27119001

View file

@ -2,6 +2,7 @@
# Cura is released under the terms of the LGPLv3 or higher. # Cura is released under the terms of the LGPLv3 or higher.
import argparse #To get the source directory from command line arguments. import argparse #To get the source directory from command line arguments.
import io # To fix encoding issues in Windows
import os #To find files from the source. import os #To find files from the source.
import os.path #To find files from the source and the destination path. import os.path #To find files from the source and the destination path.
@ -34,12 +35,12 @@ def lionbridge_import(source: str) -> None:
else: else:
raise Exception("Unknown file: " + source_file + "... Is this Cura or Uranium?") raise Exception("Unknown file: " + source_file + "... Is this Cura or Uranium?")
with open(os.path.join(directory, file_pot)) as f: with io.open(os.path.join(directory, file_pot), encoding = "utf8") as f:
source_str = f.read() source_str = f.read()
with open(destination_file) as f: with io.open(destination_file, encoding = "utf8") as f:
destination_str = f.read() destination_str = f.read()
result = merge(source_str, destination_str) result = merge(source_str, destination_str)
with open(destination_file, "w") as f: with io.open(destination_file, "w", encoding = "utf8") as f:
f.write(result) f.write(result)
## Gets the destination path to copy the translations for Cura to. ## Gets the destination path to copy the translations for Cura to.