简体   繁体   English

Botbuilder如何在命名空间未定义的情况下使用默认语言环境字符串

[英]Botbuilder how to use default locale strings in case namespace hasn't defined it

I am using the botbuilder framework. 我正在使用botbuilder框架。 I have defined several namespaces for the dialogs I have created, such as help or default . 我为我创建的对话框定义了几个名称空间,例如helpdefault For all of these I have also created json files in my locale/en/ directory, and all is well. 对于所有这些,我还在我的locale/en/目录中创建了json文件,一切都很好。 However, I have a few sentences that are very common, and I don't feel like copying those over to each of the individual namespaces. 但是,我有一些非常普遍的句子,我不想将它们复制到每个单独的命名空间中。 I have tried using index.json as a 'fallback' in case the namespace file doesn't define the string. 我曾尝试使用index.json作为“后备”,以防命名空间文件未定义字符串。 But it doesn't work for me. 但这对我不起作用。 Contrary to what the documentation seems to suggest. 文档似乎暗示的相反。

/locale
  /en
    /help.json
    /default.json
    /index.json <-- Doesn't work
/dialogs
  /help.js
  /default.js
bot.js

Say I have the following library in help.js , that : 说我在help.js有以下库:

lib = new builder.Library('help')
lib.dialog('/', (session) => {
  session.send('custom_cancel')
}
module.exports = lib

The library is used in bot.js : 该库在bot.js

bot.library(require('./dialogs/help'))

And index.json has this content: 并且index.json具有以下内容:

{
  "custom_cancel": "My custom cancel"
}

Whereas help.json is empty: help.json为空:

 {}

Because help.json does not have custom_cancel , the bot will actually send custom_cancel as the string. 因为help.json没有custom_cancel ,所以该漫游器实际上会将custom_cancel作为字符串发送。

Again. 再次。 I can copy paste the strings to both locations and there is no more problem. 我可以将字符串复制粘贴到两个位置,并且没有其他问题。 But that seems like an ugly solution to me. 但这对我来说似乎是一个丑陋的解决方案。

I have tried the more explicit version, which seems to help in more cases, but I am not fully convinced yet. 我尝试了更明确的版本,这似乎在更多情况下会有所帮助,但我还没有完全确信。

session.localizer.gettext(session.preferredLocale(), 'custom_cancel')

You can use the third argument for the namespace. 您可以将第三个参数用作名称空间。 It seems that '' will point to the index.json file. 似乎''将指向index.json文件。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用BotBuilder-Location时出现意外的字符串“ botbuilder-location:TitleSuffix”和“ botbuilder-location:MultipleResultsFound” - Unexpected strings “botbuilder-location:TitleSuffix” and “botbuilder-location:MultipleResultsFound” when using BotBuilder-Location 使用节点计划开始BotBuilder对话框 - Use Node-Schedule to begin a BotBuilder Dialog 在botbuilder中使用api.ai意图 - Use api.ai intents in botbuilder node.js / express应用程序失败,错误为未定义变量 - node.js / express app failing with error that a variable hasn't been defined 使用区域敏感字符串作为数据结构键的有效方法 - Efficient way to use locale sensitive strings as keys to a data structure 如何引用尚未注册的Mongoose模式 - How to reference a Mongoose Schema that hasn't been registered yet 如何自定义提示选择(Microsoft Botbuilder SDK) - How to Customize Prompt Choice (Microsoft Botbuilder SDK) MissingSchemaError:尚未为模型“用户,userSchema”注册架构。 使用 mongoose.model(name, schema) - MissingSchemaError: Schema hasn't been registered for model "User, userSchema". Use mongoose.model(name, schema) MissingSchemaError:尚未为 model“用户”注册架构。 使用 mongoose.model(name, schema) - MissingSchemaError: Schema hasn't been registered for model "User". Use mongoose.model(name, schema) 架构尚未为 model “订单”注册。 使用 mongoose.model(name, schema) 那么哪里出错 - Schema hasn't been registered for model “Order”. Use mongoose.model(name, schema) So where the error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM