修改fileMatcher中的模式错误
This commit is contained in:
parent
5dc3727119
commit
8e61c363e4
@ -21,7 +21,7 @@ module.exports = function(options={}){
|
||||
* @param {*} texts 多条文本
|
||||
* @returns
|
||||
*/
|
||||
translate:async (texts=[],from,to)=>{
|
||||
translate:async (texts=[],from="zh",to="en")=>{
|
||||
|
||||
if(Array.isArray(texts)){
|
||||
texts = texts.join("\n");
|
||||
|
@ -10,8 +10,7 @@ const deepmerge = require("deepmerge")
|
||||
const path = require('path')
|
||||
const fs = require('fs-extra')
|
||||
const createLogger = require("logsets")
|
||||
const { t } = require("./i18nProxy")
|
||||
const { findModuleType } = require("@voerkai18n/utils")
|
||||
const { t } = require("./i18nProxy")
|
||||
|
||||
|
||||
const logger = createLogger()
|
||||
@ -105,7 +104,7 @@ function extractTranslateTextUseRegexp(content,namespace,extractor,file,options)
|
||||
// 移除代码中的注释,以便正则表达式提取翻译文本时排除注释部分
|
||||
const fileExtName = file.extname.substr(1).toLowerCase() // 文件扩展名
|
||||
content = removeComments(content,fileExtName)
|
||||
|
||||
let result
|
||||
let texts = {}
|
||||
while ((result = extractor.exec(content)) !== null) {
|
||||
// 这对于避免零宽度匹配的无限循环是必要的
|
||||
@ -156,7 +155,7 @@ function extractTranslateTextUseFunction(content,namespace,extractor,file,option
|
||||
* @param {*} extractor 提取器配置={default:[],js:[],html:[],"sass,css":[],json:[],"*":[]}"}
|
||||
*/
|
||||
function getFileTypeExtractors(filetype,extractor){
|
||||
if(!typeof(extractor)==="object") return null
|
||||
if(!typeof(extractor)=="object") return null
|
||||
let matchers=[]
|
||||
for(let [key,value] of Object.entries(extractor)){
|
||||
if(filetype.toLowerCase()===key.toLowerCase()){
|
||||
@ -395,7 +394,7 @@ module.exports = function(options={}){
|
||||
logger.log(t("激活语言\t: {}"),options.activeLanguage)
|
||||
logger.log(t("名称空间\t: {}"),Object.keys(options.namespaces).join(","))
|
||||
logger.log("")
|
||||
logger
|
||||
|
||||
// 保存提交提取的文本 = {}
|
||||
let results = {}
|
||||
let fileCount=0 // 文件总数
|
||||
|
@ -6,8 +6,7 @@ const path = require("path")
|
||||
const fs = require("fs-extra")
|
||||
const logger = createLogger()
|
||||
const { i18nScope ,t } = require("./i18nProxy")
|
||||
const { getProjectRootFolder, getProjectSourceFolder } = require("@voerkai18n/utils");
|
||||
const { translate } = require('../runtime/dist/index.cjs');
|
||||
const { getProjectSourceFolder } = require("@voerkai18n/utils");
|
||||
|
||||
logger.use(bannerPluin)
|
||||
|
||||
@ -106,7 +105,7 @@ program
|
||||
logger.error(t("语言包文件夹<{}>不存在",langFolder))
|
||||
return
|
||||
}
|
||||
compile = require("./compile.command")
|
||||
let compile = require("./compile.command")
|
||||
compile(langFolder,options)
|
||||
});
|
||||
|
||||
|
@ -121,6 +121,8 @@ var eventemitter = class EventEmitter{
|
||||
}
|
||||
};
|
||||
|
||||
const DataTypes$1 = ["String","Number","Boolean","Object","Array","Function","Null","Undefined","Symbol","Date","RegExp","Error"];
|
||||
|
||||
var scope = class i18nScope {
|
||||
constructor(options={},callback){
|
||||
// 每个作用域都有一个唯一的id
|
||||
@ -187,7 +189,7 @@ var scope = class i18nScope {
|
||||
if(!typeof(formatter)==="function" || typeof(name)!=="string"){
|
||||
throw new TypeError("Formatter must be a function")
|
||||
}
|
||||
if(DataTypes.includes(name)){
|
||||
if(DataTypes$1.includes(name)){
|
||||
this.formatters[language].$types[name] = formatter;
|
||||
}else {
|
||||
this.formatters[language][name] = formatter;
|
||||
@ -325,7 +327,7 @@ let varWithPipeRegexp = /\{\s*(?<varname>\w+)?(?<formatters>(\s*\|\s*\w*(\(.*\))
|
||||
function hasInterpolation(str){
|
||||
return str.includes("{") && str.includes("}")
|
||||
}
|
||||
const DataTypes$1 = ["String","Number","Boolean","Object","Array","Function","Error","Symbol","RegExp","Date","Null","Undefined","Set","Map","WeakSet","WeakMap"];
|
||||
const DataTypes = ["String","Number","Boolean","Object","Array","Function","Error","Symbol","RegExp","Date","Null","Undefined","Set","Map","WeakSet","WeakMap"];
|
||||
|
||||
|
||||
/**
|
||||
@ -915,7 +917,7 @@ function translate(message) {
|
||||
if(!typeof(formatter)==="function" || typeof(name)!=="string"){
|
||||
throw new TypeError("Formatter must be a function")
|
||||
}
|
||||
if(DataTypes$1.includes(name)){
|
||||
if(DataTypes.includes(name)){
|
||||
this.formatters[language].$types[name] = formatter;
|
||||
}else {
|
||||
this.formatters[language][name] = formatter;
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@voerkai18n/cli",
|
||||
"version": "1.0.28",
|
||||
"version": "1.0.29",
|
||||
"description": "VoerkaI18n command line interactive tools",
|
||||
"main": "index.js",
|
||||
"homepage": "https://gitee.com/zhangfisher/voerka-i18n",
|
||||
@ -50,5 +50,5 @@
|
||||
"devDependencies": {
|
||||
"@voerkai18n/autopublish": "workspace:^1.0.2"
|
||||
},
|
||||
"lastPublish": "2022-04-15T17:44:50+08:00"
|
||||
"lastPublish": "2022-04-16T09:12:24+08:00"
|
||||
}
|
@ -63,7 +63,7 @@ function getTranslateProvider(options={}){
|
||||
* @param {*} options
|
||||
* @returns
|
||||
*/
|
||||
async function translateMessages(messages={},from,to,options={}){
|
||||
async function translateMessages(messages={},from="zh",to="en",options={}){
|
||||
let { mode,qps=1 } = options
|
||||
if(messages.length===0) return;
|
||||
const provider = getTranslateProvider(options)
|
||||
@ -82,6 +82,7 @@ async function translateMessages(messages={},from,to,options={}){
|
||||
*/
|
||||
async function translateMultiLineMessage(messages=[],from,to,options={}){
|
||||
if(messages.length===0) return;
|
||||
const qps = options.qps || 1
|
||||
const provider = getTranslateProvider(options)
|
||||
await delay(1000/qps)
|
||||
let result = await provider.translate(messages,from,to)
|
||||
@ -125,7 +126,6 @@ async function translateLanguage(messages,from,to,options={}){
|
||||
}
|
||||
// 对剩余的信息进行翻译
|
||||
if(Object.keys(lngMessages).length > 0){
|
||||
requestCount++
|
||||
await translateMessages(lngMessages,from,to,options)
|
||||
result = deepMerge(result,lngMessages)
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
import React, { useState, useEffect,useCallback } from 'react';
|
||||
import React, { useState, useEffect } from 'react';
|
||||
|
||||
/**
|
||||
* MyComponent(){
|
||||
@ -9,7 +9,7 @@ import React, { useState, useEffect,useCallback } from 'react';
|
||||
*
|
||||
*
|
||||
*/
|
||||
export function useVoerkaI18n(i18nScope) {
|
||||
export function useVoerkaI18n() {
|
||||
|
||||
if(!globalThis.VoerkaI18n){
|
||||
console.warn("useI18nContext is not provided, use default i18nContext")
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@voerkai18n/react",
|
||||
"version": "1.0.3",
|
||||
"version": "1.0.4",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
@ -15,5 +15,5 @@
|
||||
"devDependencies": {
|
||||
"@voerkai18n/autopublish": "workspace:^1.0.2"
|
||||
},
|
||||
"lastPublish": "2022-04-15T17:53:30+08:00"
|
||||
"lastPublish": "2022-04-16T09:12:12+08:00"
|
||||
}
|
2
packages/runtime/dist/index.cjs
vendored
2
packages/runtime/dist/index.cjs
vendored
File diff suppressed because one or more lines are too long
2
packages/runtime/dist/index.cjs.map
vendored
2
packages/runtime/dist/index.cjs.map
vendored
File diff suppressed because one or more lines are too long
2
packages/runtime/dist/index.esm.js
vendored
2
packages/runtime/dist/index.esm.js
vendored
File diff suppressed because one or more lines are too long
2
packages/runtime/dist/index.esm.js.map
vendored
2
packages/runtime/dist/index.esm.js.map
vendored
File diff suppressed because one or more lines are too long
8
packages/runtime/dist/runtime.cjs
vendored
8
packages/runtime/dist/runtime.cjs
vendored
@ -121,6 +121,8 @@ var eventemitter = class EventEmitter{
|
||||
}
|
||||
};
|
||||
|
||||
const DataTypes$1 = ["String","Number","Boolean","Object","Array","Function","Null","Undefined","Symbol","Date","RegExp","Error"];
|
||||
|
||||
var scope = class i18nScope {
|
||||
constructor(options={},callback){
|
||||
// 每个作用域都有一个唯一的id
|
||||
@ -187,7 +189,7 @@ var scope = class i18nScope {
|
||||
if(!typeof(formatter)==="function" || typeof(name)!=="string"){
|
||||
throw new TypeError("Formatter must be a function")
|
||||
}
|
||||
if(DataTypes.includes(name)){
|
||||
if(DataTypes$1.includes(name)){
|
||||
this.formatters[language].$types[name] = formatter;
|
||||
}else {
|
||||
this.formatters[language][name] = formatter;
|
||||
@ -325,7 +327,7 @@ let varWithPipeRegexp = /\{\s*(?<varname>\w+)?(?<formatters>(\s*\|\s*\w*(\(.*\))
|
||||
function hasInterpolation(str){
|
||||
return str.includes("{") && str.includes("}")
|
||||
}
|
||||
const DataTypes$1 = ["String","Number","Boolean","Object","Array","Function","Error","Symbol","RegExp","Date","Null","Undefined","Set","Map","WeakSet","WeakMap"];
|
||||
const DataTypes = ["String","Number","Boolean","Object","Array","Function","Error","Symbol","RegExp","Date","Null","Undefined","Set","Map","WeakSet","WeakMap"];
|
||||
|
||||
|
||||
/**
|
||||
@ -915,7 +917,7 @@ function translate(message) {
|
||||
if(!typeof(formatter)==="function" || typeof(name)!=="string"){
|
||||
throw new TypeError("Formatter must be a function")
|
||||
}
|
||||
if(DataTypes$1.includes(name)){
|
||||
if(DataTypes.includes(name)){
|
||||
this.formatters[language].$types[name] = formatter;
|
||||
}else {
|
||||
this.formatters[language][name] = formatter;
|
||||
|
8
packages/runtime/dist/runtime.mjs
vendored
8
packages/runtime/dist/runtime.mjs
vendored
@ -119,6 +119,8 @@ var eventemitter = class EventEmitter{
|
||||
}
|
||||
};
|
||||
|
||||
const DataTypes$1 = ["String","Number","Boolean","Object","Array","Function","Null","Undefined","Symbol","Date","RegExp","Error"];
|
||||
|
||||
var scope = class i18nScope {
|
||||
constructor(options={},callback){
|
||||
// 每个作用域都有一个唯一的id
|
||||
@ -185,7 +187,7 @@ var scope = class i18nScope {
|
||||
if(!typeof(formatter)==="function" || typeof(name)!=="string"){
|
||||
throw new TypeError("Formatter must be a function")
|
||||
}
|
||||
if(DataTypes.includes(name)){
|
||||
if(DataTypes$1.includes(name)){
|
||||
this.formatters[language].$types[name] = formatter;
|
||||
}else {
|
||||
this.formatters[language][name] = formatter;
|
||||
@ -323,7 +325,7 @@ let varWithPipeRegexp = /\{\s*(?<varname>\w+)?(?<formatters>(\s*\|\s*\w*(\(.*\))
|
||||
function hasInterpolation(str){
|
||||
return str.includes("{") && str.includes("}")
|
||||
}
|
||||
const DataTypes$1 = ["String","Number","Boolean","Object","Array","Function","Error","Symbol","RegExp","Date","Null","Undefined","Set","Map","WeakSet","WeakMap"];
|
||||
const DataTypes = ["String","Number","Boolean","Object","Array","Function","Error","Symbol","RegExp","Date","Null","Undefined","Set","Map","WeakSet","WeakMap"];
|
||||
|
||||
|
||||
/**
|
||||
@ -913,7 +915,7 @@ function translate(message) {
|
||||
if(!typeof(formatter)==="function" || typeof(name)!=="string"){
|
||||
throw new TypeError("Formatter must be a function")
|
||||
}
|
||||
if(DataTypes$1.includes(name)){
|
||||
if(DataTypes.includes(name)){
|
||||
this.formatters[language].$types[name] = formatter;
|
||||
}else {
|
||||
this.formatters[language][name] = formatter;
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@voerkai18n/runtime",
|
||||
"version": "1.0.23",
|
||||
"version": "1.0.24",
|
||||
"description": "Voerkai18n Runtime",
|
||||
"main": "./dist/index.cjs",
|
||||
"module": "dist/index.esm.js",
|
||||
@ -35,5 +35,5 @@
|
||||
"rollup-plugin-terser": "^7.0.2",
|
||||
"@voerkai18n/autopublish": "workspace:^1.0.2"
|
||||
},
|
||||
"lastPublish": "2022-04-15T17:44:08+08:00"
|
||||
"lastPublish": "2022-04-16T09:12:02+08:00"
|
||||
}
|
@ -1,4 +1,7 @@
|
||||
|
||||
|
||||
const DataTypes = ["String","Number","Boolean","Object","Array","Function","Null","Undefined","Symbol","Date","RegExp","Error"];
|
||||
|
||||
module.exports = class i18nScope {
|
||||
constructor(options={},callback){
|
||||
// 每个作用域都有一个唯一的id
|
||||
|
@ -16,7 +16,8 @@ const fs = require("fs-extra")
|
||||
* debug:<true/>false,是否输出调试信息,当=true时,.test()方法返回[<true/false>,pattern] *
|
||||
* })
|
||||
*
|
||||
*
|
||||
* matcher.test("<文件名称>") 返回true/false
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param {*} patterns
|
||||
@ -35,6 +36,9 @@ const fs = require("fs-extra")
|
||||
|
||||
// 默认排除模式
|
||||
if(defaultPatterns.length===0){
|
||||
finalPatterns.push([/__test__\/.*/,true])
|
||||
finalPatterns.push([/.*\/.*\.test\.js$/,true])
|
||||
finalPatterns.push([/node_modules\/.*/,true])
|
||||
finalPatterns.push([/.*\/node_modules\/.*/,true])
|
||||
finalPatterns.push([/.*\/languages\/.*/,true]) // 默认排除语言文件
|
||||
finalPatterns.push([/\.babelrc/,true])
|
||||
@ -46,15 +50,21 @@ const fs = require("fs-extra")
|
||||
|
||||
inputPatterns.forEach(pattern=>{
|
||||
if(typeof pattern === "string"){
|
||||
pattern.replaceAll("**",".*")
|
||||
pattern.replaceAll("?","[^\/]?")
|
||||
pattern.replaceAll(/(?<!\.)\*/g,"[^\/]*")
|
||||
// 以!开头的表示排除
|
||||
if(pattern.startsWith("!")){
|
||||
finalPatterns.unshift([new RegExp(pattern.substring(1),"g"),true])
|
||||
}else{
|
||||
finalPatterns.push([new RegExp(pattern,"g"),false])
|
||||
}
|
||||
pattern = pattern.replaceAll("**",".*")
|
||||
.replaceAll("?","[^\/]?")
|
||||
.replaceAll(/(?<!\.)\*/g,"[^\/]*")
|
||||
try{
|
||||
// 以!开头的表示排除
|
||||
if(pattern.startsWith("!")){
|
||||
finalPatterns.unshift([new RegExp(pattern.substring(1),"g"),true])
|
||||
}else{
|
||||
finalPatterns.push([new RegExp(pattern,"g"),false])
|
||||
}
|
||||
}catch(e){
|
||||
if(debug){
|
||||
console.error(`${pattern} is not a valid pattern`)
|
||||
}
|
||||
}
|
||||
}else{
|
||||
finalPatterns.push([pattern,false])
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@voerkai18n/vite",
|
||||
"version": "1.0.9",
|
||||
"version": "1.0.10",
|
||||
"description": "VoerkaI18n plugin for Vite",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
@ -15,5 +15,5 @@
|
||||
"devDependencies": {
|
||||
"@voerkai18n/autopublish": "workspace:^1.0.2"
|
||||
},
|
||||
"lastPublish": "2022-04-15T17:45:00+08:00"
|
||||
"lastPublish": "2022-04-16T09:12:34+08:00"
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
const path = require("path")
|
||||
|
||||
const fs = require("fs")
|
||||
/**
|
||||
*
|
||||
* 匹配指定路径或文件名称
|
||||
|
@ -67,6 +67,9 @@ function resetTestApp(){
|
||||
}
|
||||
|
||||
beforeAll(() => {
|
||||
shelljs.exec("pnpm add -g @voerkai18n/utils")
|
||||
shelljs.exec("pnpm add -g @voerkai18n/runtime ")
|
||||
shelljs.exec("pnpm add -g @voerkai18n/cli ")
|
||||
shelljs.exec("pnpm update -g @voerkai18n/utils")
|
||||
shelljs.exec("pnpm update -g @voerkai18n/runtime ")
|
||||
shelljs.exec("pnpm update -g @voerkai18n/cli ")
|
||||
|
Loading…
x
Reference in New Issue
Block a user