Actions on google 如何使用Google Actions和带有Firebase函数的DiaglogflowApp处理不同的语言
我在Dialogflow代理中配置了多种语言。我不知道如何在firebase函数中检测请求的语言,以便用正确的语言回答。有没有标准的方法来处理这个问题?我看不到任何函数来检测中的语言 我希望能够做到以下几点:Actions on google 如何使用Google Actions和带有Firebase函数的DiaglogflowApp处理不同的语言,actions-on-google,Actions On Google,我在Dialogflow代理中配置了多种语言。我不知道如何在firebase函数中检测请求的语言,以便用正确的语言回答。有没有标准的方法来处理这个问题?我看不到任何函数来检测中的语言 我希望能够做到以下几点: const app = new DialogflowApp({request: request, response: response}); if (app.getLang == 'en') { \\ Do something in english } else if (app
const app = new DialogflowApp({request: request, response: response});
if (app.getLang == 'en') {
\\ Do something in english
}
else if (app.getLang == 'es') {
\\ Do something in spanish
}
AoG GitHub上有一个公共示例,它是法语和英语的 在此示例中,他们为英语和法语地区定义:
{
"images": {
"cold": {
"url": "COLD.gif",
"altText": "cold genie",
"cardText": [
"Freezing like an ice cave in Antarctica?",
"I can't feel my face anymore",
"Hurry, before I turn into an icicle"
]
},
...
{
"images": {
"cold": {
"url": "COLD.gif",
"altText": "Génie froid",
"cardText": [
"Je me gèle comme un glaçon en Antartique",
"Je ne sens plus mon visage",
"Dépêchez-vous avant que je ne me transforme en glaçon"
]
},
...
然后是一个中心文件,它将为该区域设置提取正确的字符串
const i18n = require("i18n");
i18n.configure({
"directory": __dirname + "/locales",
"objectNotation": true,
"fallbacks": {
"fr-FR": "fr",
"fr-CA": "fr"
}
});
const prompts = () => ({
"welcome": {
"visual": {
"elements": [
[i18n.__("variants.greeting"), i18n.__("variants.invocation")],
i18n.__("variants.invocationGuess"),
i18n.__("images.intro")
],
"suggestions": onlyNumberSuggestions
}
},
...
然后用于:
字符串;
this.data.guessCount=0;
this.data.fallbackCount=0;
this.data.streamsoundcount=0;
this.ask(strings.prompts.welcome、strings.numbers.min、strings.numbers.max);
}
通过从app.getUserLocale()
方法获取语言环境来设置语言环境:
/**
* Get the Dialogflow intent and handle it using the appropriate method
*/
run () {
strings.setLocale(this.app.getUserLocale());
/** @type {*} */
const map = this;
const action = this.app.getIntent();
console.log(action);
if (!action) {
return this.app.ask(`I didn't hear a number. What's your guess?`);
}
map[action]();
}
这里肯定有很多东西,你不需要用完全相同的方式来做
app.getUserLocale()
应返回当前区域设置,然后您可以以任何方式使用该区域设置来返回响应。在AoG GitHub for上有一个公共示例,该示例使用法语和英语
在此示例中,他们为英语和法语地区定义:
{
"images": {
"cold": {
"url": "COLD.gif",
"altText": "cold genie",
"cardText": [
"Freezing like an ice cave in Antarctica?",
"I can't feel my face anymore",
"Hurry, before I turn into an icicle"
]
},
...
{
"images": {
"cold": {
"url": "COLD.gif",
"altText": "Génie froid",
"cardText": [
"Je me gèle comme un glaçon en Antartique",
"Je ne sens plus mon visage",
"Dépêchez-vous avant que je ne me transforme en glaçon"
]
},
...
然后是一个中心文件,它将为该区域设置提取正确的字符串
const i18n = require("i18n");
i18n.configure({
"directory": __dirname + "/locales",
"objectNotation": true,
"fallbacks": {
"fr-FR": "fr",
"fr-CA": "fr"
}
});
const prompts = () => ({
"welcome": {
"visual": {
"elements": [
[i18n.__("variants.greeting"), i18n.__("variants.invocation")],
i18n.__("variants.invocationGuess"),
i18n.__("images.intro")
],
"suggestions": onlyNumberSuggestions
}
},
...
然后用于:
字符串;
this.data.guessCount=0;
this.data.fallbackCount=0;
this.data.streamsoundcount=0;
this.ask(strings.prompts.welcome、strings.numbers.min、strings.numbers.max);
}
通过从app.getUserLocale()
方法获取语言环境来设置语言环境:
/**
* Get the Dialogflow intent and handle it using the appropriate method
*/
run () {
strings.setLocale(this.app.getUserLocale());
/** @type {*} */
const map = this;
const action = this.app.getIntent();
console.log(action);
if (!action) {
return this.app.ask(`I didn't hear a number. What's your guess?`);
}
map[action]();
}
这里肯定有很多东西,你不需要用完全相同的方式来做
app.getUserLocale()
应返回当前区域设置,然后您可以以任何方式使用该区域设置来返回响应。但是DialogflowApp没有getUserLocale
方法。我不能执行app.getUserLocale()
它是superAssistantApp
类的一部分:但是DialogflowApp没有getUserLocale
方法。我不能做app.getUserLocale()
它是superassistantap
类的一部分: