#16493 closed New feature (needsinfo)
Windows: makemessages generate django.po should use forward slashes too
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | Core (Management commands) | Version: | 1.3 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | yes | UI/UX: | no |
Description
develope under windows, run "python manage.py makemessages ...", will write file path use "\" in django.po,
the files copy to product linux server, should not be valid, because unix/linux use "/" as path seperater.
the solution should be use the same "/" in path string even under windows.
so, I add a function "normpath" to ensure use "/" under windows:
def normpath(filepath): p = os.path.normpath(filepath) if os.name=='nt': p = p.replace("\\", "/") return p
Attachments (1)
Change History (8)
by , 13 years ago
Attachment: | makemessages.py added |
---|
comment:1 by , 13 years ago
Resolution: | → needsinfo |
---|---|
Status: | new → closed |
comment:2 by , 12 years ago
Summary: | winodws: makemessages generate django.po should use forward slashes too → Windows: makemessages generate django.po should use forward slashes too |
---|
comment:3 by , 12 years ago
The problem i had here was merging between developers using windows and linux. The windows version change everything to backslash and linux version changes it to slash. The end result is we need end merging all comments.
comment:4 by , 12 years ago
makemessages gained a '--no-location' option since this ticket was initially filed. That probably resolves your problem.
comment:5 by , 3 years ago
This makes it difficult for Unix and Windows developers to be working on the same project. The .po file will switch back and forth each time. The file in the comment is useful information, so using --no-location
is not a great solution.
comment:6 by , 3 years ago
I agree with John. Removing information from the document is not the solution to a problem which is easily fixable within the makemessages command.
comment:7 by , 3 years ago
The following makemessages.py works around this problem:
import os import sys 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
The only paths in .po files are comments, so I don't understand why you say that the resulting file "should not be valid".
Do you really get an error? If yes, can you provide the traceback?