mirror of
https://github.com/kwsch/NHSE.git
synced 2026-10-02 06:46:36 -05:00
@@ -11,6 +11,7 @@ public sealed class GameStrings
|
||||
public readonly string[] itemlistdisplay;
|
||||
public readonly Dictionary<string, string> VillagerMap;
|
||||
public readonly List<ComboItem> ItemDataSource;
|
||||
public readonly Dictionary<string, string> InternalNameTranslation = new Dictionary<string, string>();
|
||||
|
||||
private string[] Get(string ident) => GameLanguage.GetStrings(ident, lang);
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ public LifeSupportAchievement(short land, short player, ushort index, string nam
|
||||
|
||||
private const string Unknown = "???";
|
||||
|
||||
private static readonly IReadOnlyDictionary<int, LifeSupportAchievement> Dictionary = new Dictionary<int, LifeSupportAchievement>
|
||||
public static readonly IReadOnlyDictionary<int, LifeSupportAchievement> Dictionary = new Dictionary<int, LifeSupportAchievement>
|
||||
{
|
||||
{0x001, new LifeSupportAchievement( 3, -1, 0001, "CatchFish" )}, // サカナを釣った
|
||||
{0x002, new LifeSupportAchievement( 3, -1, 0002, "CatchInsect" )}, // ムシを捕まえた
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Windows.Forms;
|
||||
@@ -25,6 +26,7 @@ public static void UpdateAll()
|
||||
IsUpdatingTranslations = true;
|
||||
DumpStringsMessage();
|
||||
UpdateTranslations();
|
||||
UpdateInternalNameTranslations();
|
||||
IsUpdatingTranslations = false;
|
||||
}
|
||||
|
||||
@@ -91,12 +93,46 @@ private static void LoadSpecialForms()
|
||||
nameof(SettingsEditor),
|
||||
};
|
||||
|
||||
private static void UpdateInternalNameTranslations()
|
||||
{
|
||||
var langs = new[] { DefaultLanguage }.Concat(Languages);
|
||||
var available = new[]
|
||||
{
|
||||
LifeSupportAchievement.Dictionary.Values.Select(z => z.Name),
|
||||
EventFlagPlayer.List.Values.Select(z => z.Name),
|
||||
EventFlagLand.List.Values.Select(z => z.Name),
|
||||
EventFlagVillager.List.Values.Select(z => z.Name),
|
||||
}.SelectMany(z => z);
|
||||
|
||||
var translatables = new HashSet<string>(available);
|
||||
foreach (var lang in langs)
|
||||
{
|
||||
var str = GameInfo.GetStrings(lang);
|
||||
var dict = str.InternalNameTranslation;
|
||||
|
||||
var oldKeys = dict
|
||||
.Where(kvp => translatables.Contains(kvp.Key));
|
||||
var newKeys = translatables
|
||||
.Where(key => !dict.ContainsKey(key))
|
||||
.Select(z => new KeyValuePair<string, string>(z, z));
|
||||
|
||||
var allKeys = oldKeys.Concat(newKeys);
|
||||
|
||||
var newDict = allKeys.ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
|
||||
|
||||
var result = newDict.Select(z => $"{z.Key}={z.Value}");
|
||||
var dir = GetResourcePath();
|
||||
var location = GetFileLocationInText("internal", dir, lang);
|
||||
File.WriteAllLines(location, result);
|
||||
}
|
||||
}
|
||||
|
||||
private static void DumpStringsMessage() => DumpStrings(typeof(MessageStrings));
|
||||
|
||||
private static void DumpStrings(Type t)
|
||||
{
|
||||
var dir = GetResourcePath();
|
||||
var langs = new[] { DefaultLanguage }.Concat(Languages);
|
||||
var dir = GetResourcePath();
|
||||
foreach (var lang in langs)
|
||||
{
|
||||
TranslationUtil.SetLocalization(t, lang);
|
||||
|
||||
@@ -84,6 +84,25 @@ private static void SetLocalization(Type t, IReadOnlyCollection<string> lines)
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Applies localization to a static class containing language-specific strings.
|
||||
/// </summary>
|
||||
/// <param name="dict">Dictionary of translatable strings</param>
|
||||
/// <param name="lines">Lines containing the localized strings</param>
|
||||
private static void SetLocalization(IDictionary<string, string> dict, IReadOnlyCollection<string> lines)
|
||||
{
|
||||
if (lines.Count == 0)
|
||||
return;
|
||||
foreach (var line in lines)
|
||||
{
|
||||
var index = line.IndexOf(TranslationSplitter);
|
||||
if (index < 0)
|
||||
continue;
|
||||
var prop = line.Substring(0, index);
|
||||
dict[prop] = line.Substring(index + 1);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Applies localization to a static class containing language-specific strings.
|
||||
/// </summary>
|
||||
@@ -105,5 +124,11 @@ public static void SetLocalization(Type t, string currentCultureCode)
|
||||
{
|
||||
SetLocalization(t, t.Name, currentCultureCode);
|
||||
}
|
||||
|
||||
public static void SetLocalization(IDictionary<string, string> dict, string currentCultureCode)
|
||||
{
|
||||
var lines = ResourceUtil.GetStringList($"internal_{currentCultureCode}");
|
||||
SetLocalization(dict, lines);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user