标签:this component sort e30 tran static repeat 标签 amp
// import Translate from ‘translate-components‘ /* * 匹配所有汉字RegExp: [\u4e00-\u9fa5] [\u4E00-\u9FA5]|[\uFE30-\uFFA0] * 汉字部分除了^的标签jsonRegExp: <Translate>[^\^]+?(?=-{4,}?)-{4,}?([a-zA-Z]+)</Translate> t(‘$1‘) * 汉字部分除换行符之外的任意字符的标签jsonRegExp: <Translate>(?:\^).+?(?=-{4,}?)-{4,}?([a-zA-Z]+)</Translate> */ function regExpStrToJson(strCount, language, isDocument) { var translation = ‘{\n‘; for (var i=0; i<strCount.length; i++) { var suffix = strCount.length === (i + 1) ? ‘"\n‘ : ‘",\n‘; var patch1 = /(?<=sign\(‘)(.+?)(?=‘\);;;?)/g; var result1 = patch1.exec(strCount[i]); translation += ‘ "‘ + RegExp.$1; // var patch2 = language === ‘cn‘ ? /(?<=cn\(‘)(.+?)(?=‘\);;;?)/g : /(?<=tl\(‘)(.+?)(?=‘\);;;?)/g; var patch2 = new RegExp("(?<=" + language + "\\(‘)(.+?)(?=‘\\);;;?)","g"); var result2 = patch2.exec(strCount[i]); translation += ‘": "‘ + RegExp.$1.replace(‘^‘, ‘‘) + suffix; } translation += ‘}‘; isDocument ? $(‘body‘).html(translation.replace(/\n/g, ‘<br>‘).replace(/\s{4}/g, ‘ ‘)) : console.log(translation); } var strToArr = ‘‘, tlStr = ‘???????????????????????????‘; $.ajax(‘./static/translations.json‘,{ dataType:‘json‘, type:‘get‘, success:function(data){ let repeatObj = {}; for (key in data) { let thisKey = key.split(/-{4,}/); if (repeatObj[thisKey[1]] === undefined) { repeatObj[thisKey[1]] = 1; strToArr += "sign(‘" + thisKey[1] + "‘);;;cn(‘" + thisKey[0] + "‘);;;tl(‘" + tlStr.split(‘‘).sort(() => Math.random() > 0.5 ? -1 : 1).join(‘‘).substring(0, parseInt(Math.random() * (tlStr.length - 1) + 5)) + "‘);;;\n"; } } let strArr = strToArr.split(‘\n‘); regExpStrToJson(strArr, ‘cn‘, 1); regExpStrToJson(strArr, ‘tl‘); } });
标签:this component sort e30 tran static repeat 标签 amp
原文地址:https://www.cnblogs.com/universe-cosmo/p/10969726.html