Accessing User Locale and Timezone

Gmail add-ons can access the locale and timezone of its user and the use that information to customize its interface and behavior. You must configure your add-on's manifest to permit your add-on to access this information.

Configure the add-on manifest

You can configure your add-on to access user locale and timezone information with the following steps:

  1. In your add-on's manifest file, add gmail.useLocaleFromApp: true as a top-level parameter. See Manifest structure for Gmail add-ons for an example.
  2. If it isn't present already, add the following explicit scope in the manifest's oauthScopes list: https://www.googleapis.com/auth/script.locale
  3. Save the manifest changes.

If you added a scope to the add-on's oauthScope list, Gmail requires users to re-authorize the add-on the next time it is opened.

Obtaining locale and timezone information

Gmail inserts user locale information into action event objects for add-ons that are properly configured. The following fields appear in the event object:

  • userLocale—A two-letter string code indicating the user's language.
  • userTimezone.offset—The user timezone offset, in milliseconds, from Coordinated Universal Time (UTC).
  • userTimezone.id—The user's timezone identifier. For example, America/New_York.

See Action event objects for more details.

Action event objects are passed to action callback functions as the user interacts with your add-on. Each callback function can read the locale and timezone information from the event object and use it as necessary. For example, a callback function that is navigating to a new card could refer to the locale string when deciding what text to add to the card.

Send feedback about...

Gmail Add-ons
Gmail Add-ons
Need help? Visit our support page.