Skip to content

Commit

Permalink
Merge pull request #38 from Accenture/german-utterances
Browse files Browse the repository at this point in the history
Added support for german utterances
  • Loading branch information
Glogo authored Dec 6, 2016
2 parents 204633e + bb189ef commit 5aa9a76
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
6 changes: 4 additions & 2 deletions src/create-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,15 @@ module.exports = (name, options) => {
*/
app.handle = (data, done) => {
// Internationalization is enabled and locale is specified in request
if (app.i18next && data.request.locale) {
if (app.i18next) {

const locale = data.request.locale || 'en-US';

// Make sure all locale resources are loaded
app.i18next.loadResources(() => {

// Get translation function for current locale
const t = app.i18next.getFixedT(data.request.locale, 'translation');
const t = app.i18next.getFixedT(locale, 'translation');

// Prefix key by using intent name or request type for launch / end requests
let prefix;
Expand Down
2 changes: 1 addition & 1 deletion src/validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module.exports = {
* possesive apostrophes, hyphens and brackets for slots.
* @see https://developer.amazon.com/appsandservices/solutions/alexa/alexa-skills-kit/docs/defining-the-voice-interface
*/
isUtteranceValid: (utterance) => /^[a-z\s.'\-{}]*$/gmi.test(utterance),
isUtteranceValid: (utterance) => /^[a-z\s.'\-{}äöüÄÖÜß]*$/gmi.test(utterance),

/**
* @returns {boolean} whether given custom slot name is correct or not.
Expand Down
12 changes: 12 additions & 0 deletions test/multi-language.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,18 @@ describe('multi language app', () => {
});
});

it('should handle LocalizedIntent without locale (backwards compatibility)', done => {
const request = alexia.createRequest({
name: 'LocalizedIntent'
});
delete request.request.locale;

app.handle(request, data => {
expect(data.response.outputSpeech.text).to.equal('Hello World');
done();
});
});

it('should have access to app.t function for all apps', (done) => {
// This app is not localized
const app2 = alexia.createApp();
Expand Down
7 changes: 2 additions & 5 deletions test/test-apps/multi-language/locales/de/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,10 @@
"text": "Hallo Welt"
},
"LocalizedSlotIntent": {
"utterances": "Meine magische nummer ist {number:Number}",
"utterances": "Meine magische nummer ist {number:Number}. Testen äöüÄÖÜß",
"text": "hallo {{number}}"
},
"YesIntent": {
"text": "Testen der Punktsyntax",
"nested": {
"nah": "meh"
}
"text": "Testen der Punktsyntax"
}
}

0 comments on commit 5aa9a76

Please sign in to comment.