Jhipster - 为新警报添加翻译
Jhipster - add translation for new alerts
为了在用户单击按钮时添加新警报,我按照 jhipster official website 关于 通知系统 部分的说明进行操作。
用户单击按钮时执行的函数现在如下所示:
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 文件夹中的一个或多个文件
喜欢 @GaëlMarziou 在问题的评论中回答:
如果您在项目中启用了国际化,则在 msg
属性 中您将不会引入消息本身。相反,您必须提供指向 src\main\webapp\i18n
中匹配语言、密钥和页面的文件的密钥。
例如,如果您想在 主页 中放置提醒,并且您已选择 英语 作为语言,你将不得不做这样的事情:
randomMethod():void {
this.alertService.get().push(
this.alertService.addAlert(
{
type: 'danger',
msg: 'yourAppName.home.buttonAllertMessage',
timeout: 3000,
toast: false,
scoped: true
},
this.alertService.get()
)
);
并且您必须像这样在 src\main\webapp\i18n\en\home.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",
"Whosebug": "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!"
}
}
然后您应该对您配置的其他语言执行相同的操作。
为了在用户单击按钮时添加新警报,我按照 jhipster official website 关于 通知系统 部分的说明进行操作。
用户单击按钮时执行的函数现在如下所示:
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 文件夹中的一个或多个文件
喜欢 @GaëlMarziou 在问题的评论中回答:
如果您在项目中启用了国际化,则在 msg
属性 中您将不会引入消息本身。相反,您必须提供指向 src\main\webapp\i18n
中匹配语言、密钥和页面的文件的密钥。
例如,如果您想在 主页 中放置提醒,并且您已选择 英语 作为语言,你将不得不做这样的事情:
randomMethod():void {
this.alertService.get().push(
this.alertService.addAlert(
{
type: 'danger',
msg: 'yourAppName.home.buttonAllertMessage',
timeout: 3000,
toast: false,
scoped: true
},
this.alertService.get()
)
);
并且您必须像这样在 src\main\webapp\i18n\en\home.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",
"Whosebug": "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!"
}
}
然后您应该对您配置的其他语言执行相同的操作。