def generate_overrides_and_replace_strings(source_string_path): fix_links_with_target_blank(source_string_path) original_xml_tree_with_branding_fixes = etree.parse(source_string_path) update_braveified_grd_tree_override(original_xml_tree_with_branding_fixes, True) write_braveified_grd_override(source_string_path) modified_xml_tree = etree.parse(source_string_path) original_messages = original_xml_tree_with_branding_fixes.xpath( '//message') modified_messages = modified_xml_tree.xpath('//message') assert len(original_messages) == len(modified_messages) for i in range(0, len(original_messages)): if textify(original_messages[i]) == textify(modified_messages[i]): modified_messages[i].getparent().remove(modified_messages[i]) # Remove uneeded things from the override grds nodes_to_remove = [ '//outputs', '//comment()', ] for xpath_expr in nodes_to_remove: nodes = modified_xml_tree.xpath(xpath_expr) for n in nodes: if n.getparent() is not None: n.getparent().remove(n) parts = modified_xml_tree.xpath('//part') for part in parts: override_file = get_override_file_path(part.attrib['file']) # Check for the special case of brave_stings.grd: if (os.path.basename(source_string_path) == 'brave_strings.grd' and override_file == 'settings_chromium_strings_override.grdp'): override_file = 'settings_brave_strings_override.grdp' if os.path.exists( os.path.join(os.path.dirname(source_string_path), override_file)): part.attrib['file'] = override_file else: # No grdp override here, carry on part.getparent().remove(part) files = modified_xml_tree.xpath('//file') for f in files: f.attrib['path'] = get_override_file_path(f.attrib['path']) # Write out an override file that is a duplicate of the original file but with strings that # are shared with Chrome stripped out. filename = os.path.basename(source_string_path) (basename, ext) = filename.split('.') override_string_path = get_override_file_path(source_string_path) modified_messages = modified_xml_tree.xpath('//message') modified_parts = modified_xml_tree.xpath('//part') if len(modified_messages) > 0 or len(modified_parts) > 0: write_xml_file_from_tree(override_string_path, modified_xml_tree)
def main(): args = parse_args() check_args() source_string_path = os.path.join(BRAVE_SOURCE_ROOT, args.source_string_path[0]) filename = os.path.basename(source_string_path).split('.')[0] if not should_use_transifex(source_string_path, filename): source_string_path = get_override_file_path(source_string_path) filename = os.path.basename(source_string_path).split('.')[0] # This check is needed because some files that we process have no replacements needed # so in that case we don't even put an override file in Transifex. if not os.path.exists(source_string_path): print 'Skipping locally handled because not present: ', source_string_path, 'filename: ', filename return print 'Handled locally, sending only overrides to Transifex: ', source_string_path, 'filename: ', filename upload_source_files_to_transifex(source_string_path, filename) return print '[transifex]: ', source_string_path upload_source_files_to_transifex(source_string_path, filename) ext = os.path.splitext(source_string_path)[1] if ext == '.grd': check_for_chromium_upgrade(SOURCE_ROOT, source_string_path) check_missing_source_grd_strings_to_transifex(source_string_path) upload_source_strings_desc(source_string_path, filename) if 'ethereum-remote-client' in source_string_path: upload_missing_json_translations_to_transifex(source_string_path)
def combine_override_xtb_into_original(source_string_path): source_base_path = os.path.dirname(source_string_path) override_path = get_override_file_path(source_string_path) override_base_path = os.path.dirname(override_path) xtb_files = get_xtb_files(source_string_path) override_xtb_files = get_xtb_files(override_path) assert len(xtb_files) == len(override_xtb_files) for (idx, _) in enumerate(xtb_files): (lang, xtb_path) = xtb_files[idx] (override_lang, override_xtb_path) = override_xtb_files[idx] assert lang == override_lang xtb_tree = lxml.etree.parse(os.path.join(source_base_path, xtb_path)) override_xtb_tree = lxml.etree.parse( os.path.join(override_base_path, override_xtb_path)) translationbundle = xtb_tree.xpath('//translationbundle')[0] override_translations = override_xtb_tree.xpath('//translation') translations = xtb_tree.xpath('//translation') override_translation_fps = [ t.attrib['id'] for t in override_translations ] translation_fps = [t.attrib['id'] for t in translations] # Remove translations that we have a matching FP for for translation in xtb_tree.xpath('//translation'): if translation.attrib['id'] in override_translation_fps: translation.getparent().remove(translation) elif translation_fps.count(translation.attrib['id']) > 1: translation.getparent().remove(translation) translation_fps.remove(translation.attrib['id']) # Append the override translations into the original translation bundle for translation in override_translations: translationbundle.append(translation) xtb_content = ('<?xml version="1.0" ?>\n' + lxml.etree.tostring(xtb_tree, pretty_print=True, xml_declaration=False, encoding='UTF-8').strip()) with open(os.path.join(source_base_path, xtb_path), mode='w') as f: f.write(xtb_content)
def main(): args = parse_args() check_args() source_string_path = os.path.join(BRAVE_SOURCE_ROOT, args.source_string_path[0]) filename = os.path.basename(source_string_path).split('.')[0] if should_use_transifex(source_string_path, filename): print('Transifex: ', source_string_path) pull_source_files_from_transifex(source_string_path, filename) else: print('Local: ', source_string_path) override_path = get_override_file_path(source_string_path) print('Transifex override: ', override_path) override_filename = os.path.basename(override_path).split('.')[0] override_exists = os.path.exists(override_path) if override_exists: pull_source_files_from_transifex(override_path, override_filename) pull_xtb_without_transifex(source_string_path, BRAVE_SOURCE_ROOT) if override_exists: combine_override_xtb_into_original(source_string_path)