Reputation: 181
I created a Google Apps Script on the Google account, which had the Polish language set in the settings. Executing the script was causing some Google error message about exceeding quote Gmail rateMax, which was displayed in Polish.
I shared this script with another account, where language was set to English in account settings. To my surprise, executing the script on the account where language was set to English, caused the error message to still appear in Polish.
Question: how can I change the 'locale' of the Google Apps Script? Is it even possible?
Or is the only option to create new script on the account with English locale, and copy over the code?
Upvotes: 10
Views: 8044
Reputation: 38296
The Google Apps Script project uses the active user locale. If you want that the error messages be shown in a different locale, change the active user language to the one that you want to use (very easy if it's your own account, very difficult if the account belongs to someone else)
Demonstration
Running the following script in a stand-along project using accounts in different languages will log:
function myFunction() {
console.info(Session.getActiveUserLocale());
try{
SpreadsheetApp.getUi().alert('Hello world!');
} catch (e){
console.error(e.message);
}
}
The following screen shot shows the messages logged (from top to bottom) first when the script was ran by an account using Spanish - Mexico, second using English
Spanish - Mexico
Jun 19, 2020, 3:34:07 PM Info es_419
Jun 19, 2020, 3:34:07 PM Error No se puede usar SpreadsheetApp.getUi() desde este contexto.
English
Jun 19, 2020, 3:33:18 PM Info en
Jun 19, 2020, 3:33:18 PM Error Cannot call SpreadsheetApp.getUi() from this context.
Upvotes: 0
Reputation: 1512
If you created the script from within a spreadsheet -- by selecting Tools --> Script Editor
within the Sheets UI, then executing setSpreadsheetLocale()
on the spreadsheet should apply your locale setting to the script, too.
If you created the script as a new document from Drive, then your suspicion appears to be correct -- there is no user-visible locale setting for a Script Document, so you'll have to create the script with an English-locale account.
You can refer to the official documentation for more info.
Upvotes: 5