I18n randomized output not working


#1

Hey,

as mentioned in the title it just don’t work.
my i18n looks like this:

 "QUIT_MESSSAGE": {
          "speech": {
            "general": "test",
            "random": [
              "Tschau!",
              "Tschüss!"
            ]
          },

however when I access the output that should be randomized as mentioned in the documentation with

this.tell(this.t(‘QUIT_MESSSAGE.speech.random’));

it just hands out all of the messages of the random array (Tschau and Tschüss)…

This one gives me an error:

this.tell(this.t(‘QUIT_MESSSAGE.speech.random[0]’));

What am I doing wrong?


#2

This is a feature of the SpeechBuilder.

Try this:

this.$speech.addT('QUIT_MESSSAGE.speech.random');

this.tell(this.$speech);

#3

Hm, I can’t reproduce it. Do you have the latest version?


#4

Here’s the code:

/src/i18n/en-US.json

{
  "translation": {
    "QUIT_MESSSAGE": {
      "speech": {
        "general": "test",
        "random": [
          "Tschau!",
          "Tschüss!"
        ]
      }
    }
  }
}

/src/app.js

const { App } = require('jovo-framework');
const { GoogleAssistant } = require('jovo-platform-googleassistant');
const { Alexa } = require('jovo-platform-alexa');
const { JovoDebugger } = require('jovo-plugin-debugger');
const { FileDb } = require('jovo-db-filedb');

const app = new App();


app.use(
    new GoogleAssistant(),
    new Alexa(),
    new JovoDebugger(),
    new FileDb(),
);


app.setHandler({
    LAUNCH() {
        this.tell(this.t('QUIT_MESSSAGE.speech.random'));
    },
});

module.exports.app = app;


#5

@jan Thanks. That solved my problem.

I actually never got whats the advantage of the SpeechBuilder. It isn’t as powerful as ssml but you can acess it a bit easier and maybe more structured + it gives you some extra features, but is also missing alot of the ssmls, doesn’t it?

And another question: Does I have to change everything now to the SpeechBuilder synthax?
Bc currently this one works:

this.tell (
this.t(‘QUIT_MESSSAGE.speech.general’) + this.$speech.addT(‘QUIT_MESSSAGE.speech.random’)
);

@AlexSwe Your version worked also. I think the problem was, that I connected the random value with anouther i18n value:
this.tell(this.t('QUIT_MESSSAGE.speech.general') + this.t('QUIT_MESSSAGE.speech.random'));

Am I able to get the version above working somehow without using the SpeechBuilder?


#6

You have to merge the string and the array into an array.

Not the cleanest solution, but in this case this should work

let speech = [this.t('QUIT_MESSSAGE.speech.general')].concat(this.t('QUIT_MESSSAGE.speech.random')))
this.tell(speech);

#7

Sadly this doesnt work.

The array then contains the msg of 'QUIT_MESSSAGE.speech.general' but also the complete array of 'QUIT_MESSSAGE.speech.random'.

In the end only one property of the 'QUIT_MESSSAGE.speech.random' array is outputed


#8

Oh, I misunderstood.

You should try the Speechbuilder.

this.$speech.addT('QUIT_MESSSAGE.speech.general');
this.$speech.addT('QUIT_MESSSAGE.speech.random');
this.tell(this.$speech);


#9

Thanks I’ll have a try soon