Skip to content

Commit

Permalink
Merge pull request #6761 from brave/maxk-fix-transifex-formatting
Browse files Browse the repository at this point in the history
Fixes bad formatting in transifex.py.
  • Loading branch information
mkarolin committed Oct 8, 2020
1 parent 049a18d commit 0ad4061
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions script/lib/transifex.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def validate_tags_in_one_string(string_tag):
string_text = textify_from_transifex(string_tag)
string_text = (string_text.replace('&lt;', '<')
.replace('&gt;', '>'))
#print 'Validating: {}'.format(string_text.encode('utf-8'))
# print 'Validating: {}'.format(string_text.encode('utf-8'))
try:
string_xml = lxml.etree.fromstring('<string>' + string_text + '</string>')
except lxml.etree.XMLSyntaxError as e:
Expand All @@ -214,16 +214,18 @@ def validate_tags_in_one_string(string_tag):
errors = validate_elements_tags(list(string_xml))
if errors is not None:
errors = ("--------------------\n"
"{0}\n").format(lxml.etree.tostring(string_tag,
method='xml', encoding='utf-8', pretty_print=True)) + errors
"{0}\n").format(
lxml.etree.tostring(
string_tag, method='xml', encoding='utf-8', pretty_print=True)
) + errors
return errors


def validate_tags_in_transifex_strings(xml_content):
"""Validates that all child elements of all <string>s are allowed"""
xml = lxml.etree.fromstring(xml_content)
string_tags = xml.findall('.//string')
#print 'Validating HTML tags in {} strings'.format(len(string_tags))
# print 'Validating HTML tags in {} strings'.format(len(string_tags))
errors = None
for string_tag in string_tags:
error = validate_tags_in_one_string(string_tag)
Expand Down Expand Up @@ -495,7 +497,7 @@ def is_translateable_string(grd_file_path, message_tag):
return False


def get_grd_strings(grd_file_path, validate_tags = True):
def get_grd_strings(grd_file_path, validate_tags=True):
"""Obtains a tubple of (name, value, FP) for each string in a GRD file"""
strings = []
# Keep track of duplicate mesasge_names
Expand Down Expand Up @@ -906,8 +908,8 @@ def pull_xtb_without_transifex(grd_file_path, brave_source_root):
chromium_grd_base_path = os.path.dirname(chromium_grd_file_path)

# Update XTB FPs so it uses the branded source string
grd_strings = get_grd_strings(grd_file_path, validate_tags = False)
chromium_grd_strings = get_grd_strings(chromium_grd_file_path, validate_tags = False)
grd_strings = get_grd_strings(grd_file_path, validate_tags=False)
chromium_grd_strings = get_grd_strings(chromium_grd_file_path, validate_tags=False)
assert(len(grd_strings) == len(chromium_grd_strings))

fp_map = {chromium_grd_strings[idx][2]: grd_strings[idx][2] for
Expand Down

0 comments on commit 0ad4061

Please sign in to comment.