/** * @OnlyCurrentDoc Limits the script to only accessing the current presentation. *//** * Create a open translate menu item. * @param {Event} event The open event. */functiononOpen(event){SlidesApp.getUi().createAddonMenu().addItem("Open Translate","showSidebar").addToUi();}/** * Open the Add-on upon install. * @param {Event} event The install event. */functiononInstall(event){onOpen(event);}/** * Opens a sidebar in the document containing the add-on's user interface. */functionshowSidebar(){constui=HtmlService.createHtmlOutputFromFile("sidebar").setTitle("Translate");SlidesApp.getUi().showSidebar(ui);}/** * Recursively gets child text elements a list of elements. * @param {PageElement[]} elements The elements to get text from. * @return {Text[]} An array of text elements. */functiongetElementTexts(elements){lettexts=[];for(constelementofelements){switch(element.getPageElementType()){caseSlidesApp.PageElementType.GROUP:for(constchildofelement.asGroup().getChildren()){texts=texts.concat(getElementTexts(child));}break;caseSlidesApp.PageElementType.TABLE:{consttable=element.asTable();for(letr=0;r < table.getNumRows();++r){for(letc=0;c < table.getNumColumns();++c){texts.push(table.getCell(r,c).getText());}}break;}caseSlidesApp.PageElementType.SHAPE:texts.push(element.asShape().getText());break;}}returntexts;}/** * Translates selected slide elements to the target language using Apps Script's Language service. * * @param {string} targetLanguage The two-letter short form for the target language. (ISO 639-1) * @return {number} The number of elements translated. */functiontranslateSelectedElements(targetLanguage){// Get selected elements.constselection=SlidesApp.getActivePresentation().getSelection();constselectionType=selection.getSelectionType();lettexts=[];switch(selectionType){caseSlidesApp.SelectionType.PAGE:for(constpageofselection.getPageRange().getPages()){texts=texts.concat(getElementTexts(page.getPageElements()));}break;caseSlidesApp.SelectionType.PAGE_ELEMENT:{constpageElements=selection.getPageElementRange().getPageElements();texts=texts.concat(getElementTexts(pageElements));break;}caseSlidesApp.SelectionType.TABLE_CELL:for(constcellofselection.getTableCellRange().getTableCells()){texts.push(cell.getText());}break;caseSlidesApp.SelectionType.TEXT:for(constelementofselection.getPageElementRange().getPageElements()){texts.push(element.asShape().getText());}break;}// Translate all elements in-place.for(consttextoftexts){text.setText(LanguageApp.translate(text.asRenderedString(),"",targetLanguage),);}returntexts.length;}
[[["Łatwo zrozumieć","easyToUnderstand","thumb-up"],["Rozwiązało to mój problem","solvedMyProblem","thumb-up"],["Inne","otherUp","thumb-up"]],[["Brak potrzebnych mi informacji","missingTheInformationINeed","thumb-down"],["Zbyt skomplikowane / zbyt wiele czynności do wykonania","tooComplicatedTooManySteps","thumb-down"],["Nieaktualne treści","outOfDate","thumb-down"],["Problem z tłumaczeniem","translationIssue","thumb-down"],["Problem z przykładami/kodem","samplesCodeIssue","thumb-down"],["Inne","otherDown","thumb-down"]],["Ostatnia aktualizacja: 2025-11-28 UTC."],[],["This document outlines how to create a Google Slides add-on that translates selected text. Key steps include: creating a new Slides presentation and an Apps Script project named \"Translate Slides,\" renaming the default code file to \"translate\", adding a file named \"sidebar\" and replacing the content of these files with the specified code. The script creates a menu to \"Open Translate\", which shows a sidebar with language options, allowing users to select text in the presentation and click \"Translate\" to change it into the chosen language.\n"]]