Google Apps Script Multi-language environment

123 views
Skip to first unread message

Tim Lai

unread,
Sep 13, 2019, 2:34:19 AM9/13/19
to Google Apps Script Community
I have the below block of codes...

function findEvents(user, keyword, start, end, optSince) {
  var params = {
    q: keyword,
    timeMin: formatDateAsRFC3339(start),
    timeMax: formatDateAsRFC3339(end),
    showDeleted: true,
  };
  if (optSince) {
    // This prevents the script from examining events that have not been
    // modified since the specified date (that is, the last time the
    // script was run).
    params.updatedMin = formatDateAsRFC3339(optSince);
  }
  var pageToken = null;
  var events = [];
  do {
    params.pageToken = pageToken;
    var response;
    try {
      response = Calendar.Events.list(user.getEmail(), params);
    } catch (e) {
      console.error('Error retrieving events for %s, %s: %s; skipping',
          user, keyword, e.toString());
      continue;
    }
    events = events.concat(response.items.filter(function(item) {
      return shoudImportEvent(user, keyword, item);
    }));
    pageToken = response.nextPageToken;
  } while (pageToken);
  return events;
}

where keyword can be...

['out of office', 'offline', 'vacation', 'ooo', '不在'];

I am scripting in a multi-languages environment the english keywords work fine but not the Kenji/Japanese characters. Any idea? Thanks for your help!



Tim Lai

unread,
Sep 13, 2019, 9:48:59 PM9/13/19
to Google Apps Script Community
Hmmm...no taker on this? 

Let's try simplifying the question. The params object property q the search keyword can be Japanese and English words as our Calendar uses both the languages. For example, the out of office event can have 'Out of office' or '不在' in the event title. 

So what is the way to handle multi-languages Calendar environment? The event listing works only with English keywords but not the Japanese. Any idea? 

Thx and appreciate your help!

-Tim


var KEYWORDS = ['out of office', 'offline', 'vacation', 'ooo', '不在'];

var params = {
    q: keyword,
    timeMin: formatDateAsRFC3339(start),
    timeMax: formatDateAsRFC3339(end),
    showDeleted: true,
};

 var response = Calendar.Events.list(user.getEmail(), params);

Tim Lai

unread,
Oct 2, 2019, 5:32:44 PM10/2/19
to Google Apps Script Community
No luv here...anyone else programming app script in a multi-language environment?

ChiefChippy2

unread,
Oct 3, 2019, 1:04:31 AM10/3/19
to Google Apps Script Community
I code Google Apps Script in English, but the environment doesn't seem very friendly with emojis, which might relate to your problem.

Google might be your friend ( I found some results but I am not sure if you want that or not )

Andrew Apell

unread,
Oct 3, 2019, 7:10:25 AM10/3/19
to google-apps-sc...@googlegroups.com
Since you want any answer (kidding...), try playing around with JSON
Please note that this is a little more than a hunch and less than a guesstimate

Tim Lai

unread,
Oct 4, 2019, 10:21:53 PM10/4/19
to Google Apps Script Community
Thx for the reply! I think I am on to it...

Tim Lai

unread,
Oct 4, 2019, 10:26:28 PM10/4/19
to Google Apps Script Community
Hi Andrew:

Right on!

I tried using js to do the encoding and it was no bueno.

So I just use PHP to convert the Japanese character...

<?php
  echo json_encode('不在');
?>

and I got:

var KEYWORDS = ['out of office', 'offline', 'vacation', 'ooo', '\u4e0d\u5728'];


Now, the Calendar.Events.list() is returning Out of Office in Japanese too. Awesome!

Thanks for your help!

Tim

Andrew Apell

unread,
Oct 4, 2019, 11:09:46 PM10/4/19
to Google Apps Script Community
You are welcome Tim! I'm glad it worked.

Alex

unread,
Oct 5, 2019, 12:26:26 AM10/5/19
to Google Apps Script Community
Reply all
Reply to author
Forward
0 new messages