Notes![what is notes.io? What is notes.io?](/theme/images/whatisnotesio.png)
![]() ![]() Notes - notes.io |
from bs4 import BeautifulSoup as BS
from bs4.element import NavigableString
import copy
import numpy as np
import pandas as pd
excel_translated = 'output2.xlsx'
with open('Esp-ptnl-tta-tool-digital-introduction-to-the-topic.xlf', 'r', encoding='UTF-8') as f:
src = f.read()
text ='''<?xml version="1.0" encoding="UTF-8"?><xliff xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 http://docs.oasis-open.org/xliff/v1.2/os/xliff-core-1.2-strict.xsd" version="1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xhtml="http://www.w3.org/1999/xhtml">
<file original="course" datatype="plaintext" source-language="en-US">
<body>
<trans-unit id="title">
<source>ESP_ PTNL - TTA - Tool digital introduction to the topic</source>
</trans-unit>
<trans-unit id="description">
<source><g id="2qK4TYpZjghj-o_R" ctype="x-html-P">Welcome to the eLearning "PTNL- TTA - Tool" digital introduction to the topic.<g id="U1xo6JgaChkpZ2-4" ctype="x-html-BR" />You will get an introduction to the TTA-Tool. The different masks in the tool are described step by step and how to use them in real life. This should enable you to recognize and analyze customer potential. Furthermore, it is also explained how you can plan and document their next visits.</g>
</source>
</trans-unit>
</body>
</file>'''
# conversions = {
# 'ESP_ PTNL - TTA - Tool digital introduction to the topic': 'ESP_ PTNL - TTA - Tool digital introduction to the topic-copy'
# }
df = pd.read_excel(excel_translated) # Translated Excel
col1 = df['Text'].astype(str)
col2 = df['Text_copy'].astype(str)
# print(col1)
# print(col2)
conversions = dict(zip(col1, col2))
# print(conversions)
# soup = BS(text, 'lxml')
soup = BS(src, 'lxml')
# print(soup)
all_source = soup.findAll('source')
for source in all_source:
# create `<target>`
target = soup.new_tag('target')
# add `<target>` after `<source>
# source = soup.find('source')
source.insert_after('', target)
# work with children in `<source>`
for child in source:
# print(child)
# print('type:', type(child))
# duplicate child and add to `<target>`
if child == 'n':
continue
child = copy.copy(child)
target.append(child)
# convert text and replace in child in `<target>`
if isinstance(child, NavigableString):
new_text = conversions[child.string]
print(new_text)
child.string.replace_with(new_text)
else:
# next_child = target.next_elements
next_child = target.next
print("Next child is", next_child)
for nc in next_child:
if nc != "n" and nc.string is not None:
# print("String #:", nc.string)
# print("Next child is", nc.string)
new_text = conversions[nc.string]
# print("Translated string is:", new_text)
# print(new_text)
# print("nc is:", nc)
nc.string.replace_with(new_text)
# print("String is replaced")
# print("After replacement:", nc.string)
# print(child.string)
# print("Value is not found!")
# print('--- target ---')
# print(target)
# print('--- source ---')
# print(source)
# print('--- soup ---')
print(soup)
# with open('output.xlf', 'w', encoding='UTF-8') as f:
# f.write(soup)
![]() |
Notes is a web-based application for online 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 14 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