diff --git a/MiraAPI.Example/Resources/Translations/English.xml b/MiraAPI.Example/Resources/Translations/English.xml index f6256c0..fd429f8 100644 --- a/MiraAPI.Example/Resources/Translations/English.xml +++ b/MiraAPI.Example/Resources/Translations/English.xml @@ -1,15 +1,15 @@ - Teleporter - Zoom out and teleport across the map! - Freezer - Freeze another player for a duration of time. - Mayor - You get extra votes! - Chamelon - Stay invisible while not moving. - Outcast Killer - Outcast who can kill. + Teleporter + Zoom out and teleport across the map! + Freezer + Freeze another player for a duration of time. + Mayor + You get extra votes! + Chamelon + Stay invisible while not moving. + Outcast Killer + Outcast who can kill. Outcast OUTCAST You are an Outcast. You do not have a team. diff --git a/MiraAPI.Example/Resources/Translations/SChinese.xml b/MiraAPI.Example/Resources/Translations/SChinese.xml index 68f34e9..3b5a53e 100644 --- a/MiraAPI.Example/Resources/Translations/SChinese.xml +++ b/MiraAPI.Example/Resources/Translations/SChinese.xml @@ -1,15 +1,15 @@ - 传送者 - 缩小视野并在地图上传送! - 冰冻者 - 将其他玩家冰冻一段时间。 - 市长 - 你拥有额外投票权! - 变色龙 - 静止不动时保持隐身。 - 流放杀手 - 可以击杀的流放者。 + 传送者 + 缩小视野并在地图上传送! + 冰冻者 + 将其他玩家冰冻一段时间。 + 市长 + 你拥有额外投票权! + 变色龙 + 静止不动时保持隐身。 + 流放杀手 + 可以击杀的流放者。 流放者 流放者 你是流放者,你没有队伍。 diff --git a/MiraAPI.Example/Roles/ChameleonRole.cs b/MiraAPI.Example/Roles/ChameleonRole.cs index bd733d7..d396fe6 100644 --- a/MiraAPI.Example/Roles/ChameleonRole.cs +++ b/MiraAPI.Example/Roles/ChameleonRole.cs @@ -10,9 +10,7 @@ namespace MiraAPI.Example.Roles; public class ChameloenRole : CrewmateRole, ICustomRole { - public string RoleName => "chamelon.name"; - public string RoleLongDescription => "chamelon.description"; - public string RoleDescription => RoleLongDescription; + public string IdPart => "chamelon"; public Color RoleColor => Palette.AcceptedGreen; public ModdedRoleTeams Team => ModdedRoleTeams.Crewmate; diff --git a/MiraAPI.Example/Roles/FreezerRole.cs b/MiraAPI.Example/Roles/FreezerRole.cs index 96adc80..33656c0 100644 --- a/MiraAPI.Example/Roles/FreezerRole.cs +++ b/MiraAPI.Example/Roles/FreezerRole.cs @@ -6,9 +6,7 @@ namespace MiraAPI.Example.Roles; public class FreezerRole : ImpostorRole, ICustomRole { - public string RoleName => "freezer.name"; - public string RoleLongDescription => "freezer.description"; - public string RoleDescription => RoleLongDescription; + public string IdPart => "freezer"; public Color RoleColor => Palette.Blue; public ModdedRoleTeams Team => ModdedRoleTeams.Impostor; diff --git a/MiraAPI.Example/Roles/MayorRole.cs b/MiraAPI.Example/Roles/MayorRole.cs index 12effc0..b06d350 100644 --- a/MiraAPI.Example/Roles/MayorRole.cs +++ b/MiraAPI.Example/Roles/MayorRole.cs @@ -5,9 +5,7 @@ namespace MiraAPI.Example.Roles; public class MayorRole : CrewmateRole, ICustomRole { - public string RoleName => "mayor.name"; - public string RoleLongDescription => "mayor.description"; - public string RoleDescription => RoleLongDescription; + public string IdPart => "mayor"; public Color RoleColor => new Color32(221, 176, 152, 255); public ModdedRoleTeams Team => ModdedRoleTeams.Crewmate; public CustomRoleConfiguration Configuration => new(this); diff --git a/MiraAPI.Example/Roles/NeutralKillerRole.cs b/MiraAPI.Example/Roles/NeutralKillerRole.cs index 695f4df..4202cd1 100644 --- a/MiraAPI.Example/Roles/NeutralKillerRole.cs +++ b/MiraAPI.Example/Roles/NeutralKillerRole.cs @@ -8,9 +8,7 @@ namespace MiraAPI.Example.Roles; public class NeutralKillerRole : ImpostorRole, ICustomRole { - public string RoleName => "outcastKiller.name"; - public string RoleDescription => "outcastKiller.description"; - public string RoleLongDescription => RoleDescription; + public string IdPart => "outcastKiller"; public Color RoleColor => Color.magenta; public ModdedRoleTeams Team => ModdedRoleTeams.Custom; diff --git a/MiraAPI.Example/Roles/TeleporterRole.cs b/MiraAPI.Example/Roles/TeleporterRole.cs index b60407b..7136ff0 100644 --- a/MiraAPI.Example/Roles/TeleporterRole.cs +++ b/MiraAPI.Example/Roles/TeleporterRole.cs @@ -5,9 +5,7 @@ namespace MiraAPI.Example.Roles; public class TeleporterRole : CrewmateRole, ICustomRole { - public string RoleName => "teleporter.name"; - public string RoleLongDescription => "teleporter.description"; - public string RoleDescription => RoleLongDescription; + public string IdPart => "teleporter"; public Color RoleColor => new Color32(221, 176, 152, 255); public ModdedRoleTeams Team => ModdedRoleTeams.Crewmate; diff --git a/MiraAPI/Roles/ICustomRole.cs b/MiraAPI/Roles/ICustomRole.cs index 2df32ae..0b3f53b 100644 --- a/MiraAPI/Roles/ICustomRole.cs +++ b/MiraAPI/Roles/ICustomRole.cs @@ -14,20 +14,25 @@ namespace MiraAPI.Roles; /// public interface ICustomRole : IOptionable { + /// + /// Gets the id part used to build the role's translation keys. + /// + string IdPart => GetType().Name.ToLower(); + /// /// Gets the name of the role. /// - string RoleName { get; } + string RoleName => TranslationManager.BuildTranslationId(IdPart, "name"); /// /// Gets the description of the role. Used in the Intro Cutscene. /// - string RoleDescription { get; } + string RoleDescription => TranslationManager.BuildTranslationId(IdPart, "description"); /// /// Gets the long description of the role. Used in the Role Tab and Role Options. /// - string RoleLongDescription { get; } + string RoleLongDescription => TranslationManager.BuildTranslationId(IdPart, "description"); /// /// Gets the of the role. diff --git a/MiraAPI/Translation/TranslationManager.cs b/MiraAPI/Translation/TranslationManager.cs index eaba44d..a6fbe63 100644 --- a/MiraAPI/Translation/TranslationManager.cs +++ b/MiraAPI/Translation/TranslationManager.cs @@ -119,6 +119,11 @@ public static class TranslationManager return key; } + public static string BuildTranslationId(string idPart, string suffix) + { + return idPart.StartsWith('#') ? idPart[1..] : $"{idPart}.{suffix}"; + } + private static string GetModLangDir(string modGuid) { return Path.Combine(Application.persistentDataPath, LangDirectory, modGuid);