- 新增 Editor 窗口:AIBIS → Yarn 本地化校验 - 新增 BatchMode CLI:Tools/validate_yarn_l10n.py - 新增文档:Docs/本地化校验工具.md - 校验 Yarn 原文 string table 与各语言 CSV 的 line id 一致性
58 lines
2.0 KiB
C#
58 lines
2.0 KiB
C#
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Text;
|
|
|
|
namespace AibisDream.YarnLocalizationValidation.Editor
|
|
{
|
|
public static class YarnL10nReportExporter
|
|
{
|
|
public static void ExportToCsv(YarnL10nValidationResult result, string outputPath)
|
|
{
|
|
var directory = Path.GetDirectoryName(outputPath);
|
|
if (!string.IsNullOrEmpty(directory))
|
|
{
|
|
Directory.CreateDirectory(directory);
|
|
}
|
|
|
|
var builder = new StringBuilder();
|
|
builder.AppendLine("issueType,language,lineId,sourceText,locText,yarnFile,yarnLineNumber,csvFile,chapterFolder,message");
|
|
|
|
foreach (var issue in result.Issues)
|
|
{
|
|
builder.AppendLine(string.Join(",",
|
|
Escape(issue.GetDisplayType()),
|
|
Escape(issue.Language),
|
|
Escape(issue.LineId),
|
|
Escape(issue.SourceText),
|
|
Escape(issue.LocText),
|
|
Escape(issue.YarnFile),
|
|
Escape(issue.YarnLineNumber),
|
|
Escape(issue.CsvFile),
|
|
Escape(issue.ChapterFolder),
|
|
Escape(issue.Message)));
|
|
}
|
|
|
|
File.WriteAllText(outputPath, builder.ToString(), new UTF8Encoding(encoderShouldEmitUTF8Identifier: true));
|
|
}
|
|
|
|
public static string BuildDefaultExportFileName(string chapterFolder)
|
|
{
|
|
var chapterName = string.IsNullOrEmpty(chapterFolder)
|
|
? "yarn_l10n"
|
|
: Path.GetFileName(chapterFolder.Replace('/', Path.DirectorySeparatorChar));
|
|
return $"{chapterName}_l10n_report_{System.DateTime.Now:yyyyMMdd_HHmmss}.csv";
|
|
}
|
|
|
|
private static string Escape(string value)
|
|
{
|
|
value ??= string.Empty;
|
|
if (value.Contains('"') || value.Contains(',') || value.Contains('\n') || value.Contains('\r'))
|
|
{
|
|
return $"\"{value.Replace("\"", "\"\"")}\"";
|
|
}
|
|
|
|
return value;
|
|
}
|
|
}
|
|
}
|