NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

from bs4 import BeautifulSoup as BS
from bs4.element import NavigableString
import copy
import re
import numpy as np
import pandas as pd
from lxml import etree


filename = "123.xlf"
excel_translated = 'translated.xlsx'

with open(filename, 'r', encoding='UTF-8') as f:
src = f.read()

df = pd.read_excel(excel_translated) # Translated Excel
col1 = df['Text'].astype(str)
col2 = df['Text-Copy'].astype(str)
# print(col1)
# print(col2)

# Create dictionary-----------
translation_dict = dict(zip(col1, col2))
print(str(translation_dict))

src_start = "<source"
src_end = "</source>"
start_ind = [i.start() for i in re.finditer(src_start, src)]
end_ind = [i.start() for i in re.finditer(src_end, src)]

offset = 0

for i in range(len(start_ind)):
sub_str = src[start_ind[i]+offset:end_ind[i]+len(src_end)+offset]
offset = offset + len(sub_str)
sub_str = sub_str.replace('<source', '<target')
sub_str = sub_str.replace('</source>', '</target>')
# Append the <target> block
src = src[:start_ind[i]+offset] + sub_str + src[start_ind[i]+offset:]
# src_blocks.append(sub_str)
# print(src)
# print("Block #%s::n" %(i+1), src_blocks[i])
# print(src)

tag_list = ['g']
soup = BS(src, 'lxml')
tags = {tag.name for tag in soup.find_all()}
for tag in tags:
if tag == 'g':
for ele in soup.find_all(tag):
# print(ele.text)
g_text = ele.text

new_txt = translation_dict[g_text]
# start_ind = [i.start() for i in re.finditer(g_text, src)]

# tag.string = new_txt


with open('duplicate.xlf', 'w', encoding='UTF-8') as f:
f.write(src)

tree = etree.parse('duplicate.xlf')
root = tree.getroot()


for element in root:
pass # not important
# now the children
for all_tags in element.findall('.//'):
if 'target' in all_tags.tag:
if all_tags.text is not None:
tgt_text = all_tags.text
new_text = translation_dict[tgt_text]
all_tags.text = new_text
# print(src)
tree.write('duplicate_v1.xlf')
# with open('output.xlf', 'w', encoding='UTF-8') as f:
# f.write(src)
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.