我需要使用翻译来自服务器的字符串ngx/翻译 https://github.com/ngx-translate/core.
当我需要翻译字符串时它工作得很好,但在某些情况下我只需要翻译字符串的一部分。
例如:
“你好谢伊”或“你好约翰”
我只需要翻译“你好”并保留名称不变。
我试过:
this.i18n.instant('hello {Shay}')
并在 en.json 文件中:
"你好 {var}": "你好 {var}"
但没有成功。
有什么想法可以做到吗?
您正在寻找参数化翻译。您不需要翻译密钥中的该参数。试试这样:
en.json:
"hello_name": "Hello {{name}}"
控制器:
this.i18n.instant('hello_name', {name: 'Shay'});
或在模板中:
{{ 'hello_name' | translate: {name: 'Shay'} }}
https://github.com/ngx-translate/core#3-define-the-translations https://github.com/ngx-translate/core#3-define-the-translations
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)