【问题标题】:Jhipster - add translation for new alertsJhipster - 为新警报添加翻译
【发布时间】:2020-05-03 10:42:48
【问题描述】:

为了在用户单击按钮时添加新警报,我按照关于通知系统部分的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 文件夹中的一个或多个文件

【问题讨论】:

  • 是的,您必须输入密钥而不是消息,然后您必须在 src\main\webapp\i18n 中编辑与您的语言和页面以及密钥匹配的文件。
  • @GaëlMarziou 它们的键是否应该类似于传递给jhiTranslate 属性的键?我明白这是怎么回事。
  • 是的,这是同一个键,它可以是使用点符号的路径。
  • @GaëlMarziou 效果很好。谢谢你的帮助!

标签: angular internationalization jhipster alert


【解决方案1】:

喜欢@GaëlMarziou在问题的cmets中回答:

如果您在项目中启用了国际化,则在 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",
      "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!"
  }
}

然后你应该对你配置的其他语言做同样的事情。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-07
    • 2017-03-13
    • 2017-07-12
    • 2017-08-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多