/** * @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('OpenTranslate','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=[];elements.forEach((element)=>{switch(element.getPageElementType()){caseSlidesApp.PageElementType.GROUP:element.asGroup().getChildren().forEach((child)=>{texts=texts.concat(getElementTexts(child));});break;caseSlidesApp.PageElementType.TABLE:consttable=element.asTable();for(lety=0;y < table.getNumColumns();++y){for(letx=0;x < table.getNumRows();++x){texts.push(table.getCell(x,y).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:selection.getPageRange().getPages().forEach((page)=>{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:selection.getTableCellRange().getTableCells().forEach((cell)=>{texts.push(cell.getText());});break;caseSlidesApp.SelectionType.TEXT:selection.getPageElementRange().getPageElements().forEach((element)=>{texts.push(element.asShape().getText());});break;}// Translate all elements in-place.texts.forEach((text)=>{text.setText(LanguageApp.translate(text.asRenderedString(),'',targetLanguage));});returntexts.length;}
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["필요한 정보가 없음","missingTheInformationINeed","thumb-down"],["너무 복잡함/단계 수가 너무 많음","tooComplicatedTooManySteps","thumb-down"],["오래됨","outOfDate","thumb-down"],["번역 문제","translationIssue","thumb-down"],["샘플/코드 문제","samplesCodeIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2024-12-22(UTC)"],[[["This quickstart guide details how to build a Google Slides add-on using Apps Script to translate selected presentation text."],["The add-on allows users to select text within their Google Slides presentation and translate it into various languages such as Arabic, Chinese, English, French, German, Hindi, Japanese, Portuguese, and Spanish."],["To utilize this add-on, users need a Google Account, a web browser, and must follow setup instructions which include creating a Slides presentation, enabling Apps Script, and pasting provided code into designated script files."],["Users can run the add-on by reloading their Slides presentation, authorizing the add-on, and selecting the text they wish to translate before clicking the \"Translate\" button in the add-on sidebar."]]],[]]