Google apps scripter
Generate Google Apps scripts to complete tasks based on user requirements.
Sure, here's a Google Apps Script that will translate all text in a Google Slides presentation to Korean using the Google Translate API:
javascript/** * Translates all text in the current Slides presentation to Korean using the Google Translate API. */ function translateSlidesToKorean() { const presentationId = SlidesApp.getActivePresentation().getId(); const requests = []; // Get all slides in the presentation const slides = SlidesApp.getActivePresentation().getSlides(); // Iterate over each slide for (const slide of slides) { // Get all shape elements on the slide const shapes = slide.getShapes(); // Iterate over each shape element for (const shape of shapes) { // Check if the shape has text if (shape.getPlaceholderType() === SlidesApp.PlaceholderType.BODY) { const text = shape.getText().asString(); // Translate the text to Korean const translatedText = LanguageApp.translate(text, 'ko', 'en'); // Create a request to update the shape's text requests.push({ updateTextRequest: { objectId: shape.getObjectId(), text: { text: translatedText }, fields: 'text' } }); } } } // Execute the batch update request Slides.Presentations.batchUpdate({ requests: requests }, presentationId); }
This script uses the SlidesApp
service to get the active Google Slides presentation and iterate over each slide and shape element. If the shape element contains text, it uses the LanguageApp
service to translate the text from English to Korean using the Google Translate API.
After translating the text, it creates a request to update the shape's text with the translated text. All requests are collected and executed in a batch update using the Slides.Presentations.batchUpdate
method.
Note: Make sure to enable the Google Translate API in your Google Cloud Console project and grant the necessary permissions for the script to use the API.
API request
pythonimport anthropic client = anthropic.Anthropic( # defaults to os.environ.get("ANTHROPIC_API_KEY") api_key="my_api_key", ) message = client.messages.create( model="claude-3-opus-20240229", max_tokens=2000, temperature=0, messages=[{"role":"user","content":"Write me a Google apps script that will translate all text in a Google Slides presentation to Korean."}] ) print(message.content)