多语言修改
This commit is contained in:
parent
23c2a54bef
commit
8125c95929
@ -470,7 +470,7 @@ ExcelExportToAsset()
|
|||||||
```
|
```
|
||||||
|
|
||||||
对齐规则:
|
对齐规则:
|
||||||
1. **带前缀 `![n]`** — 按 n 值匹配中文对应的 `**<[n]id>**`
|
1. **带前缀 `![n]`** — 按 n 值匹配中文对应的 `**<![n]id>**`
|
||||||
2. **无前缀** — 按出现顺序依次对齐
|
2. **无前缀** — 按出现顺序依次对齐
|
||||||
|
|
||||||
#### 运行时解析
|
#### 运行时解析
|
||||||
|
|||||||
@ -1300,10 +1300,10 @@ namespace Logic.Editor
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查是否以 [n] 开头
|
// 检查是否以 ![n] 或历史格式 [n] 开头
|
||||||
string prefix = null;
|
string prefix = null;
|
||||||
string actualStr = innerContent;
|
string actualStr = innerContent;
|
||||||
var prefixRegex = new Regex(@"^!\[([^\]]*)\](.*)$", RegexOptions.Singleline);
|
var prefixRegex = new Regex(@"^!?\[([^\]]*)\](.*)$", RegexOptions.Singleline);
|
||||||
var prefixMatch = prefixRegex.Match(innerContent);
|
var prefixMatch = prefixRegex.Match(innerContent);
|
||||||
if (prefixMatch.Success)
|
if (prefixMatch.Success)
|
||||||
{
|
{
|
||||||
@ -1323,6 +1323,15 @@ namespace Logic.Editor
|
|||||||
if (uint.TryParse(actualStr, out var strId))
|
if (uint.TryParse(actualStr, out var strId))
|
||||||
{
|
{
|
||||||
_activeSet.Add(strId);
|
_activeSet.Add(strId);
|
||||||
|
if (prefix != null)
|
||||||
|
{
|
||||||
|
var canonical = $"**<![{prefix}]{strId}>**";
|
||||||
|
if (match.Value != canonical)
|
||||||
|
{
|
||||||
|
replaced = replaced.Substring(0, match.Index) + canonical +
|
||||||
|
replaced.Substring(match.Index + match.Length);
|
||||||
|
}
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (string.IsNullOrEmpty(actualStr)) continue;
|
if (string.IsNullOrEmpty(actualStr)) continue;
|
||||||
@ -1344,7 +1353,7 @@ namespace Logic.Editor
|
|||||||
string replacement;
|
string replacement;
|
||||||
if (prefix != null)
|
if (prefix != null)
|
||||||
{
|
{
|
||||||
replacement = $"**<[{prefix}]{subId}>**";
|
replacement = $"**<![{prefix}]{subId}>**";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@ -198,7 +198,7 @@ namespace Logic.Multilingual
|
|||||||
var origin = item.GetStrByType(type);
|
var origin = item.GetStrByType(type);
|
||||||
if (string.IsNullOrEmpty(origin)) return result;
|
if (string.IsNullOrEmpty(origin)) return result;
|
||||||
|
|
||||||
var regex = new Regex(@"\*\*<(?:!\[(\d+)\])?(\d+)>\*\*");
|
var regex = new Regex(@"\*\*<(?:!?\[(\d+)\])?(\d+)>\*\*");
|
||||||
var matches = regex.Matches(origin);
|
var matches = regex.Matches(origin);
|
||||||
foreach (Match m in matches)
|
foreach (Match m in matches)
|
||||||
{
|
{
|
||||||
@ -216,7 +216,7 @@ namespace Logic.Multilingual
|
|||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(origin)) return string.Empty;
|
if (string.IsNullOrEmpty(origin)) return string.Empty;
|
||||||
|
|
||||||
var regex = new Regex(@"\*\*<(?:!\[(\d+)\])?(\d+)>\*\*");
|
var regex = new Regex(@"\*\*<(?:!?\[(\d+)\])?(\d+)>\*\*");
|
||||||
var result = regex.Replace(origin, m =>
|
var result = regex.Replace(origin, m =>
|
||||||
{
|
{
|
||||||
var prefixGroup = m.Groups[1]; // [n] 中的 n
|
var prefixGroup = m.Groups[1]; // [n] 中的 n
|
||||||
@ -255,7 +255,7 @@ namespace Logic.Multilingual
|
|||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(origin)) return string.Empty;
|
if (string.IsNullOrEmpty(origin)) return string.Empty;
|
||||||
|
|
||||||
var regex = new Regex(@"\*\*<(?:!\[(\d+)\])?(\d+)>\*\*");
|
var regex = new Regex(@"\*\*<(?:!?\[(\d+)\])?(\d+)>\*\*");
|
||||||
var result = regex.Replace(origin, m =>
|
var result = regex.Replace(origin, m =>
|
||||||
{
|
{
|
||||||
var prefixGroup = m.Groups[1]; // [n] 中的 n
|
var prefixGroup = m.Groups[1]; // [n] 中的 n
|
||||||
@ -275,7 +275,7 @@ namespace Logic.Multilingual
|
|||||||
|
|
||||||
if (prefixGroup.Success)
|
if (prefixGroup.Success)
|
||||||
{
|
{
|
||||||
return $"**<[{prefixGroup.Value}]{str}>**";
|
return $"**<![{prefixGroup.Value}]{str}>**";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -291,14 +291,21 @@ namespace Logic.Multilingual
|
|||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(origin)) return string.Empty;
|
if (string.IsNullOrEmpty(origin)) return string.Empty;
|
||||||
|
|
||||||
var regex = new Regex(@"\*\*<(?:!\[(\d+)\])?(.+?)>\*\*");
|
var regex = new Regex(@"\*\*<(?:!?\[(\d+)\])?(.+?)>\*\*");
|
||||||
var result = regex.Replace(origin, m =>
|
var result = regex.Replace(origin, m =>
|
||||||
{
|
{
|
||||||
var prefixGroup = m.Groups[1]; // [n] 中的 n
|
var prefixGroup = m.Groups[1]; // [n] 中的 n
|
||||||
var str = m.Groups[2].Value; // 内部字符串
|
var str = m.Groups[2].Value; // 内部字符串
|
||||||
|
|
||||||
// 已经是 id 则跳过
|
// 已经是 id 则跳过
|
||||||
if (uint.TryParse(str, out _)) return m.Value;
|
if (uint.TryParse(str, out _))
|
||||||
|
{
|
||||||
|
if (prefixGroup.Success)
|
||||||
|
{
|
||||||
|
return $"**<![{prefixGroup.Value}]{str}>**";
|
||||||
|
}
|
||||||
|
return m.Value;
|
||||||
|
}
|
||||||
|
|
||||||
// 检测嵌套:内部字符串不应再包含 **<...>**
|
// 检测嵌套:内部字符串不应再包含 **<...>**
|
||||||
if (Regex.IsMatch(str, @"\*\*<.+?>\*\*"))
|
if (Regex.IsMatch(str, @"\*\*<.+?>\*\*"))
|
||||||
@ -329,7 +336,7 @@ namespace Logic.Multilingual
|
|||||||
|
|
||||||
if (prefixGroup.Success)
|
if (prefixGroup.Success)
|
||||||
{
|
{
|
||||||
return $"**<[{prefixGroup.Value}]{id}>**";
|
return $"**<![{prefixGroup.Value}]{id}>**";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -342,8 +349,8 @@ namespace Logic.Multilingual
|
|||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 将其他语言的嵌入字符串对齐到中文已转换好的ID格式
|
/// 将其他语言的嵌入字符串对齐到中文已转换好的ID格式
|
||||||
/// zhResolved: 中文已经通过 UnResolveEmbeddedStrings 转换后的字符串(包含 **<id>** 和 **<[n]id>**)
|
/// zhResolved: 中文已经通过 UnResolveEmbeddedStrings 转换后的字符串(包含 **<id>** 和 **<![n]id>**)
|
||||||
/// otherOrigin: 其他语言的原始字符串(包含 **<str>** 和 **<[n]str>**)
|
/// otherOrigin: 其他语言的原始字符串(包含 **<str>** 和 **<![n]str>**)
|
||||||
/// type: 当前语言类型(用于日志)
|
/// type: 当前语言类型(用于日志)
|
||||||
/// itemId: 当前item的ID(用于日志)
|
/// itemId: 当前item的ID(用于日志)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -354,11 +361,11 @@ namespace Logic.Multilingual
|
|||||||
if (string.IsNullOrEmpty(zhResolved)) return otherOrigin;
|
if (string.IsNullOrEmpty(zhResolved)) return otherOrigin;
|
||||||
|
|
||||||
// 解析中文已转换的嵌入引用
|
// 解析中文已转换的嵌入引用
|
||||||
var zhRegex = new Regex(@"\*\*<(?:!\[(\d+)\])?(\d+)>\*\*");
|
var zhRegex = new Regex(@"\*\*<(?:!?\[(\d+)\])?(\d+)>\*\*");
|
||||||
var zhMatches = zhRegex.Matches(zhResolved);
|
var zhMatches = zhRegex.Matches(zhResolved);
|
||||||
|
|
||||||
// 构建中文的 n->完整匹配 字典(带前缀n的)和 无前缀的有序列表
|
// 构建中文的 n->完整匹配 字典(带前缀n的)和 无前缀的有序列表
|
||||||
var zhPrefixDict = new Dictionary<string, string>(); // n -> **<[n]id>**
|
var zhPrefixDict = new Dictionary<string, string>(); // n -> **<![n]id>**
|
||||||
var zhNoPrefixList = new List<string>(); // **<id>** 有序列表
|
var zhNoPrefixList = new List<string>(); // **<id>** 有序列表
|
||||||
|
|
||||||
foreach (Match m in zhMatches)
|
foreach (Match m in zhMatches)
|
||||||
@ -368,7 +375,7 @@ namespace Logic.Multilingual
|
|||||||
|
|
||||||
if (prefixGroup.Success)
|
if (prefixGroup.Success)
|
||||||
{
|
{
|
||||||
zhPrefixDict[prefixGroup.Value] = m.Value; // n -> **<[n]id>**
|
zhPrefixDict[prefixGroup.Value] = $"**<![{prefixGroup.Value}]{idStr}>**"; // n -> **<![n]id>**
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -378,7 +385,7 @@ namespace Logic.Multilingual
|
|||||||
|
|
||||||
// 解析其他语言的嵌入引用
|
// 解析其他语言的嵌入引用
|
||||||
// 允许匹配 **<>**(空内容),导回时也按中文顺序对齐为 **<id>**
|
// 允许匹配 **<>**(空内容),导回时也按中文顺序对齐为 **<id>**
|
||||||
var otherRegex = new Regex(@"\*\*<(?:!\[(\d+)\])?(.*?)>\*\*");
|
var otherRegex = new Regex(@"\*\*<(?:!?\[(\d+)\])?(.*?)>\*\*");
|
||||||
var otherMatches = otherRegex.Matches(otherOrigin);
|
var otherMatches = otherRegex.Matches(otherOrigin);
|
||||||
|
|
||||||
// 分类其他语言的匹配:带前缀n的 和 不带前缀的
|
// 分类其他语言的匹配:带前缀n的 和 不带前缀的
|
||||||
@ -390,15 +397,14 @@ namespace Logic.Multilingual
|
|||||||
var prefixGroup = m.Groups[1];
|
var prefixGroup = m.Groups[1];
|
||||||
var content = m.Groups[2].Value;
|
var content = m.Groups[2].Value;
|
||||||
|
|
||||||
// 如果内容已经是纯数字(id),跳过
|
|
||||||
if (uint.TryParse(content, out _)) continue;
|
|
||||||
|
|
||||||
if (prefixGroup.Success)
|
if (prefixGroup.Success)
|
||||||
{
|
{
|
||||||
otherPrefixMatches.Add(m);
|
otherPrefixMatches.Add(m);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
// 不带顺序前缀且内容已经是纯数字(id)时无需按顺序再次对齐
|
||||||
|
if (uint.TryParse(content, out _)) continue;
|
||||||
otherNoPrefixMatches.Add(m);
|
otherNoPrefixMatches.Add(m);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -407,7 +413,7 @@ namespace Logic.Multilingual
|
|||||||
// 收集所有需要替换的操作
|
// 收集所有需要替换的操作
|
||||||
var replacements = new List<(int index, int length, string replacement)>();
|
var replacements = new List<(int index, int length, string replacement)>();
|
||||||
|
|
||||||
// 1. 处理带前缀 **<[n]str>** 的情况:使用中文对应n的 **<[n]id>**
|
// 1. 处理带前缀 **<![n]str>** 的情况:使用中文对应n的 **<![n]id>**
|
||||||
foreach (var m in otherPrefixMatches)
|
foreach (var m in otherPrefixMatches)
|
||||||
{
|
{
|
||||||
var n = m.Groups[1].Value;
|
var n = m.Groups[1].Value;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user