User content translations

Remote translations on demand by the user

The aim of this service is to be able to offer all the dynamic contents of the application (proposals, debates, budget investments and comments) in different languages automatically.

When a user visits a page with a language where there is untranslated content, they will have a button to request the translation of all the content. This content will be sent to an automatic translator (in this case Microsoft TranslatorText) and as soon as the response is obtained, all these translations will be available to any user.

Getting started

In order to use this functionality, the following steps are necessary:

  1. Create an Azure account.

  2. Once you are logged into the Azure portal, create a resource of type Translator Text (note: for this implementation it is necessary to select the GLOBAL region when creating the resource, otherwise it will be necessary to customize the API calls by adding the selected region).

  3. Once you have subscribed to the Translator Text service, you will have access to two API keys in the section Resource Management > Keys and Endpoint that will be necessary for the configuration of the translation service in your application.

Configuration

To enable the translation service in your application you must complete the following steps:

Add api key in the application

In the previous section we have mentioned that, once subscribed to the translation service, we get two API keys. To configure the service correctly in our application we must add one of the two API keys to the apis: section of the secrets.yml file, with the key microsoft_api_key as follows:

apis: &apis
  census_api_end_point: ""
  census_api_institution_code: ""
  census_api_portal_code: ""
  census_api_user_code: ""
  sms_end_point: ""
  sms_username: ""
  sms_password: ""
  microsoft_api_key: "new_api_key_1_for_translator_text"

Enabling the feature

Once we have the new key in the secrets.yml we can now proceed to enable the feature. To enable it, in the administration area access the section Settings > Global settings > Features and enable the Remote translation feature.

Use Cases

Once we have the api key in our secrets.yml and the feature enabled, users will now be able to use remote translations in the application.

We attach some screenshots of how the application interacts with our users:

Available languages for remote translation

Currently these are all the available languages in the translation service:

["af", "am", "ar", "as", "az", "ba", "bg", "bho", "bn", "bo", "brx", "bs", "ca", "cs", "cy", "da", "de", "doi", "dsb", "dv", "el", "en", "es", "et", "eu", "fa", "fi", "fil", "fj", "fo", "fr", "fr-CA", "ga", "gl", "gom", "gu", "ha", "he", "hi", "hne", "hr", "hsb", "ht", "hu", "hy", "id", "ig", "ikt", "is", "it", "iu", "iu-Latn", "ja", "ka", "kk", "km", "kmr", "kn", "ko", "ks", "ku", "ky", "ln", "lo", "lt", "lug", "lv", "lzh", "mai", "mg", "mi", "mk", "ml", "mn-Cyrl", "mn-Mong", "mni", "mr", "ms", "mt", "mww", "my", "nb", "ne", "nl", "nso", "nya", "or", "otq", "pa", "pl", "prs", "ps", "pt", "pt-PT", "ro", "ru", "run", "rw", "sd", "si", "sk", "sl", "sm", "sn", "so", "sq", "sr-Cyrl", "sr-Latn", "st", "sv", "sw", "ta", "te", "th", "ti", "tk", "tlh-Latn", "tlh-Piqd", "tn", "to", "tr", "tt", "ty", "ug", "uk", "ur", "uz", "vi", "xh", "yo", "yua", "yue", "zh-Hans", "zh-Hant", "zu"]

Of all the languages currently available in Consul Democracy (available_locales) in config/application.rb, the only one that is not listed above and therefore no translation service is offered is Valencian ["val"].

Pricing

The translation service used has the most competitive pricing. The price for each 1 Million characters translated is $10 and there is no fixed cost per month.

Although technical measures have been taken to prevent misuse of this service, we recommend the creation of Alerts offered by Azure so that an Administrator can be notified in the event of detecting unusual use of the service. This service has a cost of $0.10 per month.

To create an Alert in Azure we must follow the following steps:

  1. Sign in to the Azure Portal.

  2. Access the Translator service created earlier.

  3. Go to Monitoring > Alerts in the side menu:

    1. Go to Create alert rule.

    2. In Select a signal select Text Characters Translated.

    3. Once selected we must define the logic of the Alert to suit our needs. Ex: Fill "Operator" field with "Greater than" option, fill "Aggregation type" field with "Total" option and fill "Threshold value" field with the number of characters we consider should be translated before being notified. In this section you can also set the time period and frequency of evaluation.

    4. In order to be notified we have to create an Action Group and associate it with this Alert we're creating. To do this, access the button Create and fill out the form. As you can see there are different types of actions, we must select Email/SMS/Push/Voice and configure the option that we consider convenient according to our needs.

    5. Once this group of actions has been created, it is directly associated with the rule we are creating.

    6. Finally, all you have to do is add a name and click on the Review + create

Add a new translation service

If you want to integrate more translation services for any reason (new translation service appears, you want to change to include languages that are currently not supported, etc.) the code is ready to be customized.

This is made possible by the RemoteTranslations::Caller class which is an intermediate layer between untranslated content management and the currently used Microsoft Translation Client.

A good solution for adding another translation service would be to replace the call to the MicrosoftTranslateClient in the translations method of RemoteTranslations::Caller with the new service implemented.

If you want to manage the coexistence of both, you should determine under which conditions to use one service or the other, either through specific conditions in the code or through a management in the Settings of the application.

class RemoteTranslationsCaller

  ...
  def translations
    @translations ||= RemoteTranslations::Microsoft::Client.new.call(fields_values, locale)
    # Add new RemoteTranslations Client
    # @translations = RemoteTranslations::NewTranslateClient::Client.new.call(fields_values, locale_to)
  end
  ...

end

Translation interface

The aim of this feature is to allow users the introduction of dynamic contents in many languages at the same time. From the administration panel you can enable or disable it. If you disable this feature (default configuration) users will be able to enter one single translation.

Enabling the feature

To enable this feature you must access from the administration panel to the section Configuration > Global configuration > Features and enable the feature called Translation Interface.

Use Cases

Depending on whether we enable or disable the Translation Interface feature we will see the forms as follows:

  • When the translation interface is active: As you can see in the image below, the translation interface has two selectors, the first one "Select language" is to switch between enabled languages and the second one "Add language" is to add new languages to the form. Translatable fields appears with a blue background to facilitate users to distinguish between translatable and not translatable fields.

    Additionally, the interface provides a link Remove language to delete the current language shown at "Select language". If a user accidentally removes a translation they can recover it by re-adding it to the form.

Last updated