diff options
author | Philip Chimento <philip@endlessm.com> | 2015-06-04 14:14:32 -0700 |
---|---|---|
committer | Philip Chimento <philip@endlessm.com> | 2015-06-04 14:28:19 -0700 |
commit | 6e767f6c2a4953c3469a4e49ff247d9e472a8c4e (patch) | |
tree | 46ce4641e2d6302d2e6962ca528d908424d8e6f7 /tools/eos-html-extractor | |
parent | de707ee95941b63bf0ed3fdbbe206e06ea97475a (diff) |
Fix bug with no comments
eos-html-extractor would crash if it encountered some text comment before
it had encountered a comment.
[endlessm/eos-sdk#3245]
Diffstat (limited to 'tools/eos-html-extractor')
-rwxr-xr-x | tools/eos-html-extractor | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/tools/eos-html-extractor b/tools/eos-html-extractor index 879d048..913695c 100755 --- a/tools/eos-html-extractor +++ b/tools/eos-html-extractor @@ -21,18 +21,21 @@ class TranslatableHTMLParser(HTMLParser): if data not in self._translatable_strings: return - # Determine if comment should be included - most_recent_comment = self._comments_with_line_numbers[-1] - comment_string, comment_line = most_recent_comment code_line = self.getpos()[0] + optional_comment = None - # Comment takes up at least one line by default (hence the +1) - comment_length = len(re.findall(r'\n', comment_string)) + 1 - optional_comment = '' + if self._comments_with_line_numbers: + # Determine if comment should be included + most_recent_comment = self._comments_with_line_numbers[-1] + comment_string, comment_line = most_recent_comment + + # Comment takes up at least one line by default (hence the +1) + comment_length = len(re.findall(r'\n', comment_string)) + 1 + + # If the comment immediately preceded this string, include it + if comment_line + comment_length == code_line: + optional_comment = ' '.join(comment_string.split()) - # If the comment immediately preceded this string, include it - if comment_line + comment_length == code_line: - optional_comment = ' '.join(comment_string.split()) self.all_translatable_data.append((data.strip(), code_line, optional_comment)) def handle_comment(self, comment): @@ -68,6 +71,6 @@ parser.feed(page) # Write out all info about the translatable strings found in this file for string, line_num, optional_comment in parser.all_translatable_data: print('#line {line} "{path}"'.format(line=line_num, path=final_path)) - if optional_comment != '': + if optional_comment: print('// ' + optional_comment) print('_("{string}");'.format(string=string)) |