feat: 佩佩病历本地化
This commit is contained in:
@@ -19,6 +19,16 @@ namespace AibisDream.SystemEditor.Tests
|
||||
"AibisDreamLocalizedObjSpriteTests",
|
||||
Guid.NewGuid().ToString("N"));
|
||||
Directory.CreateDirectory(temporaryRoot);
|
||||
Directory.CreateDirectory(Path.Combine(
|
||||
temporaryRoot,
|
||||
LocalizedObjSpriteValidator.DefaultFolderName));
|
||||
foreach (LocalizedObjSpriteDirectory directory in
|
||||
LocalizedObjSpriteValidator.LocaleDirectories)
|
||||
{
|
||||
Directory.CreateDirectory(Path.Combine(
|
||||
temporaryRoot,
|
||||
directory.FolderName));
|
||||
}
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
@@ -28,20 +38,20 @@ namespace AibisDream.SystemEditor.Tests
|
||||
Directory.Delete(temporaryRoot, true);
|
||||
}
|
||||
|
||||
[TestCase("zh-Hans", "病历")]
|
||||
[TestCase("zh-CN", "病历")]
|
||||
[TestCase("en", "病历-en")]
|
||||
[TestCase("en-US", "病历-en")]
|
||||
[TestCase("ja-JP", "病历-ja-JP")]
|
||||
[TestCase("ru-RU", "病历-ru")]
|
||||
[TestCase("es-ES", "病历-es")]
|
||||
[TestCase("pt-BR", "病历-pt-BR")]
|
||||
public void GetPicName_UsesCanonicalLocaleSuffix(
|
||||
[TestCase("zh-Hans", "Sprite/Obj/病历.png")]
|
||||
[TestCase("zh-CN", "Sprite/Obj/病历.png")]
|
||||
[TestCase("en", "Sprite/Obj_en/病历.png")]
|
||||
[TestCase("en-US", "Sprite/Obj_en/病历.png")]
|
||||
[TestCase("ja-JP", "Sprite/Obj_ja-JP/病历.png")]
|
||||
[TestCase("ru-RU", "Sprite/Obj_ru/病历.png")]
|
||||
[TestCase("es-ES", "Sprite/Obj_es/病历.png")]
|
||||
[TestCase("pt-BR", "Sprite/Obj_pt-BR/病历.png")]
|
||||
public void GetKey_UsesCanonicalLocaleDirectory(
|
||||
string localeCode,
|
||||
string expected)
|
||||
{
|
||||
Assert.That(
|
||||
LocalizedObjSpriteNaming.GetPicName("病历.png", localeCode),
|
||||
LocalizedObjSpriteNaming.GetKey("病历.png", localeCode),
|
||||
Is.EqualTo(expected));
|
||||
}
|
||||
|
||||
@@ -49,20 +59,26 @@ namespace AibisDream.SystemEditor.Tests
|
||||
public void CandidateNames_FallBackToUnsuffixedChineseWithoutDuplicates()
|
||||
{
|
||||
Assert.That(
|
||||
LocalizedObjSpriteNaming.GetCandidatePicNames("病历.png", "en"),
|
||||
Is.EqualTo(new[] { "病历-en", "病历" }));
|
||||
LocalizedObjSpriteNaming.GetCandidateKeys("病历.png", "en"),
|
||||
Is.EqualTo(new[]
|
||||
{
|
||||
"Sprite/Obj_en/病历.png",
|
||||
"Sprite/Obj/病历.png"
|
||||
}));
|
||||
Assert.That(
|
||||
LocalizedObjSpriteNaming.GetCandidatePicNames("病历.png", "zh-Hans"),
|
||||
Is.EqualTo(new[] { "病历" }));
|
||||
LocalizedObjSpriteNaming.GetCandidateKeys("病历.png", "zh-Hans"),
|
||||
Is.EqualTo(new[] { "Sprite/Obj/病历.png" }));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Validator_IgnoresUnsuffixedOnlySprites()
|
||||
{
|
||||
WriteSprite("普通图片.png");
|
||||
WriteSprite(
|
||||
LocalizedObjSpriteValidator.DefaultFolderName,
|
||||
"普通图片.png");
|
||||
|
||||
Assert.That(
|
||||
LocalizedObjSpriteValidator.Validate(temporaryRoot),
|
||||
LocalizedObjSpriteValidator.Validate(temporaryRoot, false),
|
||||
Is.Empty);
|
||||
}
|
||||
|
||||
@@ -71,27 +87,42 @@ namespace AibisDream.SystemEditor.Tests
|
||||
{
|
||||
WriteCompleteGroup("病历");
|
||||
Assert.That(
|
||||
LocalizedObjSpriteValidator.Validate(temporaryRoot),
|
||||
LocalizedObjSpriteValidator.Validate(temporaryRoot, false),
|
||||
Is.Empty);
|
||||
|
||||
File.Delete(Path.Combine(temporaryRoot, "病历-ru.png"));
|
||||
var issues = LocalizedObjSpriteValidator.Validate(temporaryRoot);
|
||||
File.Delete(Path.Combine(temporaryRoot, "Obj_ru", "病历.png"));
|
||||
var issues = LocalizedObjSpriteValidator.Validate(temporaryRoot, false);
|
||||
|
||||
Assert.That(issues, Has.Count.EqualTo(1));
|
||||
Assert.That(issues.Single().AssetPath, Does.EndWith("病历-ru.png"));
|
||||
Assert.That(issues.Single().AssetPath, Does.EndWith("Obj_ru/病历.png"));
|
||||
Assert.That(issues.Single().Message, Does.Contain("'ru'"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ProjectLocaleFolders_AreAddressableByConvention()
|
||||
{
|
||||
Assert.That(
|
||||
LocalizedObjSpriteValidator.Validate(),
|
||||
Is.Empty);
|
||||
}
|
||||
|
||||
private void WriteCompleteGroup(string logicalName)
|
||||
{
|
||||
WriteSprite($"{logicalName}.png");
|
||||
foreach (string localeCode in LocalizedObjSpriteNaming.NonDefaultLocaleCodes)
|
||||
WriteSprite($"{logicalName}-{localeCode}.png");
|
||||
WriteSprite(
|
||||
LocalizedObjSpriteValidator.DefaultFolderName,
|
||||
$"{logicalName}.png");
|
||||
foreach (LocalizedObjSpriteDirectory directory in
|
||||
LocalizedObjSpriteValidator.LocaleDirectories)
|
||||
{
|
||||
WriteSprite(directory.FolderName, $"{logicalName}.png");
|
||||
}
|
||||
}
|
||||
|
||||
private void WriteSprite(string fileName)
|
||||
private void WriteSprite(string folderName, string relativePath)
|
||||
{
|
||||
File.WriteAllBytes(Path.Combine(temporaryRoot, fileName), Array.Empty<byte>());
|
||||
string filePath = Path.Combine(temporaryRoot, folderName, relativePath);
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(filePath));
|
||||
File.WriteAllBytes(filePath, Array.Empty<byte>());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user