首页 > 解决方案 > 角度 8 中的 AWS Amplify i18n 国际化

问题描述

翻译.ts

const dict = {
   'bh': {
      'Hello there!': "Apa khabar di sana!"   
  },
  'ch': {
      'Hello there!': "你好!"
  }
};

I18n.putVocabularies(dict);
I18n.setLanguage('ch');
I18n.get('Hello there!');

翻译.html

<h3>(how to call function to get translation)</h3>

我正在尝试使用 AWS amplify i18n 功能翻译不同语言的网站文本。我正在关注 AWS-amplify 参考https://docs.amplify.aws/lib/utilities/i18n/q/platform/js#setlanguage

但我正在努力从 HTML 调用函数以用中文显示。

标签: javascriptangulartypescriptaws-amplify

解决方案


您的“get”未分配给变量。尝试将 get 分配给变量并将其绑定到 UI。

this.text = I18n.get('Hello There');

然后在你的 HTML

<p>{{text}}</p>

推荐阅读