Editor's Note: you may now publish Canadian French skills in the Canada Alexa Store.
Since November 2017, Canadian customers can use Amazon Echo devices to interact with Alexa in English. Today, we announced that Amazon Alexa and Alexa-enabled devices will be available with Canadian French later this year. Starting today, developers can use the Alexa Skills Kit (ASK) to build skills for customers in Canada using the new French (Canada) language model.
If you are new to skill development, check out this detailed walkthrough to get started. If you’re an experienced Alexa developer, you can enhance your existing skill by extending it to support the new French language model for Canada. This tutorial will show you how you can add support for the French (Canada) model for your existing skills. It will also show you how you can use ASK to enable Alexa to respond based on locales.
You will learn:
1. Navigate to your existing skill on the Amazon Developer Portal.
2. Click on the language drop down on the top right of the screen and select the last option: “Language Settings.” In this example, the skill already has language models for several English models and French.
3. Follow the steps below to complete the Language Settings screen:
4. Now provide the interaction model for the French (Canada) version. You can do this by copying the interaction model from one of the English versions of our skill, and translating the sample utterances and slot values and synonyms. Alternatively, if your skill already supports French for France, you can just copy the interaction model as-is as a first step. In this example, we’re starting from Canadian English. Switch to the Canadian English version by clicking on the language dropdown in the skill builder, and choose English (CA).
5. Click on JSON Editor on the left side bar. This displays the complete interaction model for the skill in JSON format.
6. Select and copy all of the JSON in the code window.
7. Switch back to French (CA) using the dropdown from Step 4.
8. Click on JSON Editor again, and paste the JSON into the code window, replacing the existing JSON.
9. Translate all sample utterances, slot values, and slot synonyms.
10. Click on the Save Model button.
11. Click on the Build Model button.
We now have the language model built for French (Canada). You now need to translate the invocation name, the sample utterances, the slot values, and the synonyms.
You also must localise the skill metadata, including skill name, description, keywords and the icons, should they contain localised content, such as text or currency symbols. Skills metadata are available in the “Distribution” tab of the Alexa Developer Console.
In a typical development workflow, you will probably build the skill voice interaction model JSON document programmatically, based on different files you have with sample utterances and slot values.
If your interaction model uses any built-in slot types, you may need to make changes to ensure that the types are supported in the locale. For example, the AMAZON.US_FIRST_NAME is supported in English (US), English (UK), English (Canada), and German. An equivalent first name slot type, AMAZON.FirstName, is available for French (Canada), French, English (India), English (Australia) and Japanese. See the Slot Type Reference for a list of slot types for each supported locale.
Once you have finished translating your interaction model for French (Canada), you need to customize the responses your skill returns for the different locales that you support. Do this by updating your Lambda function.
Now that your skill is ready to support multiple regions, you may want to update your Lambda function to ensure that your skill provides responses translated or tailored to each supported region.
At least, you need to translate to French (Canada) the strings the skill is sending to Alexa to render with the voice of Alexa. You can also use this technique to use different strings for different variation of English. For instance, you may want to greet your customers with “G’day” in Australia, “Hello” in Canada and the UK, “Namaste,” in India, "Hi" in the US, “Bonjour” in France, and “Bon matin” in Quebec. You can use any localisation library to help you to match strings to locale. Here is an example of how I made it with the ASK Software Development Kit (SDK) for Node.js. For brevity, in this example, all English-based languages are sharing the same set of strings.
The code below is based on version 2 of the ASK SDK for Node.js, using the Typescript programming language. It can be easily adapted to other languages.
Step 0: Have a basic string localisation library or class.
For advanced localisation needs, you probably want to use a full fledge localisation library that handles not only strings but also number, date and currency formats. For example AirBnB’s Polyglot, Wikimedia’s i18n, or JQuery’s Globalize.
For simpler requirements, I wrote my own utility class and shared it in the skill audio sample repository. This class resolves locale-specific strings based on a locale code. It also allows you to substitute in string variables.
For brevity and simplicity, the code below is based on this simple string localisation utility class.
Step 1: Set the language strings for each region.
To do this, we define all user-facing language strings in the following format:
'use strict';
let EnglishStrings = {
"WELCOME_MSG": "Welcome to {0}",
"HELP_MSG": "Welcome to {0}. You can play, stop, resume listening. How can I help you ?",
"UNHANDLED_MSG": "Sorry, I could not understand what you've just said.",
"CAN_NOT_SKIP_MSG": "This is radio, you have to wait for next track to play.",
"RESUME_MSG": "Resuming {0}",
"NOT_POSSIBLE_MSG": "This is radio, you can not do that. You can ask me to stop or pause to stop listening.",
"STOP_MSG": "Goodbye.",
"TEST": "test english",
"TEST_PARAMS": "test with parameters {0} and {1}",
};
let FrenchStrings = {
"WELCOME_MSG": "Bienvenue sur {0}",
"HELP_MSG": "Bienvenue sur {0}. Vous pouvez démarrer, arrêter ou reprendre. Que souhaitez-vous faire ?",
"UNHANDLED_MSG": "Désolé, je n'ai pas compris ce que vous avez dit.",
"CAN_NOT_SKIP_MSG": "C'est de la radio, vous devez attendre le titre suivant.",
"RESUME_MSG": "Je redémarre {0}",
"NOT_POSSIBLE_MSG": "C'est de la radio, vous ne pouvez pas faire ca. Vous pouvez me demander d'arrêter ou de metre en pause pour arrêter la musique.",
"STOP_MSG": "au revoir !",
"TEST": "test français",
"TEST_PARAMS": "test avec paramètres {0} et {1}",
};
export const strings = {
"en-GB": EnglishStrings,
"en-US": EnglishStrings,
"en-CA": EnglishStrings,
"fr-FR": FrenchStrings,
"fr-CA": FrenchStrings
};
As you can see, languageStrings object contains five objects, one for each supported English language (en-CA, en-US, en-GB), one for French for France (fr-FR), and one for Canadian French. The object keys are identical to the value of the locale property that is passed to our skill when it is invoked by Alexa. This tells us the language model the customer’s device is configured to use so that we can respond with the appropriate string. If you wanted to support German and Japanese, you would add additional objects for 'de-DE' and 'ja-JP' locales, with appropriate translations.
You can see this in action by looking at the JSON request sent to your skill through the service simulator. When testing in the simulator, be sure to select the tab for the language you want to test. In our example, when testing from the Canadian French language, the request sent to the skill includes the fr-CA locale:
Each language has a translations object within languageStrings. This is where we specify any properties that are different for each language. For our example, we have WELCOME_MESSAGE and SKILL_NAME as part of the language strings. You can add more strings as you find relevant.
Step 2: Enable internationalization for your skill
To use the simple string localisation class in your typescript Intent Handler, import the class in your code’s header. The class will automatically load String.js with your string definitions for each language.
import { i18n } from './utils/I18N';
Step 3: Access the language strings in your code
Once you are done defining and enabling language strings, you can access these strings using the i18n(request,key, vars…)function. Strings will be rendered in the language that matches the locale of the incoming request. The first parameter is the skill request itself, the utility class will fetch the request locale from there. The second parameter is the key (name) of the string to return. The remaining parameters are an open list of variables to include in the returned string. The i18n() function will substitute these for any {0} placeholder. The order of the parameters must match the number in your placeholders.
This handler for the LaunchRequest retrieves the localized strings for the welcome message and skill greeting, then assembles a complete welcome message for the skill. For a customer using an English (US) device, this would return the speech output "Welcome to My Radio." A customer using a Canadian French device would receive the speech output “Bienvenue sur Ma Radio.”
const request = input.requestEnvelope.request;
return ResponseFactory.init()
.speak(i18n.S(request, "HELP_MSG", skill_name)
.withShouldEndSession(false)
.getResponse();
That’s all that it takes to update your skill for French customers in Canada. We are excited to have Alexa available in French in Canada, and we can't wait to see what you will build.
Check out our documentation to learn more about how you can use ASK to create multi-language Alexa skills.
Check out the following training resources, tutorials, and code samples to start building Alexa skills: