This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
print('Hello World!') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Make imports | |
import time | |
import clipboard | |
from selenium import webdriver | |
# Define text to translate | |
text_to_translate = 'This is a translation example for my article.' | |
# Start a Selenium driver | |
driver_path='../chromedriver' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Importing our previous translation function | |
from run_translation import translate_sentence | |
# Sentences input | |
sentence1 = 'I want to translate a first sentence without any link to the second one.' | |
sentence2 = 'The starlings ate all the cherries in one afternoon, there won\'t be any more for us.'' | |
# Creation of the corpus as a list of strings | |
corpus = [sentence1, sentence2] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def prepare_batch_corpus(corpus, max_caracter=5000): | |
# Size information | |
nb_sentence = len(corpus) | |
# Batch information (reset these values after each batch finalization) | |
batch = [] | |
batch_length = 0 | |
# All batches are stored in that list, which will bbe the output of the function |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Making necessary imports | |
import clipboard | |
from selenium.webdriver.common.keys import Keys | |
# Identifying the text area in the html structure | |
input_css = 'div.lmt__inner_textarea_container textarea' | |
# Connecting to it with our driver | |
input_area = driver.find_element_by_css_selector(input_css) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Getting button location on the html tree | |
button_css = ' div.lmt__target_toolbar__copy button' | |
# Getting the button object | |
button = driver.find_element_by_css_selector(button_css) | |
# Extracting its position | |
y = button.location['y'] | |
# Positionning the button into the screen |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pptx import Presentation | |
def get_texts_from_file(input_file): | |
# Instantiate variable to store the texts | |
texts = [] | |
# Load the presentation | |
prs = Presentation(input_file) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# parameters | |
input_file = 'original.pptx' | |
output_file = 'translated.pptx' | |
# Opening presentation | |
prs = Presentation(input_file) | |
# List of all texts [text1, text2, ....] | |
corpus = extract_text_frames_from(prs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# For each paragraph of each text_frame | |
for text_frame in all_presentation_text_frames: | |
for paragraph in text_frame.paragraphs: | |
# We get the translated text | |
old_text = text_frame.paragraphs[idx].text | |
new_text = corpus_translated[old_text] | |
# And inspect the runs (for font analysis) | |
if len(paragraph.runs)>0: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# For each paragraph of each text_frame | |
for text_frame in all_presentation_text_frames: | |
for paragraph in text_frame.paragraphs: | |
# We get the translated text | |
old_text = text_frame.paragraphs[idx].text | |
new_text = corpus_translated[old_text] | |
# And inspect the runs (for font analysis) | |
if len(paragraph.runs)>0: |
OlderNewer