vite-gc-i18n-plugin 1.1.8 → 1.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +82 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +82 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -924,7 +924,7 @@ function createTextSplitter(values, maxChunkSize) {
|
|
|
924
924
|
*/
|
|
925
925
|
function splitByRegex(str, separatorRegex) {
|
|
926
926
|
// 定义标点符号的正则表达式
|
|
927
|
-
const punctuationRegex = /[
|
|
927
|
+
const punctuationRegex = /[,。?!《》()(),..:!?""'';'"、0-9\n\r\t\v\f]/;
|
|
928
928
|
// 创建一个新的正则表达式,用于分割字符串
|
|
929
929
|
const splitRegex = new RegExp(`(${separatorRegex.source}|${punctuationRegex.source})`, separatorRegex.flags);
|
|
930
930
|
|
|
@@ -934,7 +934,7 @@ function splitByRegex(str, separatorRegex) {
|
|
|
934
934
|
let currentMatch = '';
|
|
935
935
|
|
|
936
936
|
// 定义连接标点符号的正则表达式
|
|
937
|
-
const connectPunctuationRegex = /[
|
|
937
|
+
const connectPunctuationRegex = /[,。?!《》()(),..:!?;'"、0-9]/;
|
|
938
938
|
// 创建一个新的正则表达式,用于检测是否需要连接
|
|
939
939
|
const connectRegex = new RegExp(`(${separatorRegex.source}|${connectPunctuationRegex.source})`, separatorRegex.flags);
|
|
940
940
|
|
|
@@ -981,7 +981,85 @@ function splitByRegex(str, separatorRegex) {
|
|
|
981
981
|
if (tempStr) {
|
|
982
982
|
finalResult.push(tempStr);
|
|
983
983
|
}
|
|
984
|
-
return finalResult;
|
|
984
|
+
return mergeInlineTextSeparatedOriginChunks(finalResult, separatorRegex);
|
|
985
|
+
}
|
|
986
|
+
function mergeInlineTextSeparatedOriginChunks(strArray, separatorRegex) {
|
|
987
|
+
const result = [];
|
|
988
|
+
for (let i = 0; i < strArray.length; i++) {
|
|
989
|
+
let current = strArray[i];
|
|
990
|
+
if (!separatorRegex.test(current) && i + 1 < strArray.length && separatorRegex.test(strArray[i + 1])) {
|
|
991
|
+
const {
|
|
992
|
+
beforeInlineText,
|
|
993
|
+
inlineText
|
|
994
|
+
} = splitTrailingInlineText(current);
|
|
995
|
+
if (inlineText && /[^\s\u00a0]/.test(inlineText)) {
|
|
996
|
+
if (beforeInlineText) {
|
|
997
|
+
result.push(beforeInlineText);
|
|
998
|
+
}
|
|
999
|
+
current = `${normalizeInlineTextPrefix(inlineText)}${strArray[i + 1]}`;
|
|
1000
|
+
i += 1;
|
|
1001
|
+
}
|
|
1002
|
+
}
|
|
1003
|
+
if (!separatorRegex.test(current) && isInlineTextSeparator(current) && /[^\s\u00a0]/.test(current) && i + 1 < strArray.length && separatorRegex.test(strArray[i + 1])) {
|
|
1004
|
+
current = `${normalizeInlineTextPrefix(current)}${strArray[i + 1]}`;
|
|
1005
|
+
i += 1;
|
|
1006
|
+
}
|
|
1007
|
+
if (separatorRegex.test(current)) {
|
|
1008
|
+
while (i + 2 < strArray.length && isInlineTextSeparator(strArray[i + 1]) && separatorRegex.test(strArray[i + 2])) {
|
|
1009
|
+
current += `${normalizeInlineTextSeparator(strArray[i + 1])}${strArray[i + 2]}`;
|
|
1010
|
+
i += 2;
|
|
1011
|
+
}
|
|
1012
|
+
if (i + 1 < strArray.length) {
|
|
1013
|
+
const {
|
|
1014
|
+
inlineText,
|
|
1015
|
+
rest
|
|
1016
|
+
} = splitLeadingInlineText(strArray[i + 1]);
|
|
1017
|
+
if (inlineText) {
|
|
1018
|
+
current += normalizeInlineTextSeparator(inlineText);
|
|
1019
|
+
strArray[i + 1] = rest;
|
|
1020
|
+
}
|
|
1021
|
+
}
|
|
1022
|
+
}
|
|
1023
|
+
if (current) {
|
|
1024
|
+
result.push(current);
|
|
1025
|
+
}
|
|
1026
|
+
}
|
|
1027
|
+
return result;
|
|
1028
|
+
}
|
|
1029
|
+
function isInlineTextSeparator(value) {
|
|
1030
|
+
return value !== '' && !/[<>]/.test(value);
|
|
1031
|
+
}
|
|
1032
|
+
function normalizeInlineTextSeparator(value) {
|
|
1033
|
+
return /^[\s\u00a0]+$/.test(value) ? ' ' : value.replace(/[\s\u00a0]+/g, ' ');
|
|
1034
|
+
}
|
|
1035
|
+
function normalizeInlineTextPrefix(value) {
|
|
1036
|
+
return value.replace(/[\s\u00a0]+/g, ' ').trimStart();
|
|
1037
|
+
}
|
|
1038
|
+
function splitLeadingInlineText(value) {
|
|
1039
|
+
const tagIndex = value.search(/[<>]/);
|
|
1040
|
+
if (tagIndex === -1) {
|
|
1041
|
+
return {
|
|
1042
|
+
inlineText: value,
|
|
1043
|
+
rest: ''
|
|
1044
|
+
};
|
|
1045
|
+
}
|
|
1046
|
+
return {
|
|
1047
|
+
inlineText: value.slice(0, tagIndex),
|
|
1048
|
+
rest: value.slice(tagIndex)
|
|
1049
|
+
};
|
|
1050
|
+
}
|
|
1051
|
+
function splitTrailingInlineText(value) {
|
|
1052
|
+
const tagEndIndex = value.lastIndexOf('>');
|
|
1053
|
+
if (tagEndIndex === -1) {
|
|
1054
|
+
return {
|
|
1055
|
+
beforeInlineText: '',
|
|
1056
|
+
inlineText: value
|
|
1057
|
+
};
|
|
1058
|
+
}
|
|
1059
|
+
return {
|
|
1060
|
+
beforeInlineText: value.slice(0, tagEndIndex + 1),
|
|
1061
|
+
inlineText: value.slice(tagEndIndex + 1)
|
|
1062
|
+
};
|
|
985
1063
|
}
|
|
986
1064
|
|
|
987
1065
|
/**
|
|
@@ -991,7 +1069,7 @@ function splitByRegex(str, separatorRegex) {
|
|
|
991
1069
|
*/
|
|
992
1070
|
function checkNeedSplit(str) {
|
|
993
1071
|
// 检查字符串中是否包含需要切割的特殊字符
|
|
994
|
-
return str.includes('
|
|
1072
|
+
return str.includes('\\') || str.includes('>') || str.includes('<');
|
|
995
1073
|
}
|
|
996
1074
|
|
|
997
1075
|
/**
|