-
Notifications
You must be signed in to change notification settings - Fork 448
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 all 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 |
---|---|---|
|
@@ -275,7 +275,7 @@ def _process_comment(self, line): | |
continue | ||
self.locations.append((location[:pos], lineno)) | ||
else: | ||
self.locations.append((location, None)) | ||
self.locations.append((location, None)) | ||
elif line[1:].startswith(','): | ||
for flag in line[2:].lstrip().split(','): | ||
self.flags.append(flag.strip()) | ||
|
@@ -522,13 +522,15 @@ def _write(text): | |
fileobj.write(text) | ||
|
||
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): | ||
# 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 | ||
if not comment: | ||
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 +579,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, prefix='.') | ||
|
||
if not no_location: | ||
locs = [] | ||
|
@@ -602,7 +602,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 +622,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.