mirror of
https://github.com/Raymonf/whack.git
synced 2024-11-27 17:40:48 +01:00
Prepare for use of other languages
This commit is contained in:
parent
0b1e357542
commit
2ce8d58ed8
@ -2,6 +2,32 @@ namespace WhackTranslationTool;
|
|||||||
|
|
||||||
public class ExportSettings
|
public class ExportSettings
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Export English (USA) message.
|
||||||
|
/// </summary>
|
||||||
|
public bool ExportEnglishUSAMessage { get; set; } = true;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Export English (SG) message.
|
||||||
|
/// </summary>
|
||||||
|
public bool ExportEnglishSGMessage { get; set; } = false;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Export Traditional Chinese (TW) message.
|
||||||
|
/// </summary>
|
||||||
|
public bool ExportTChineseTWMessage { get; set; } = false;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Export Traditional Chinese (HK) message.
|
||||||
|
/// </summary>
|
||||||
|
public bool ExportTChineseHKMessage { get; set; } = false;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Export Simplified Chinese message along with the Japanese message.
|
||||||
|
/// Useful for cross-referencing meaning of a phrase or word.
|
||||||
|
/// </summary>
|
||||||
|
public bool ExportSChineseMessage { get; set; } = false;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Export Korean message along with the Japanese message.
|
/// Export Korean message along with the Japanese message.
|
||||||
/// Useful for cross-referencing meaning of a phrase or word.
|
/// Useful for cross-referencing meaning of a phrase or word.
|
||||||
|
19
WTT/WTT/Language.cs
Normal file
19
WTT/WTT/Language.cs
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace WTT
|
||||||
|
{
|
||||||
|
public enum Language
|
||||||
|
{
|
||||||
|
Japanese,
|
||||||
|
EnglishUSA,
|
||||||
|
EnglishSG,
|
||||||
|
TraditionalChineseTW,
|
||||||
|
TraditionalChineseHK,
|
||||||
|
SimplifiedChinese,
|
||||||
|
Korean
|
||||||
|
}
|
||||||
|
}
|
90
WTT/WTT/Table.cs
Normal file
90
WTT/WTT/Table.cs
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
using UAssetAPI.PropertyTypes.Structs;
|
||||||
|
using UAssetAPI.UnrealTypes;
|
||||||
|
using WTT;
|
||||||
|
|
||||||
|
namespace WhackTranslationTool;
|
||||||
|
|
||||||
|
public class Table
|
||||||
|
{
|
||||||
|
public const UE4Version UnrealVersion = UE4Version.VER_UE4_19;
|
||||||
|
|
||||||
|
public static string GetMessageKeyName(Language language)
|
||||||
|
{
|
||||||
|
return language switch
|
||||||
|
{
|
||||||
|
Language.Japanese => "JapaneseMessage",
|
||||||
|
Language.EnglishUSA => "EnglishMessageUSA",
|
||||||
|
Language.EnglishSG => "EnglishMessageSG",
|
||||||
|
Language.TraditionalChineseTW => "TraditionalChineseMessageTW",
|
||||||
|
Language.TraditionalChineseHK => "TraditionalChineseMessageHK",
|
||||||
|
Language.SimplifiedChinese => "SimplifiedChineseMessage",
|
||||||
|
Language.Korean => "KoreanMessage",
|
||||||
|
_ => throw new NotImplementedException($"unknown language {language}")
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the prop
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="entry"></param>
|
||||||
|
/// <param name="language"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
/// <exception cref="Exception"></exception>
|
||||||
|
public static int GetMessageIndex(StructPropertyData entry, Language language)
|
||||||
|
{
|
||||||
|
switch (language)
|
||||||
|
{
|
||||||
|
case Language.Japanese:
|
||||||
|
return entry.StructType.Value.Value switch
|
||||||
|
{
|
||||||
|
"MessageData" => 0,
|
||||||
|
"CharaMessageData" => 3,
|
||||||
|
_ => throw new NotImplementedException($"Unhandled type '{entry.StructType}'")
|
||||||
|
};
|
||||||
|
case Language.EnglishUSA:
|
||||||
|
return entry.StructType.Value.Value switch
|
||||||
|
{
|
||||||
|
"MessageData" => 1,
|
||||||
|
"CharaMessageData" => 4,
|
||||||
|
_ => throw new NotImplementedException($"Unhandled type '{entry.StructType}'")
|
||||||
|
};
|
||||||
|
case Language.EnglishSG:
|
||||||
|
return entry.StructType.Value.Value switch
|
||||||
|
{
|
||||||
|
"MessageData" => 2,
|
||||||
|
"CharaMessageData" => 5,
|
||||||
|
_ => throw new NotImplementedException($"Unhandled type '{entry.StructType}'")
|
||||||
|
};
|
||||||
|
case Language.TraditionalChineseTW:
|
||||||
|
return entry.StructType.Value.Value switch
|
||||||
|
{
|
||||||
|
"MessageData" => 3,
|
||||||
|
"CharaMessageData" => 6,
|
||||||
|
_ => throw new NotImplementedException($"Unhandled type '{entry.StructType}'")
|
||||||
|
};
|
||||||
|
case Language.TraditionalChineseHK:
|
||||||
|
return entry.StructType.Value.Value switch
|
||||||
|
{
|
||||||
|
"MessageData" => 4,
|
||||||
|
"CharaMessageData" => 7,
|
||||||
|
_ => throw new NotImplementedException($"Unhandled type '{entry.StructType}'")
|
||||||
|
};
|
||||||
|
case Language.SimplifiedChinese:
|
||||||
|
return entry.StructType.Value.Value switch
|
||||||
|
{
|
||||||
|
"MessageData" => 5,
|
||||||
|
"CharaMessageData" => 8,
|
||||||
|
_ => throw new NotImplementedException($"Unhandled type '{entry.StructType}'")
|
||||||
|
};
|
||||||
|
case Language.Korean:
|
||||||
|
return entry.StructType.Value.Value switch
|
||||||
|
{
|
||||||
|
"MessageData" => 6,
|
||||||
|
"CharaMessageData" => 9,
|
||||||
|
_ => throw new NotImplementedException($"Unhandled type '{entry.StructType}'")
|
||||||
|
};
|
||||||
|
default:
|
||||||
|
throw new NotImplementedException($"unknown language '{language}'");
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
@ -1,10 +0,0 @@
|
|||||||
using UAssetAPI.UnrealTypes;
|
|
||||||
|
|
||||||
namespace WhackTranslationTool;
|
|
||||||
|
|
||||||
public class TableConstants
|
|
||||||
{
|
|
||||||
public const UE4Version UnrealVersion = UE4Version.VER_UE4_19;
|
|
||||||
// public const int JAPANESE_MESSAGE_INDEX = 0;
|
|
||||||
// public const int KOREAN_MESSAGE_INDEX = 6;
|
|
||||||
}
|
|
@ -25,7 +25,7 @@ public class TableExporter
|
|||||||
{
|
{
|
||||||
_settings = settings;
|
_settings = settings;
|
||||||
|
|
||||||
var asset = new UAsset(filename, TableConstants.UnrealVersion);
|
var asset = new UAsset(filename, Table.UnrealVersion);
|
||||||
if (!asset.VerifyBinaryEquality())
|
if (!asset.VerifyBinaryEquality())
|
||||||
throw new UnsupportedAssetException($"'{asset.FilePath}' is not supported (no binary equality)");
|
throw new UnsupportedAssetException($"'{asset.FilePath}' is not supported (no binary equality)");
|
||||||
Read(asset);
|
Read(asset);
|
||||||
@ -36,7 +36,11 @@ public class TableExporter
|
|||||||
var tomlTable = new TomlTable();
|
var tomlTable = new TomlTable();
|
||||||
|
|
||||||
tomlTable.AddMessage(entry, 0, "JapaneseMessage");
|
tomlTable.AddMessage(entry, 0, "JapaneseMessage");
|
||||||
|
if (_settings.ExportEnglishUSAMessage)
|
||||||
tomlTable.AddMessage(entry, 1, "EnglishMessageUSA");
|
tomlTable.AddMessage(entry, 1, "EnglishMessageUSA");
|
||||||
|
if (_settings.ExportSChineseMessage)
|
||||||
|
tomlTable.AddMessage(entry, 5, "SimplifiedChineseMessage");
|
||||||
|
if (_settings.ExportKoreanMessage)
|
||||||
tomlTable.AddMessage(entry, 6, "KoreanMessage");
|
tomlTable.AddMessage(entry, 6, "KoreanMessage");
|
||||||
|
|
||||||
return tomlTable;
|
return tomlTable;
|
||||||
@ -47,7 +51,10 @@ public class TableExporter
|
|||||||
var tomlTable = new TomlTable();
|
var tomlTable = new TomlTable();
|
||||||
|
|
||||||
tomlTable.AddMessage(entry, 3, "JapaneseMessage");
|
tomlTable.AddMessage(entry, 3, "JapaneseMessage");
|
||||||
|
if (_settings.ExportEnglishUSAMessage)
|
||||||
tomlTable.AddMessage(entry, 4, "EnglishMessageUSA");
|
tomlTable.AddMessage(entry, 4, "EnglishMessageUSA");
|
||||||
|
if (_settings.ExportSChineseMessage)
|
||||||
|
tomlTable.AddMessage(entry, 8, "SimplifiedChineseMessage");
|
||||||
if (_settings.ExportKoreanMessage)
|
if (_settings.ExportKoreanMessage)
|
||||||
tomlTable.AddMessage(entry, 9, "KoreanMessage");
|
tomlTable.AddMessage(entry, 9, "KoreanMessage");
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ using UAssetAPI.Kismet.Bytecode.Expressions;
|
|||||||
using UAssetAPI.PropertyTypes.Structs;
|
using UAssetAPI.PropertyTypes.Structs;
|
||||||
using UAssetAPI.UnrealTypes;
|
using UAssetAPI.UnrealTypes;
|
||||||
using WhackTranslationTool.Exceptions;
|
using WhackTranslationTool.Exceptions;
|
||||||
|
using WTT;
|
||||||
|
|
||||||
namespace WhackTranslationTool;
|
namespace WhackTranslationTool;
|
||||||
|
|
||||||
@ -12,6 +13,7 @@ public class TableImporter
|
|||||||
{
|
{
|
||||||
private Dictionary<string, string?> strings = new();
|
private Dictionary<string, string?> strings = new();
|
||||||
private UAsset asset;
|
private UAsset asset;
|
||||||
|
private Language language;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
@ -19,9 +21,11 @@ public class TableImporter
|
|||||||
/// <param name="tomlPath">Path to the toml source import file</param>
|
/// <param name="tomlPath">Path to the toml source import file</param>
|
||||||
/// <param name="assetPath">Path to the target uasset file</param>
|
/// <param name="assetPath">Path to the target uasset file</param>
|
||||||
/// <exception cref="UnsupportedAssetException">When UAssetAPI fails to reconstruct the asset file</exception>
|
/// <exception cref="UnsupportedAssetException">When UAssetAPI fails to reconstruct the asset file</exception>
|
||||||
public TableImporter(string tomlPath, string assetPath)
|
public TableImporter(string tomlPath, string assetPath, Language language = Language.EnglishUSA)
|
||||||
{
|
{
|
||||||
asset = new UAsset(assetPath, TableConstants.UnrealVersion);
|
this.language = language;
|
||||||
|
|
||||||
|
asset = new UAsset(assetPath, Table.UnrealVersion);
|
||||||
if (!asset.VerifyBinaryEquality())
|
if (!asset.VerifyBinaryEquality())
|
||||||
{
|
{
|
||||||
throw new UnsupportedAssetException($"'{asset.FilePath}' is not supported (no binary equality)");
|
throw new UnsupportedAssetException($"'{asset.FilePath}' is not supported (no binary equality)");
|
||||||
@ -68,6 +72,7 @@ public class TableImporter
|
|||||||
throw new UnhandledTomlError("TOML error was not handled");
|
throw new UnhandledTomlError("TOML error was not handled");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var keyName = Table.GetMessageKeyName(language);
|
||||||
foreach (var (key, value) in table.RawTable)
|
foreach (var (key, value) in table.RawTable)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(key))
|
if (string.IsNullOrEmpty(key))
|
||||||
@ -76,8 +81,8 @@ public class TableImporter
|
|||||||
throw new DuplicateKeyException($"duplicate key '{key}' found for file {tomlPath} ({asset.FilePath})");
|
throw new DuplicateKeyException($"duplicate key '{key}' found for file {tomlPath} ({asset.FilePath})");
|
||||||
|
|
||||||
// we now output the boolean false for null values since toml doesn't have null
|
// we now output the boolean false for null values since toml doesn't have null
|
||||||
var exists = value.HasKey("EnglishMessageUSA") && value["EnglishMessageUSA"].IsString;
|
var exists = value.HasKey(keyName) && value[keyName].IsString;
|
||||||
strings.Add(key, exists ? value["EnglishMessageUSA"].AsString.Value : null);
|
strings.Add(key, exists ? value[keyName].AsString.Value : null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,18 +101,10 @@ public class TableImporter
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// index of EnglishMessageUSA
|
// index of the Message key
|
||||||
var engIndex = entry.StructType.Value.Value switch
|
var index = Table.GetMessageIndex(entry, language);
|
||||||
{
|
// if (strings[name] != null)
|
||||||
"MessageData" => 1,
|
entry.Value[index].SetObject(FString.FromString(strings[name]));
|
||||||
"CharaMessageData" => 4,
|
|
||||||
_ => throw new Exception($"Unhandled type '{entry.StructType}'")
|
|
||||||
};
|
|
||||||
|
|
||||||
if (strings[name] != null)
|
|
||||||
{
|
|
||||||
entry.Value[engIndex].SetObject(FString.FromString(strings[name]));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user