[英]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
. 我为我创建的对话框定义了几个名称空间,例如help
或default
。 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.