From 8686adbb5495904e97c457c74a06791fc3c55798 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20H=C3=A4ttasch?= <benjamin.haettasch@fachschaft.informatik.tu-darmstadt.de> Date: Sat, 22 Oct 2022 15:31:15 +0200 Subject: [PATCH] Adapt django makemessages command to ensure forward slashes This adapts submethods of the makemessages command to use generic forward slashes instead of os specific slashes, e.g., backslashes on windows --- AKModel/management/__init__.py | 0 AKModel/management/commands/__init__.py | 0 AKModel/management/commands/makemessages.py | 39 +++++++++++++++++++++ 3 files changed, 39 insertions(+) create mode 100644 AKModel/management/__init__.py create mode 100644 AKModel/management/commands/__init__.py create mode 100644 AKModel/management/commands/makemessages.py diff --git a/AKModel/management/__init__.py b/AKModel/management/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/AKModel/management/commands/__init__.py b/AKModel/management/commands/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/AKModel/management/commands/makemessages.py b/AKModel/management/commands/makemessages.py new file mode 100644 index 00000000..d3e9149e --- /dev/null +++ b/AKModel/management/commands/makemessages.py @@ -0,0 +1,39 @@ +""" +Ensure PO files are generated using forward slashes in the location comments on all operating systems +""" +import os + +from django.core.management.commands.makemessages import Command as MakeMessagesCommand + + +class Command(MakeMessagesCommand): + def find_files(self, root): + all_files = super().find_files(root) + if os.sep != "\\": + return all_files + + for file_entry in all_files: + if file_entry.dirpath == ".": + file_entry.dirpath = "" + elif file_entry.dirpath.startswith(".\\"): + file_entry.dirpath = file_entry.dirpath[2:].replace("\\", "/") + + return all_files + + def build_potfiles(self): + pot_files = super().build_potfiles() + if os.sep != "\\": + return pot_files + + for filename in pot_files: + lines = open(filename, "r", encoding="utf-8").readlines() + fixed_lines = [] + for line in lines: + if line.startswith("#: "): + line = line.replace("\\", "/") + fixed_lines.append(line) + + with open(filename, "w", encoding="utf-8") as f: + f.writelines(fixed_lines) + + return pot_files -- GitLab