Text Translation Reference Architecture

It's not unusual that players in the same game session natively speak different languages and may appreciate receiving both the original message and its translation.

This article will describe the architecture used in this sample on GitHub. Keep in mind that the code from this reference architecture is only an example for guidance and there may be places to optimize the code before using in a production environment.

Architecture Diagram

Text translation reference architecture

Architecture Services

  • Translator Text - Translates text to multiple languages on the fly.
  • Azure Traffic Manager - (Optional) connects the player to the most appropiate regional zone based on latency where the chat servers would be.
  • Event Hub - A service tailored for real-time receiving and processing of a large number of events (chat strings in this case), in order, with little configuration or management overhead.
  • Azure Function - Serverless compute service to run code on-demand -- in this case, code that invokes the different cognitive services.

Architecture Considerations

You only need to create a single Event Hub namespace that will contain the 2 Event Hubs used for sending and receiving messages, respectively.

Not every language is supported by the service today. Please see the language and region support for the Translator Text API documentation for what languages and regions are supported.

Deployment Template

Click the following button to deploy the project to your Azure subscription:

This operation will trigger a template deployment of the azuredeploy.json ARM template file to your Azure subscription, which will create the necessary Azure resources. This may induce charges in your Azure account.

Have a look at the general guidelines documentation that includes a section summarizing the naming rules and restrictions for Azure services.

Note

If you're interested in how the ARM template works, review the Azure Resource Manager template documentation from each of the different services leveraged in this reference architecture:

There are two types of Azure Cognitive Services subscriptions. The first is a subscription to a single service, such as Computer Vision or the Speech Services. A single-service subscription is restricted to just that service. The second type is a multi-service subscription. This allows you to use a single subscription for multiple Azure Cognitive Services. This option also consolidates billing. To make this reference architecture as modular as possible, the cognitive services are each setup as a single service.

Finally, add these Function application settings so the sample project can connect to the Azure services:

  • EVENTHUB_CONNECTION_STRING - The connection string to the Azure Event Hub namespace that was created
  • TRANSLATORTEXT_KEY - The access key used to access the Azure Translator Text Cognitive Service that was created

Tip

To run the Azure Functions locally, update the local.settings.json file with these same app settings.

Step by Step

  1. The player's device opens a persistent and encrypted connection to the chat server in a specific region determined by Azure Traffic Manager. The chat server creates a process responsible for maintaining connectivity with the player along with some basic metadata.
  2. The player's client sends a chat message to the chat server over the secure connection previously created. The player's process in the chat server receives the message, decrypts it, and parses it.
  3. Standard validations are run, and the chat server calls the Azure Event Hub service, as it keeps the message order.
  4. The Azure Event Hub serves as an input trigger for an Azure Function.
  5. The Azure Function invokes the Azure Text Translator service that reviews the message sent by the player and returns an result.
  6. Another Azure Event Hub is set as the output for the Azure Function.
  7. The chat server receives the outcome from the Azure Event Hub.
  8. Optionally the chat server saves both the original message and the translation from the Azure Text Translator service in persistent storage like Azure Data Lake Storage.
  9. If the result was stored, optionally save into Azure Data Lake Analytics for analysis purposes.
  10. The result from the Azure Text Translator service is then sent to the recipient players' pertinent processes in the chat server. The processes run further validations on the message, serialize it and send it to the recipient players' devices over their secure connections. Finally it's displayed in the chat screen.

Azure Event Hubs

See this quickstart for a simple implementation for sending an event to an Event Hub in multiple programming languages. Some additional samples are available here.

Function triggered by an Azure Event Hub outputting to another Azure Event Hub

When an Event Hubs trigger Function is triggered, the message that triggers it is passed into the Function as a string. Use the Event Hubs output binding to write events to an event stream.

[return: EventHub("ehigce-output", Connection = "EventHubConnectionAppSetting")]
    public static string Run([EventHubTrigger("ehigce-input", Connection = "EventHubConnectionAppSetting")] string chatString, ILogger log)

Check out the common causes and solutions for 401 Access Denied errors when calling Cognitive Services.

Security considerations

Do not hard-code any Event Hub or Cognitive Services connection strings into the source of the Function. Instead, at a minimum, leverage the Function App Settings or, for even stronger security, use Key Vault instead. There is a tutorial explaining how to create a Key Vault, how to use a managed service identity with a Function and finally how to read the secret stored in Key Vault from a Function.

Review the Event Hub authentication and security model overview and put it into practice to ensure only your chat server can talk to the Event Hub.

The Translator Text API can translate behind firewalls using either domain-name or IP filtering. Domain-name filtering is the preferred method. We do not recommend running Microsoft Translator from behind an IP filtered firewall as the setup is likely to break in the future without notice. See how to translate behind IP firewalls with the Translator Text API for all the details.

Scaling

There are two points that could become a bottleneck in this architecture that you should plan for:

  1. Cognitive Services scale well but they are throttled by default. Reach out to Azure support if you are planning to make use of them in large scale to increase capacity.
  2. The chat server receiving the Azure Event Hub responses will need to scale. Spin up enough virtual machines to address the demand.

Alternatives

You could consider leveraging Azure Cache for Redis and Azure Databricks if you are interested in gathering analytics using an Apache Spark-based platform.

Additional resources and samples

Azure Event Hubs SDK for Unity: This is a sandbox project. The content in this article is unsupported, and therefore may be out of date or not in a working state.

Pricing

If you don't have an Azure subscription, create a free account to get started with 12 months of free services. You're not charged for services included for free with Azure free account, unless you exceed the limits of these services. Learn how to check usage through the Azure Portal or through the usage file.

You are responsible for the cost of the Azure services used while running these reference architectures. The total amount will vary based on usage. See the pricing webpages for each of the services that were used in the reference architecture:

You can also use the Azure pricing calculator to configure and estimate the costs for the Azure services that you are planning to use.