/** * @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-11-15 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."]]],[]]