alexa-js / alexa-app

A framework for Alexa (Amazon Echo) apps using Node.js
https://www.youtube.com/watch?v=pzM4jv7k7Rg
MIT License
1.03k stars 212 forks source link

Implement localization support #127

Open sibbl opened 7 years ago

sibbl commented 7 years ago

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?

dblock commented 7 years ago

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.

sibbl commented 7 years ago

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.

dblock commented 7 years ago

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

siedi commented 7 years ago

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.

natterstefan commented 7 years ago

@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!