-
Notifications
You must be signed in to change notification settings - Fork 444
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Addressing problems raised in sphinx_issues #10104 #863
base: master
Are you sure you want to change the base?
Changes from 4 commits
3258580
67aa652
53c89f4
7bddb4b
314b648
90dd90d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,7 +35,7 @@ | |
(?:\.(?:\*|[\d]+))? | ||
[hlL]? | ||
) | ||
([diouxXeEfFgGcrs%]) | ||
((?<!\s)[diouxXeEfFgGcrs%])(?=([\s\'\)\.\,\:\"\!\]\>\?]|$)) | ||
''', re.VERBOSE) | ||
|
||
|
||
|
@@ -94,7 +94,7 @@ def __init__(self, id, string=u'', locations=(), flags=(), auto_comments=(), | |
if not string and self.pluralizable: | ||
string = (u'', u'') | ||
self.string = string | ||
self.locations = list(distinct(locations)) | ||
self.locations = list(set(locations)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this changed? Using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you so much for your comments. Please read my original post here (Message.locations duplicate unnecessary) for the original observations and tests performed. I just personally found that locations will need to be sorted in alphabetical order for user to easily observing and finding the file, especially when the location list is long. so to make it unique using 'set' would not affecting the performance and the correctness. This is one example of location list in the Blender
The original document can be found here Blender UI translation SVN Repository You can just run
and take a look at the file. As a translator, I have occasionally observing changes from the 'blender.pot' file and I always wished this location data block is made distinct and sorted alphabetically. |
||
self.flags = set(flags) | ||
if id and self.python_format: | ||
self.flags.add('python-format') | ||
|
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -276,6 +276,7 @@ def _process_comment(self, line): | |||||||
self.locations.append((location[:pos], lineno)) | ||||||||
else: | ||||||||
self.locations.append((location, None)) | ||||||||
self.locations = list(set(self.locations)) | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here, this should probably also use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you, you're right, don't need to perform this here. When the message is created then do it there instead, once and for all. Thank you again. |
||||||||
elif line[1:].startswith(','): | ||||||||
for flag in line[2:].lstrip().split(','): | ||||||||
self.flags.append(flag.strip()) | ||||||||
|
@@ -521,14 +522,21 @@ def _write(text): | |||||||
text = text.encode(catalog.charset, 'backslashreplace') | ||||||||
fileobj.write(text) | ||||||||
|
||||||||
<<<<<<< HEAD | ||||||||
def _write_comment(comment, prefix='': | ||||||||
======= | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Merge conflict marker and syntax error. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know why there is an error here, the code at my local appeared to be OK. I will make another push to ensure the correct code is placed. |
||||||||
def _write_comment(comment, prefix=''): | ||||||||
# xgettext always wraps comments even if --no-wrap is passed; | ||||||||
# provide the same behaviour | ||||||||
if width and width > 0: | ||||||||
_width = width | ||||||||
else: | ||||||||
_width = 76 | ||||||||
for line in wraptext(comment, _width): | ||||||||
>>>>>>> 67aa652a1c10bfdc92587cdae87fdab65d633b23 | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Merge conflict marker. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These lines are removed. There is no need for wrapping comments any more. Please refer back to the original post commented above |
||||||||
# NEVER wrap comments, this observation: "xgettext always wraps comments even if --no-wrap is passed;" is FALSE. There seemed to be a bug in the xgettext code, because wrapping doesn't always occur | ||||||||
# Make sure comments are unique and sorted alphabetically so locations can be easily searched and identify | ||||||||
has_comment = (bool(comment) and len(comment) > 0) | ||||||||
if not has_comment: | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe this simplifies to
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for this comment. I'm changing the code and pushing another commit. |
||||||||
return | ||||||||
|
||||||||
is_list_type = isinstance(comment, list) | ||||||||
comment_list = (list(comment) if not is_list_type else comment) | ||||||||
comment_list.sort() | ||||||||
Comment on lines
+530
to
+532
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you explain what's happening here? Is it possible this reorders multiline comments into the wrong order? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As I run the code in tests, there are times the comment came in as an instance of list, sometimes it is not. So to make sure they are all instance of list type, I test it first and ensure that it is a list type whatever the input is, and sort the list according ly. Please run this simple testing code lines:
and load the output file into an editor (ie. vscode) and POEdit to test for python-format errors. |
||||||||
for line in comment_list: | ||||||||
_write('#%s %s\n' % (prefix, line.strip())) | ||||||||
|
||||||||
def _write_message(message, prefix=''): | ||||||||
|
@@ -577,10 +585,8 @@ def _write_message(message, prefix=''): | |||||||
comment_header = u'\n'.join(lines) | ||||||||
_write(comment_header + u'\n') | ||||||||
|
||||||||
for comment in message.user_comments: | ||||||||
_write_comment(comment) | ||||||||
for comment in message.auto_comments: | ||||||||
_write_comment(comment, prefix='.') | ||||||||
_write_comment(message.user_comments) | ||||||||
_write_comment(message.auto_comments) | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we no longer use the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for this observation. I will be making a new commit for the corrected code. |
||||||||
|
||||||||
if not no_location: | ||||||||
locs = [] | ||||||||
|
@@ -602,7 +608,7 @@ def _write_message(message, prefix=''): | |||||||
location = u'%s' % filename.replace(os.sep, '/') | ||||||||
if location not in locs: | ||||||||
locs.append(location) | ||||||||
_write_comment(' '.join(locs), prefix=':') | ||||||||
_write_comment(locs, prefix=':') | ||||||||
if message.flags: | ||||||||
_write('#%s\n' % ', '.join([''] + sorted(message.flags))) | ||||||||
|
||||||||
|
@@ -622,8 +628,7 @@ def _write_message(message, prefix=''): | |||||||
catalog.obsolete.values(), | ||||||||
sort_by=sort_by | ||||||||
): | ||||||||
for comment in message.user_comments: | ||||||||
_write_comment(comment) | ||||||||
_write_comment(message.user_comments) | ||||||||
_write_message(message, prefix='#~ ') | ||||||||
_write('\n') | ||||||||
|
||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The commit message(s) don't seem to explain why these changes are necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please read the original post at
Message.locations duplicate unnecessary #10104
This is an extract of the original message:
By the way, in the past I posted a bug report mentioning the PYTHON_FORMAT problem, in that this re.Pattern causing the problem in recognizing this part "%50 'one letter'" (diouxXeEfFgGcrs%) as an ACCEPTABLE pattern, thus causing the flag "python_format" in the Message class to set, and the Catalog.dump_po will insert a "#, python-format" in the comment section of the message, causing applications such as PoEdit to flag up as a WRONG format for "python-format". The trick is to insert a look behind clause in the PYTHON_FORMAT pattern, as an example here:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After all the above comments, and as you finished your preview, could you please give me a approval as what other changes I should make, before I make another push to the pull request branch. Thank you.