-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor code and fix conflict with XML declaration (#505)
- Loading branch information
Showing
6 changed files
with
32 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from lxml import etree | ||
|
||
|
||
def write_xliff(root, filename): | ||
with open(filename, "w+") as fp: | ||
# Fix identation of XML file | ||
etree.indent(root) | ||
""" | ||
Hack to avoid conflicts with Pontoon, which uses single quotes | ||
for the XML declaration: | ||
1. Exclude the XML declaration when using etree.tostring() | ||
2. Manually add the declaration with double quotes | ||
""" | ||
xliff_content = etree.tostring( | ||
root, | ||
encoding="UTF-8", | ||
xml_declaration=False, | ||
pretty_print=True, | ||
) | ||
xliff_content = ( | ||
'<?xml version="1.0" encoding="UTF-8"?>\n' + xliff_content.decode("utf-8") | ||
) | ||
fp.write(xliff_content) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.pyc |