alexa / alexa-skills-kit-sdk-for-nodejs

The Alexa Skills Kit SDK for Node.js helps you get a skill up and running quickly, letting you focus on skill logic instead of boilerplate code.
Apache License 2.0
3.12k stars 736 forks source link

"locale" information missing in Alexa HouseholdList event request / How to get multi language support in event handler? #413

Closed jensbuehl closed 6 years ago

jensbuehl commented 6 years ago

Reopen vor SDK v2: https://github.com/alexa/alexa-skills-kit-sdk-for-nodejs/issues/322

I have successfully integrated the Alexa.HousholdListEvents in my node.js AWS lambda based skill. Now I am trying to use language translation as for usual Intents / Requests.

Unfortunately in the HousholdListEvent the "request" does not contain locale information and instead of a translated string I am getting just the identifier repeated when using t(). See example below. I cannot get the locale information from the received event and would have to fall back to english which is blocking me from starting skill the certification process.

If you need further information - feel free to ask. I am more than happy to provide more details if needed.

Any help is appreciated!

Why do I have no locale information as part of the event? Why is t() not working as expected (just like for normal intents)? How could I translate in the event handler based on the origin locale?

My event request:

"request": {
    "type": "AlexaHouseholdListEvent.ItemsCreated",
    "requestId": "4a3d1715-e9b3-4980-a6eb-e4047ac40907",
    "timestamp": "2018-03-12T11:20:13Z",
    "eventCreationTime": "2018-03-12T11:20:13Z",
    "eventPublishingTime": "2018-03-12T11:20:13Z",
    "body": {
        "listId":        "YW16bjEuYWNjb3VudC5BRVlQT1hTQ0MyNlRQUU5RUzZITExKN0xNUUlBLVNIT1BQSU5HX0lURU0=    ",
        "listItemIds": [
            "fbcd3b22-7954-4c9a-826a-8a7322ffe57c"
        ]
    }
},

I am using the Default Translation interceptor, which probably needs an update in case the request does not include locale Information:

const LocalizationInterceptor = {
    process(handlerInput) {
        const localizationClient = i18n.use(sprintf).init({
            lng: handlerInput.requestEnvelope.request.locale,
            overloadTranslationOptionHandler: sprintf.overloadTranslationOptionHandler,
            resources: languageStrings,
            returnObjects: true
        });

        const attributes = handlerInput.attributesManager.getRequestAttributes();
        attributes.t = function (...args) {
            return localizationClient.t(...args);
        };
    },
};

My translation usage:

attributes.t('MY_STRING_IDENTIFIER')

My result (in the ItemsCreated event handler):

MY_STRING_IDENTIFIER

Expected result (as for other requests):

"This is my translated text"

Your Environment

Node.js and NPM Info

jensbuehl commented 6 years ago

According to Amazon it is as intended and as of now no workaround seems available. If anybody runs into the same problem, please support the idea so that we may get the locale property for events anytime soon:

https://alexa.uservoice.com/forums/906892-alexa-skills-developer-voice-and-vote/suggestions/34621093-provide-locale-property-in-event-skillevent-list

tianrenz commented 6 years ago

Hi @exe222 ,

Thanks for your effort in looking into this. Since this is a non-SDK related issue, I would recommend future discussions to move to the link above.

Regards