Dynamically translate between languages using Google machine learning. Google Translation enables fast, dynamic translation tailored to your content needs.Supports more than one hundred languages, from Afrikaans to Zulu.
Sign-up for a Google Cloud account and setup the Natural Language API.
Sign-up for a PubNub account, if you don't have one already.
Import the Integration Block into your PubNub account. You can choose to add this to an existing application or create a new one.
Configure the Integration Block module code, connecting it to your Google Cloud account:
Create a Secret in PubNub Vault, named GOOGLE_TRANSLATION_SERVICES_APIKEY
, with value equal to your Google API Key for this service, retrieved as part of step 1 above.
Start the Integration Block module.
Try a test message (you can click on Publish
to do this).
This Integration Block is setup to listen to a specific PubNub channel (CHANNEL-to-translate-Google
) but you can configure it to listen to all channels or a subset, using wildcards, e.g. chat.*
. Thus, you can add machine learning-generated translation capabilities even in private chats and other secure communication channels. The Integration Block is flexible in that it can be used both as part of a PubNub messaging flow, i.e. as part of publishing data, as well as accessed separately through a REST endpoint. Additionally, customization of capabilities can be done through publish message metadata or REST query parameters. In publish metadata, the customization properties are set as part of a JSON object specific for the function named google-translate-v2
.
TEXT_LOCATION_ID: json dot notation for locating the text field in the message payload.
INPUT_TEXT_MODEL: direct configuration of the Google Translation API property
INPUT_TEXT_TYPE: direct configuration of the Google Translation API property
INPUT_TEXT_LANGUAGE: direct configuration of the Google Translation API property; this is the language of the input text
INPUT_TARGET_LANGUAGE: direct configuration of the Google Translation API property; this is the target language into which the input text should be translated
INPUT_TEXT_ENCODING_TYPE: direct configuration of the Google Natural Language API property
OUTPUT_LOCATION_ID: json dot notation for locating the output data in the final message payload. Specify meta
if you want the output data to be part of the metadata property of the message payload.
Publish message containing message body to input channel. Input Channel: CHANNEL-to-moderate-Azure-Content
You can change this channel in the PubNub Administration Portal, using the Block's Function editor.
{ "content": { "body": "This is Awesome!" } }
The response from Azure Content Moderation API is included in the payload, or in the meta property of the published message.
{ "content": { "body": "This is Awesome!" }, "moderation": { "azure": { "OriginalText": "This is Awesome!", "NormalizedText": " Awesome!", "Misrepresentation": null, "Classification": { "ReviewRecommended": false, "Category1": { "Score": 0.08436591923236847 }, "Category2": { "Score": 0.23644307255744934 }, "Category3": { "Score": 0.04646378755569458 } }, "Language": "eng", "Terms": null, "Status": { "Code": 3000, "Description": "OK", "Exception": null }, "TrackingId": "USC_ibiza_fb755908-2ccb-4f2f-a2f1-35dac3c8c640_ContentModerator.F0_b33cce45-e2b9-4268-8e42-da5301f2ad99" } } }
Need help? Contact PubNub Support.
Copyright (c) 2018 PubNub
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.