fix: 调整Character语言回退逻辑

This commit is contained in:
2026-07-31 23:13:56 +08:00
parent 48dcc9ec3a
commit 24c5169a10
3 changed files with 28 additions and 11 deletions
+12 -4
View File
@@ -24,6 +24,11 @@ namespace AibisDream.SystemEditor.Tests
"GetLocalizedNameByKind", "GetLocalizedNameByKind",
BindingFlags.Instance | BindingFlags.NonPublic); BindingFlags.Instance | BindingFlags.NonPublic);
private static readonly MethodInfo GetCharacterVoByKeyMethod =
typeof(YarnUtil).GetMethod(
"GetCharacterVoByKey",
BindingFlags.Static | BindingFlags.NonPublic);
[TestCase("ru", LocaleKind.Ru)] [TestCase("ru", LocaleKind.Ru)]
[TestCase("ru-RU", LocaleKind.Ru)] [TestCase("ru-RU", LocaleKind.Ru)]
[TestCase("es", LocaleKind.Es)] [TestCase("es", LocaleKind.Es)]
@@ -48,7 +53,7 @@ namespace AibisDream.SystemEditor.Tests
} }
[Test] [Test]
public void CharacterVo_AddedLocaleName_ReturnsTranslationOrKey() public void CharacterVo_LocalizedName_ReturnsOnlySelectedLocaleContent()
{ {
Assert.That(GetLocalizedNameMethod, Is.Not.Null); Assert.That(GetLocalizedNameMethod, Is.Not.Null);
@@ -65,9 +70,12 @@ namespace AibisDream.SystemEditor.Tests
Assert.That(GetLocalizedName(translated, LocaleKind.PtBr), Is.EqualTo(translated.ptBr)); Assert.That(GetLocalizedName(translated, LocaleKind.PtBr), Is.EqualTo(translated.ptBr));
var untranslated = new CharacterVo { key = "actor_key" }; var untranslated = new CharacterVo { key = "actor_key" };
Assert.That(GetLocalizedName(untranslated, LocaleKind.Ru), Is.EqualTo(untranslated.key)); Assert.That(GetLocalizedName(untranslated, LocaleKind.Cn), Is.Null);
Assert.That(GetLocalizedName(untranslated, LocaleKind.Es), Is.EqualTo(untranslated.key)); Assert.That(GetLocalizedName(untranslated, LocaleKind.En), Is.Null);
Assert.That(GetLocalizedName(untranslated, LocaleKind.PtBr), Is.EqualTo(untranslated.key)); Assert.That(GetLocalizedName(untranslated, LocaleKind.Ja), Is.Null);
Assert.That(GetLocalizedName(untranslated, LocaleKind.Ru), Is.Null);
Assert.That(GetLocalizedName(untranslated, LocaleKind.Es), Is.Null);
Assert.That(GetLocalizedName(untranslated, LocaleKind.PtBr), Is.Null);
} }
[Test] [Test]
+11 -7
View File
@@ -76,6 +76,11 @@ namespace AibisDream.Kit
rawName = GetLocalizedNameByKind(LocalizationKit.CurrentLocaleKind); rawName = GetLocalizedNameByKind(LocalizationKit.CurrentLocaleKind);
} }
if (string.IsNullOrWhiteSpace(rawName))
{
return string.Empty;
}
return string.IsNullOrEmpty(nameColor) ? rawName : $"<color={nameColor}>{rawName}</color>"; return string.IsNullOrEmpty(nameColor) ? rawName : $"<color={nameColor}>{rawName}</color>";
} }
@@ -84,19 +89,18 @@ namespace AibisDream.Kit
switch (kind) switch (kind)
{ {
case LocaleKind.En: case LocaleKind.En:
return string.IsNullOrWhiteSpace(en) ? key : en; return en;
case LocaleKind.Ja: case LocaleKind.Ja:
if (!string.IsNullOrWhiteSpace(ja)) return ja; return ja;
return string.IsNullOrWhiteSpace(cn) ? key : cn;
case LocaleKind.Ru: case LocaleKind.Ru:
return string.IsNullOrWhiteSpace(ru) ? key : ru; return ru;
case LocaleKind.Es: case LocaleKind.Es:
return string.IsNullOrWhiteSpace(es) ? key : es; return es;
case LocaleKind.PtBr: case LocaleKind.PtBr:
return string.IsNullOrWhiteSpace(ptBr) ? key : ptBr; return ptBr;
case LocaleKind.Cn: case LocaleKind.Cn:
default: default:
return string.IsNullOrWhiteSpace(cn) ? key : cn; return cn;
} }
} }
+5
View File
@@ -134,6 +134,11 @@ namespace AibisDream.Utility
{ {
key = charKey, key = charKey,
cn = charKey, cn = charKey,
en = charKey,
ja = charKey,
ru = charKey,
es = charKey,
ptBr = charKey,
role = ActorRole.Aside role = ActorRole.Aside
}; };
} }