def get_package_name(project_path): app_dir = os.path.join(project_path, 'app') android_manifest_file = fh.search_file(app_dir, 'AndroidManifest.xml')[0] android_manifest_file_xml = xh.read_xml_file(android_manifest_file) root_node = xh.get_root_node(android_manifest_file_xml) package_name = xh.get_node_att(root_node, 'package') return package_name
def build_strings_dict(strings_file_path): strings_xml = xh.read_xml_file(strings_file_path) strings_node = xh.find_all_nodes(xh.get_root_node(strings_xml), 'string') nodes_to_translate = [] for node in strings_node: translatable_val = xh.get_node_att(node, 'translatable') if translatable_val is None or translatable_val == "true": nodes_to_translate.append(node) return nodes_to_translate
def add_extension_nodes(xml_path, place_holder_map, root_node, xml): extension_mapper_path = xh.get_node_att( root_node, res.NODE_ROOT_ATT_EXTENSION_MAPPER_PATH) if extension_mapper_path: extension_mapper_path = tools.rel_path_to_abs(extension_mapper_path, xml_path) extension_mapper_path = fill_place_holders(extension_mapper_path, place_holder_map) extension_xml = xh.read_xml_file(extension_mapper_path) return xh.merge_xml1_with_xml2(extension_xml, xml) else: return xml
def dict_to_xlsx(string_nodes, output_path, src_language, languages_arr): import xlsxwriter # Create an new Excel file and add a worksheet. workbook = xlsxwriter.Workbook(output_path) big_red_format = workbook.add_format() title_format = workbook.add_format() content_format = workbook.add_format() border_format = workbook.add_format() big_red_format.set_font_color('red') big_red_format.set_font_size(16) title_format.set_font_size(22) content_format.set_font_size(12) content_format.set_font('Arial') big_red_format.set_align('center') border_format.set_top() # set the border for language in languages_arr: worksheet = workbook.add_worksheet(language) # widen all of the columns used worksheet.set_column('A:A', 50, cell_format=content_format) worksheet.set_column('B:B', 50, cell_format=content_format) worksheet.set_column('C:C', 50, cell_format=content_format) worksheet.set_column('F:F', 50, cell_format=content_format) # set headers worksheet.write('A1', 'Translation Project', title_format) worksheet.write('A3', src_language, big_red_format) worksheet.write('B3', language, big_red_format) worksheet.write('F3', 'Code (DO NOT CHANGE)', big_red_format) # set strings for i in range(len(string_nodes)): node = string_nodes[i] node_id = xh.get_node_att(node, 'name') node_value = xh.get_text_from_node(node) worksheet.write('A' + str(i + 4), node_value) worksheet.write('F' + str(i + 4), node_id) workbook.close()
def get_file_node_path(xml_path, place_holder_map, file_node, node_name, previous_found_path=None, file_search=True): file_node = xh.get_child_nodes(file_node, node_name)[0] file_type = xh.get_node_att(file_node, res.PATH_TYPE) if file_type == res.PATH_TYPE_AS_SRC: output_file_path = previous_found_path elif file_type == res.PATH_TYPE_SEARCH: output_file_path = find_search_path(place_holder_map, file_node, file_search) else: output_file_path = find_normal_path(place_holder_map, file_node) # fix paths if required return tools.rel_path_to_abs(output_file_path, xml_path)
def manipulate(xml_path, xml, place_holder_map): file_nodes = xh.get_all_direct_child_nodes(xh.get_root_node(xml)) # run on all of the root's direct children for file_node in file_nodes: # get the action action = xh.get_node_att(file_node, shared_res.ACTION) # if copy, do copy if action == res.NODE_FILE_ATT_ACTION_VAL_COPY: src_path = get_file_or_dir_src_path(xml_path, place_holder_map, file_node) dst_path = get_dst_path(xml_path, place_holder_map, file_node, src_path) copy_file_or_dir(src_path, dst_path) # if delete, do delete elif action == res.NODE_FILE_ATT_ACTION_VAL_DELETE: to_delete_files = get_files_or_dirs_src_paths( xml_path, place_holder_map, file_node) delete_files_or_dirs(to_delete_files)