2

I'm using Session.getActiveUserLocale() to get the user's locale in a Google Calendar Workspace add-on (runtimeVersion: V8) and it works perfectly for every language I've tested - except for Chinese (both simplified and traditional).

function onCalendarHomePageOpen(e) {
Logger.log("Language Code: " + Session.getActiveUserLocale());
}

Should return "zh-CN" when my language is set to Simplified Chinese at https://myaccount.google.com/language, but it returns an empty string.

I know I could use e.commonEventObject.userLocale, but need the locale in lots of places, and would rather not pass it around if possible.

I have the scope https://www.googleapis.com/auth/script.locale and addOns.common.useLocaleFromApp is true, and as I mentioned it works as expected for every other language I've tried including Japanese and Arabic.

Is this a known issue? Can anyone help? Thanks!

Rubén
  • 34,714
  • 9
  • 70
  • 166
jazzwhistle
  • 337
  • 2
  • 12
  • Can you provide some reproduction steps to experiment with on (ideally a [Minimal Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example))? I know it may seem to not be related, but there are some issues relating to the user locale between the old IDE and new IDE, though not sure exactly where you are running it from. [source](https://issuetracker.google.com/179563675) – iansedano May 10 '21 at 07:36
  • The above code was my MRE - here it is with the manifest. When I run the function in the editor it returns zh_CH as you'd expect, but when run as an add-on it logs an empty string. Here's a public link to the MRE, and I can share the add-on with you for testing if you need that to see the logs? https://script.google.com/d/1DE6GYCwUKrt42qbEJcRjF5CLCZUkYpuJ4XdAud53USXHPDkpATVNz4qm/edit?usp=sharing – jazzwhistle May 11 '21 at 11:04

1 Answers1

0

I have filed a bug for this

Session.getActiveUserLocale() not returning values for Chinese, works fine on other languages

Be sure to go and star it to let Google know that it affects you.

Reproduction Steps

  1. Start new Apps Script project.

  2. Paste this code below:

    code.gs

    function onCalendarHomePageOpen(e) {
        Logger.log("Language Code: " + Session.getActiveUserLocale());
    }
    
  3. Replace the manifest with this:

    appscript.json

    { 
       "timeZone":"Europe/Madrid",
       "addOns":{ 
          "calendar":{ 
             "homepageTrigger":{ 
                "runFunction":"onCalendarHomePageOpen",
                "enabled":true
             }
          },
          "common":{ 
             "logoUrl":"https://ssl.gstatic.com/docs/script/images/logo/script-64.png",
             "name":"MRE Chinese Locale",
             "useLocaleFromApp":true
          }
       },
       "oauthScopes":[
          "https://www.googleapis.com/auth/script.locale",
          "https://www.googleapis.com/auth/calendar.addons.execute"
       ],
       "exceptionLogging":"STACKDRIVER",
       "runtimeVersion":"V8"
    }
    
  4. Go to Deploy > Test Deployments - select type "Add on", then install it for your account.

  5. Open the executions page.

  6. In a new tab go to https://calendar.google.com/ and once loaded, in the sidebar you should see the icon for apps script. Click the icon to open the sidebar. This will trigger the function.

  7. Go back to executions page.

  8. In another new tab, go to https://myaccount.google.com/u/1/language

  9. Change your preferred Language to Chinese, simplified or traditional

  10. Refresh the calendar page and open the sidebar again.

  11. Check the executions page.

Expected Result:

My account was set to English originally, and outputted Language code: en, I changed it to spanish and it outputted Language code: es. For chinese I would expect Langauge code: zh.

Actual Result:

Language Code: - no langauge code for Chinese.

iansedano
  • 6,169
  • 2
  • 12
  • 24