[英]Date in arguments using i18n
I'm working on a nodeJs project in typescript我正在用 typescript 开发一个 nodeJs 项目
I use i18n npm package to manage text translation through all the application.我使用 i18n npm 包来管理所有应用程序的文本翻译。 For basic use it's ok.
基本使用没问题。
My issue is with dates, here is the problem:我的问题是日期,这是问题所在:
import * as i18n from 'i18n';
export const translate = (key: string, args = {}): string => {
return i18n.__(key, args);
};
Exemple : resultString = translate('You have an appointement with {{name}} on {{date}}', {
name : 'Mr smith',
date : '20/11/2019',
});
=> resultString is You have an appointement with Mr Smith on 20/11/2019
=> resultString 是
You have an appointement with Mr Smith on 20/11/2019
The character /
is converted to it's hex字符
/
被转换为它的十六进制
Any idea why?知道为什么吗?
EDIT -----编辑 - - -
I tried using unescape()
on the final string but it's not working我尝试在最后一个字符串上使用
unescape()
但它不起作用
I think maybe is just a problem of how the translate service is been used.我认为可能只是翻译服务使用方式的问题。 I try this way and i didn't have any issue:
我尝试这种方式,我没有任何问题:
component.html组件.html
{{'HOME.TEST' | translate:{name: msg.name, date: msg.date} }}
<br>
{{translation()}}
component.ts组件.ts
export class AppComponent {
msg = {name : 'Mr smith', date : '20/11/2019'};
constructor(public translate: TranslateService) {
translate.addLangs(['en', 'fr']);
translate.setDefaultLang('en');
const browserLang = translate.getBrowserLang();
translate.use(browserLang.match(/en|fr/) ? browserLang : 'en');
}
translation() : string {
return this.translate.instant('HOME.TEST', this.msg)
}
}
I leave a link to stackbliz with a demo: https://stackblitz.com/edit/angular-translation-service-tc8tju我留下了带有演示的 stackbliz 链接: https ://stackblitz.com/edit/angular-translation-service-tc8tju
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.