Localization legge assets/i18n/strings.csv così com'è, ma Godot lo importava come traduzione e nel .pck finivano solo i file .translation: il gioco v0.5.1 partiva senza inglese («Traduzioni non trovate»). Il CSV ora usa l'importatore «keep» e il workflow di rilascio fallisce se le traduzioni importate tornano nel pacchetto. STATE.md registra il collaudo di v0.5.1 (pilota automatico completo sul gioco scaricato) e il secondo test instabile (#24). Closes #27. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
45 lines
1.7 KiB
C#
45 lines
1.7 KiB
C#
using Godot;
|
|
|
|
namespace RailEnterprise.Client.App;
|
|
|
|
/// <summary>
|
|
/// Testi dell'interfaccia: la lingua sorgente è l'italiano (le chiavi sono i testi italiani),
|
|
/// le traduzioni stanno in <c>assets/i18n/strings.csv</c> (colonne keys, it, en) e si caricano
|
|
/// all'avvio senza passare dall'importazione dell'editor. Per questo <c>strings.csv.import</c> usa
|
|
/// l'importatore «keep»: con quello di traduzione Godot non metterebbe il CSV nel gioco esportato.
|
|
/// </summary>
|
|
public static class Localization
|
|
{
|
|
public static void Load(string locale)
|
|
{
|
|
const string path = "res://assets/i18n/strings.csv";
|
|
using var file = Godot.FileAccess.Open(path, Godot.FileAccess.ModeFlags.Read);
|
|
if (file is null)
|
|
{
|
|
GD.PushWarning("Traduzioni non trovate");
|
|
return;
|
|
}
|
|
string[] header = file.GetCsvLine();
|
|
var translations = new List<Translation>();
|
|
for (int c = 1; c < header.Length; c++)
|
|
{
|
|
var t = new Translation { Locale = header[c] };
|
|
translations.Add(t);
|
|
}
|
|
while (!file.EofReached())
|
|
{
|
|
string[] row = file.GetCsvLine();
|
|
if (row.Length < 2 || row[0].Length == 0) continue;
|
|
for (int c = 1; c < row.Length && c - 1 < translations.Count; c++)
|
|
{
|
|
if (row[c].Length > 0) translations[c - 1].AddMessage(row[0], row[c]);
|
|
}
|
|
}
|
|
foreach (var t in translations) TranslationServer.AddTranslation(t);
|
|
TranslationServer.SetLocale(locale);
|
|
}
|
|
|
|
/// <summary>Traduce un testo dell'interfaccia (chiave = testo italiano).</summary>
|
|
public static string T(string italian) => TranslationServer.Translate(italian);
|
|
}
|