How do I get the language of the Slides? - javascript

In Google Sheets I can get the language of the spreadsheet by SpreadsheetApp.getActiveSpreadsheet().getSpreadsheetLocale()
What is the equivalent way in Google Slides Script?

You want to retrieve the locale of Google Slides.
You want to achieve this using Google Apps Script.
If my understanding is correct, how about this answer? Please think of this as just one of several possible answers.
Issue and workaround:
Unfortunately, it seems that there are no built-in methods for retrieving the locate of Google Slides in Slides service. So in this case, as a workaround, how about using Slides API? When the Slides API is used, the locale can be retrieved.
It seems that the value retrieved by Slides API is different from getSpreadsheetLocale(). In my environment, getSpreadsheetLocale() returns ja_JP. The value of locale retrieved by Slides API is ja. Please be careful this. The official document says as follows.
locale: The locale of the presentation, as an IETF BCP 47 language tag.
Sample script:
When you use this script, please enable Slides API at Advanced Google services.
var presentationId = "###"; // Please set the Slides ID.
var locale = Slides.Presentations.get(presentationId).locale;
Logger.log(locale)
References:
getSpreadsheetLocale()
Advanced Google services
REST Resource: presentations
Method: presentations.get
If I misunderstood your question and this was not the direction you want, I apologize.

Related

How to import dynamic Javascript element from a website to Google Sheets

I am trying to import a current price from a website that utilizes JavaScript to dynamically update the price of a crypto coin using the =ImportXML function in google sheets. Below is what I have tried but obviously it is not correct. Any ideas on how to pull a price of a coin from the URL mentioned below?
This method works with other websites that dont automatically update the price live on scree but it seems being a dynamic field does not allow this method to work.
=IMPORTXML(F3,"//div[#class='mb-1 d-flex flex-column lh-1']")
F3=https://poocoin.app/tokens/0x864397b060a2210e9ded2e9a8d63cd7a83eb0ef0
Would advise using a proper API to get the coins prices.
Websites are not meant for bot consumption, they can change at any moment and force you to re implement everything again.
You could try this endpoint instead albeit it might be missing smaller/poop coins? =IMPORTDATA("https://cryptoprices.cc/BTC/")
CoinGecko also has a good API which you could try using with only slightly more effort
=importJSON("https://api.coingecko.com/api/v3/coins/markets?vs_currency=usd&ids=bitcoin","0.current_price")
You might be having problems because the url you're querying is behind a DDos protector

Google sheets API: How to retrieve the A1 notation of an active range with javascript

I'm actually working on a web project based on Google Spreadsheet, and following the Browser quickstart method (https://developers.google.com/sheets/api/quickstart/js).
I would like to select a range on my sheet, and click on a button.
I would have a function that detect the active range's A1 notation, then stores it in a variable and display it in an input range.
Many people that are using the script editor are talkig about a "getActiveRange" function. But this function is only accessible when using the script editor, and not from my js file.
Is there another way to get the A1 notation of my selected range?
Using Sheets API, what you're asking isn't straight up available. Like what you've mentioned, this is somewhat doable using App Script's getActiveRange() but for Sheets APIv4, there's no ad-hoc to do that. The only supported methods in Sheets API v4 is found in the official reference.
You should be able to select a Range with the spreadsheets.values.get Method, take a look here:
https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values/get
Does that help you?

Using google script to manipulate data conditional formating and data validation

I was looking for already 3 days but nowhere found how to manipulate those two tools by google script.
I am interested in maiking script runned dynamic creation of worksheets and fast edditing of worksheets.
I need to alter those: data validation and conditional formating which are available normaly on tool bar.
Please help, give me the name of class that consists of those or the functions in google script with little information I will find rest.
Thanks in adavance
Tom
Data validation can be set using Range.setDataValidation(). Unfortunately Apps Script doesn't support setting conditional formatting, but you can star this feature request to get notified if/when it's added.
The tools you are asking about appear to be in the Range class of the Google Apps Script Spreadsheet API. Note that the API calls deal with a range of cells at a time, although you can easily define a range that contains only one cell.
The question in its current form has nothing to do with Google App Engine, so consider taking that off the question tags.

How to Show Different Products Depending on Google Translate Widget Language Chosen

I am developing a website with shopping cart that will have different products per country. Customer wants to use Google Translate to change language.
We thought one website with different product categories for each country would be best. So someone in France chooses FR in Google Translate, and we have some code to show the FR product category.
But I cant find how to determine in my website code (PHP) what language is chosen by the Google Translate Widget. The URL stays the same, so I cannot query the URL.
How would one be able to determine at the server level (PHP) what language has been chosen by the Google Translate Widget?
I wonder if this is even possible as its probably using Javascript to change it, so would there be other ways to tap into the Google Translate Widget so I could use Javascript to show the correct product category?
This is the Google Widget Code
<script type="text/javascript">
function googleTranslateElementInit()
{
new google.translate.TranslateElement(
{
pageLanguage: 'en',
includedLanguages: 'en,cy',
layout: google.translate.TranslateElement.InlineLayout.SIMPLE
},
'google_translate_element');
}
</script>
<script type="text/javascript" src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>
Thanks
This is one way, but not ideal due to horrible hashes in the URL...
Google can auto translate the page content if you add #googtrans(en|TARGET_LANG_CODE) to the end of the URL, e.g. www.mydomain.com#googtrans(en|fr)
So setup a multi-country site like standard, e.g. /fr, /de etc. (sub-domains could be used or anything in the URL to specify what country, e.g. ?country=fr).
Using links to each country section of the site, link to the country section with the hash on the end, e.g. www.mydomain.com/fr#googtrans(en|fr) or fr.mydomain.com#googtrans(en|fr) or www.mydomain.com?country=fr#googtrans(en|fr)
The country section in the URL, e.g. /fr allows you to show the correct store for that country (and anything else you want to display for that country, perhaps call different images as Google cant translate those), and then the hash allows Google to translate it to the correct language.
Its a horrible hash to use! Be good if we could not use the hash and just translate based on just /fr (probably can do this using the non-free API but this is just for the free widget).
Note: Its probably necessary to exclude the country sections e.g. /fr from being indexed in Google, because I would hazard a guess Google may see the original language content on these sub-sections before its JS translation kicks in, so we would not want that duplicate content. I do not believe Google indexes the widget translated pages, so just disallow these sections in the robots.txt file.

Is there a way to add a Javascript-based Signature Pad to a Google Form to capture a responder's signature?

Is there a way to add in Thomas Bradley's Signature Pad plugin so that someone who is filling out the Google Form would be able to sign the form? Would it be possible to use the HTML Service option to create a custom HTML form web app that can then still upload the responses into a Google Spreadsheet?
The project I've been asked to look into involves an individual being able to fill out a form but they would also like to be able to capture a signature (essentially a web form replacing paper forms) and they would like to do it all with Google since it is their preferred service. They also prefer to use Google Spreadsheets.
I'm very new to Google App Scripts and have a beginner's understanding of Javascript so I may very well misunderstand the uses and potential of Google App Scripts. Any help or advice is much appreciated.
patt0 is right. Here is a working example...
I've added a jQuery signature pad plugin to a Google spreadsheet using Google's HTML Service. (http://willowsystems.github.io/jSignature/#/about/)
The following example shows a signature pad on a Google Spreadsheet and converts the drawn signature to Base64 vector (image/jSignature;base30) data.
Here is my code.gs :
var ss = SpreadsheetApp.getActive();
function openDialog() {
var html = HtmlService.createHtmlOutputFromFile('index');
ss.show(html);
}
and here is index.html - - (link in your own Jsignature.js):
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<script src="jSignature.js></script>
<script>
$(document).ready(function() {
$("#signature1").jSignature();
});
</script>
<div id="signature1"></div>
<button type="button" onclick="$('#signature1').jSignature('clear')">Clear</button>
<button type="button" onclick="alert($('#signature1').jSignature('getData','base30'))">Export</button>
As far as I can see, adding the plugin to a Google Form directly will not be possible.
Using HTML Service is a good idea and yes indeed it will be possible to get the the data from the form and push it to a spreadsheet, which then can trigger other workflow parts.
The only potential red flag is to find out wether the dependencies for the plugin are compatible HTML Service (https://developers.google.com/apps-script/guides/html-service-caja).
Let me know if you need more direction.

Categories