Jhipster-为新警报添加翻译



为了在用户单击按钮时添加新警报,我遵循了jhipster官方网站上关于通知系统部分的说明。

当用户点击按钮时执行的功能现在看起来是这样的:

randomMethod():void {
this.alertService.get().push(
this.alertService.addAlert(
{
type: 'danger',
msg: 'you should not have pressed this button!',
timeout: 3000,
toast: false,
scoped: true
},
this.alertService.get()
)
);

新的警报确实会显示,但由于我启用了国际化,我的警报消息显示如下:

translation-not-found[you should not have pressed this button!]

我需要做些什么来配置警报的翻译?

编辑:它认为我需要修改src\main\webapp\i18n文件夹中的一个或多个文件

Like@GaëlMarziou在问题的评论中回答:

如果在项目中启用了国际化,则在msg属性中不会引入消息本身。相反,您必须提供一个指向srcmainwebappi18n中与语言、键和页面匹配的文件的键。

例如,如果您想在主页中放置警报,并且您选择了英语作为语言,则必须执行以下操作:

randomMethod():void {
this.alertService.get().push(
this.alertService.addAlert(
{
type: 'danger',
msg: 'yourAppName.home.buttonAllertMessage',
timeout: 3000,
toast: false,
scoped: true
},
this.alertService.get()
)
);

您必须在srcmainwebappi18nenhome.json文件中添加新属性(buttonAllertMessage(,如下所示:

{
"home": {
"title": "Welcome",
"subtitle": "This is your homepage",
"logged": {
"message": "You are logged in as user "{{username}}"."
},
"question": "If you have any question on JHipster:",
"link": {
"homepage": "JHipster homepage",
"stackoverflow": "JHipster on Stack Overflow",
"bugtracker": "JHipster bug tracker",
"chat": "JHipster public chat room",
"follow": "follow @jhipster on Twitter"
},
"like": "If you like JHipster, don't forget to give us a star on",
"github": "GitHub",
"buttonAllertMessage" : "you should not have pressed this button!"
}
}

然后,您应该对您配置的其他语言执行同样的操作。

最新更新