alexa-app icon indicating copy to clipboard operation
alexa-app copied to clipboard

Implement localization support

Open sibbl opened this issue 7 years ago • 5 comments

I plan to develop a Skill which should be reusable for both German and English. Of course I don't want to deploy it twice, but I want to be able to switch it dynamically at run time.

Would it be possible to introduce a URL parameter like "?locale=de" which I could add to the URL, which is then accessible in the request variable? Or is there already a way to get the express server's request object?

sibbl avatar Jan 17 '17 18:01 sibbl

I've never done this personally, but the Alexa skill localization seems to be fairly straightforward as described in https://developer.amazon.com/blogs/post/Tx2XUAQ741IYQI4/how-to-build-a-multi-language-alexa-skill. You get event.request.locale and you can respond accordingly.

Would love whatever code is needed in alexa-app to support that, but I don't think support for ?locale=de is that code. I could be wrong.

dblock avatar Jan 17 '17 18:01 dblock

It seems that it's not even possible to append GET parameters - Alexa then told me that she couldn't resolve my host name. As request.data.request.locale is set to de-DE, this should do it, if you ask me now. I wasn't aware of this property and appreciate your hint :)

Update: of course one has to handle the generation of slots+utterances then. But I'm not sure if making this easier is the purpose of this great alexa-app project.

sibbl avatar Jan 17 '17 18:01 sibbl

I'd love to have a section in the README on how to support multiple languages. Whatever that takes. And some new code ;)

dblock avatar Jan 17 '17 19:01 dblock

Having the same challenge. I'm using i18n and instantiate it in app.pre (using the alexa-app-router as well)

function pre (req, res) {
  i18n.configure({
    locales: ['en-US', 'en-GB', 'de-DE'],
    objectNotation: true,
    directory: __dirname + '/../locales',
    register: req
  })
  i18n.setLocale(req.data.request.locale)

Then I can use it in any handler with req.__('launch.welcome', config.appName)

I looked in @sibbl solution in his akinator project. The solution to generate the different utterances is kinda smart but still a workaround. Would love to see support in alexa-app/*-server directly as it is also a feature of Alexa and not just an afterthought.

siedi avatar Feb 07 '17 12:02 siedi

@siedi can you post a full example with the Launch-Intent for instance please? Would be awesome! I still have some questions and not sure if I understand or can implement your solution properly. Thank you very much!

natterstefan avatar Jul 02 '17 06:07 natterstefan