【问题标题】:i18n how translate text in javascripti18n 如何在 javascript 中翻译文本
【发布时间】:2018-11-29 06:53:27
【问题描述】:

我尝试在 javascript 脚本中翻译一些文本。我有:

i18n: {
  messages: {
    en: {
      i18n_profile_alert:'Please draw a geometry with the Geometry selection',
    },
    de: {
      i18n_profile_alert:'Bitte zeichnen Sie mit der Geometry Auswahl eine Geometry',
    },
  },
},

在 HTML 中,我可以像这样得到我的翻译消息:

<span>{{$t('i18n_profile_alert')}}</span>

但在 javascript 中它不起作用:

entegetGeometry() {
    const drawingUtil = vcs.vcm.util.Drawing.getInstance();
    const drawingId = this.$refs.geometrySelection.getDrawingId();
    if (!drawingId) {
      this.notifyError({{$t('i18n_profile_alert')}});
      return;
    }

如何在 javascript 代码中引用我的消息?

【问题讨论】:

    标签: javascript internationalization translate


    【解决方案1】:

    如果你正在使用 Angular 并且你已经使用 Angular CLI 创建了你的项目,那么你可以使用这个包。 https://www.npmjs.com/package/ng2-translate

    使用 ng2-translate,您可以在项目中使用多种语言翻译。

    【讨论】:

    • 感谢您的快速回复,但我在 Vue.js 项目中使用它。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-26
    • 1970-01-01
    • 2012-11-12
    • 1970-01-01
    • 2018-01-25
    • 1970-01-01
    相关资源
    最近更新 更多