feat: 佩佩病历本地化

This commit is contained in:
2026-08-03 01:21:14 +08:00
parent d0cd0b00b5
commit 708786e788
443 changed files with 34829 additions and 142 deletions
@@ -5,13 +5,14 @@ using AibisDream.Framework;
namespace AibisDream.UI
{
/// <summary>
/// Defines the file-name convention used by localized Obj sprites.
/// Chinese uses the unsuffixed source asset; every other supported locale uses
/// "{logicalName}-{localeCode}".
/// Defines the Addressable key convention used by localized Obj sprites.
/// Chinese uses Sprite/Obj; every other supported locale uses
/// Sprite/Obj_{localeCode}. File names stay identical across locales.
/// </summary>
internal static class LocalizedObjSpriteNaming
{
internal const string DefaultLocaleCode = "zh-Hans";
internal const string DefaultAddressRoot = "Sprite/Obj";
private static readonly string[] NonDefaultLocaleCodeValues =
{
@@ -46,55 +47,34 @@ namespace AibisDream.UI
};
}
internal static string GetPicName(string logicalName, string localeCode)
internal static string GetAddressRoot(string localeCode)
{
string normalizedName = NormalizeLogicalName(logicalName);
string assetLocaleCode = GetAssetLocaleCode(localeCode);
return string.Equals(
assetLocaleCode,
DefaultLocaleCode,
StringComparison.Ordinal)
? normalizedName
: $"{normalizedName}-{assetLocaleCode}";
? DefaultAddressRoot
: $"{DefaultAddressRoot}_{assetLocaleCode}";
}
internal static IReadOnlyList<string> GetCandidatePicNames(
internal static string GetKey(string logicalName, string localeCode)
{
string normalizedName = NormalizeLogicalName(logicalName);
return $"{GetAddressRoot(localeCode)}/{normalizedName}.png";
}
internal static IReadOnlyList<string> GetCandidateKeys(
string logicalName,
string localeCode)
{
string normalizedName = NormalizeLogicalName(logicalName);
string localizedName = GetPicName(normalizedName, localeCode);
if (string.Equals(localizedName, normalizedName, StringComparison.Ordinal))
return new[] { normalizedName };
string localizedKey = GetKey(normalizedName, localeCode);
string defaultKey = GetKey(normalizedName, DefaultLocaleCode);
if (string.Equals(localizedKey, defaultKey, StringComparison.Ordinal))
return new[] { defaultKey };
return new[] { localizedName, normalizedName };
}
internal static bool TryParseLocalizedVariant(
string fileNameWithoutExtension,
out string logicalName,
out string localeCode)
{
foreach (string candidateCode in NonDefaultLocaleCodeValues)
{
string suffix = $"-{candidateCode}";
if (!fileNameWithoutExtension.EndsWith(
suffix,
StringComparison.OrdinalIgnoreCase))
{
continue;
}
logicalName = fileNameWithoutExtension.Substring(
0,
fileNameWithoutExtension.Length - suffix.Length);
localeCode = candidateCode;
return true;
}
logicalName = null;
localeCode = null;
return false;
return new[] { localizedKey, defaultKey };
}
}
}
+14 -6
View File
@@ -78,6 +78,14 @@ namespace AibisDream.UI
{
var normalizedName = NormalizeObjPicName(picName);
var key = string.Format(ObjSpritePath, normalizedName);
yield return LoadObjSpriteByKey(key, completed, warning);
}
private IEnumerator LoadObjSpriteByKey(
string key,
Action<Sprite> completed,
Action<string> warning = null)
{
var handle = ResourceSystem.LoadAsync<Sprite>(key);
yield return handle;
if (handle.Status == AsyncOperationStatus.Succeeded && handle.Result != null)
@@ -100,17 +108,17 @@ namespace AibisDream.UI
yield return LocalizationKit.WaitUntilReady();
string localeCode = LocalizationSettings.SelectedLocale?.Identifier.Code;
IReadOnlyList<string> candidates =
LocalizedObjSpriteNaming.GetCandidatePicNames(logicalName, localeCode);
IReadOnlyList<string> candidateKeys =
LocalizedObjSpriteNaming.GetCandidateKeys(logicalName, localeCode);
for (int index = 0; index < candidates.Count; index++)
for (int index = 0; index < candidateKeys.Count; index++)
{
Sprite sprite = null;
Action<string> loadWarning = index == candidates.Count - 1
Action<string> loadWarning = index == candidateKeys.Count - 1
? warning
: null;
yield return LoadObjSprite(
candidates[index],
yield return LoadObjSpriteByKey(
candidateKeys[index],
value => sprite = value,
loadWarning);
if (sprite == null)