vis.js中timeliness的中文化

vis.js的官网中这部分写的不是很清楚,只提到了timeliness的本地化是基于moment.js,如果需要自定义,需要引入moment.js,或者使用moment.js包装好的本地化文件moment-with-locales.min.js,原文如下:

Timeline can be localized. For localization, Timeline depends largely on the localization of moment.js. Locales are not included in vis.js by default. To enable localization, moment.js must be loaded with locales. Moment.js offers a bundle named “moment-with-locales.min.js” for this and there are various alternative ways to load locales.


Create a new locale

To load a locale (that is not supported by default) into the Timeline, one can add a new locale to the option locales:

var options = {
    locales: {
    // create a new locale (text strings should be replaced with localized strings)
    mylocale: {
        current: 'current',
        time: 'time',
    }
  },

// use the new locale
      locale: 'mylocale'
    };

但是文档中没有提到应该如何使用moment.js,在moment.js的官网上也没有看到使用说明,所以我大概地看了一下vis.js这部分的代码实现,逻辑是这样:vis会先检测moment.js是否已经引入,否的话就通过commonjs引入;

module.exports = typeof window !== 'undefined' && window['moment'] || __webpack_require__(3);

在引用了moment-with-locales.min.js文件后,’moment’会被注册,此时在timeline的初始化中调用moment-with-locales.min.js文件中实现的本地化对象来初始化locale属性即可(中文对象名为:’zh-cn’):

var option = {
    ...
    locale: moment.locale('zh-cn'),
    ... 
}

需要注意的是,因为vis会先检测moment对象是否存在,如果不存在则会通过commonJS引入moment.js,但是引入的moment.js没有中文本地化对象,所以需要将moment-with-locales.min.js引入放在vis.js引入之前

优化以下代码: FileMatrixVo fileMatrixVo = new FileMatrixVo(); fileMatrixVo.setId(tableName + "-" + columnName); fileMatrixVo.setCoherenceFiles(errorOutputFiles.stream().filter(errorOutputFileVo -> RuleTemplateName.ENUMERATION_CHECK.getId().equals(errorOutputFileVo.getRuleTemplateId())).collect(Collectors.toList())); fileMatrixVo.setEffectiveFiles(errorOutputFiles.stream().filter(errorOutputFileVo -> RuleTemplateName.REGEXP_CHECK.getId().equals(errorOutputFileVo.getRuleTemplateId())).collect(Collectors.toList())); fileMatrixVo.setCompleteFiles(errorOutputFiles.stream().filter(errorOutputFileVo -> RuleTemplateName.NULL_CHECK.getId().equals(errorOutputFileVo.getRuleTemplateId())).collect(Collectors.toList())); fileMatrixVo.setUniquenessFiles(errorOutputFiles.stream().filter(errorOutputFileVo -> RuleTemplateName.UNIQUENESS_CHECK.getId().equals(errorOutputFileVo.getRuleTemplateId())).collect(Collectors.toList())); fileMatrixVo.setMultiTableConsistency(errorOutputFiles.stream().filter(errorOutputFileVo -> RuleTemplateName.MULTI_TABLE_ACCURACY.getId().equals(errorOutputFileVo.getRuleTemplateId())).collect(Collectors.toList())); fileMatrixVo.setFieldLengthFiles(errorOutputFiles.stream().filter(errorOutputFileVo -> RuleTemplateName.FIELD_LENGTH_CHECK.getId().equals(errorOutputFileVo.getRuleTemplateId())).collect(Collectors.toList())); fileMatrixVo.setTimelinessFiles(errorOutputFiles.stream().filter(errorOutputFileVo -> RuleTemplateName.TIMELINESS_CHECK.getId().equals(errorOutputFileVo.getRuleTemplateId())).collect(Collectors.toList()));
06-07
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值