search

How to Use Unicode in OpenWhisk and the Globalization Pipeline Service


In this post I am going to help you overcome some of the issues you might encounter when trying to output Unicode from OpenWhisk actions. In a previous post I showed how to call the Globalization Pipeline service from Node Red and in this post I will show you how to call the Globalization Pipeline service from an OpenWhisk action and properly handle Unicode text that is returned by the service in OpenWhisk. If you are already familiar with how to get the Globalization Pipeline service’s credentials then you can go ahead and grab the service instance id, username, password, and create a reader key for accessing the service. If you don’t know how to do this, then read my earlier post.

I have provided a sample OpenWhisk action JavaScript file that shows how to call the Globalization Pipeline service. Feel free to download this file and simply insert your credentials in the appropriate locations. You will notice that we don’t simply return the raw result returned by calling the Globalization Pipeline service, but rather we first URI encode the messages for each key. We need to do this, because OpenWhisk converts all output to the ISO8859-1 encoding that causes Unicode characters beyond U+007F to be incorrectly converted. To avoid this issue we convert the messages to a safe URI encoding before outputting them by calling the querystring.escape function. This means that you will need to decode the messages before using them in other JavaScript functions. To decode the messages in JavaScript you can use the decodeURI function.

To upload the OpenWhisk action from the command line use the wsk action create command.

wsk action create globalization g11n-pipeline.js

To invoke the OpenWhisk action from the command line use the wsk action invoke command and substitute the lang id and bundle name with your values.

wsk action invoke globalization –blocking –result –param lang ‘lang id’ –param bundle ‘bundle name’

I hope this post helps you with using Unicode text in OpenWhisk.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

close
search
Latest Tweets

Hi, guest!

settings

menu