From 276ab0ac79e9f4eb47b764b052cd472c9156d421 Mon Sep 17 00:00:00 2001 From: Atony <75191600+AtonyGit@users.noreply.github.com> Date: Tue, 25 Aug 2026 19:02:55 -0500 Subject: [PATCH] Fix overall localization --- MiraAPI.Example/Resources/Locale/en_US.xml | 61 ++++++++++--------- MiraAPI.Example/Roles/ChameleonRole.cs | 2 +- MiraAPI.Example/Roles/FreezerRole.cs | 2 +- MiraAPI.Example/Roles/MayorRole.cs | 2 +- MiraAPI.Example/Roles/NeutralKillerRole.cs | 2 +- MiraAPI.Example/Roles/TeleporterRole.cs | 2 +- .../Patches/Options/RoleSettingMenuPatches.cs | 2 +- MiraAPI/PluginLoading/IMiraPlugin.cs | 12 ++-- MiraAPI/Roles/CustomRoleManager.cs | 14 ++--- MiraAPI/Roles/CustomRoleUtils.cs | 4 +- MiraAPI/Roles/ICustomRole.cs | 53 ++++++++++++---- MiraAPI/Utilities/Helpers.cs | 2 +- 12 files changed, 97 insertions(+), 61 deletions(-) diff --git a/MiraAPI.Example/Resources/Locale/en_US.xml b/MiraAPI.Example/Resources/Locale/en_US.xml index fd429f8..4039ad9 100644 --- a/MiraAPI.Example/Resources/Locale/en_US.xml +++ b/MiraAPI.Example/Resources/Locale/en_US.xml @@ -1,57 +1,60 @@ - 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 + Teleporter + Zoom out and teleport across the map! + Zoom out and teleport across the map! + Zoom out and teleport across the map! + The Teleporter is a Crewmate role that can move around the map using their dope-ass ability. + 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. - Think + Think Thinking... - Freeze - Teleport - Call Meeting - Win Game - Captain - You can call a meeting from anywhere on the map. - Freezed - High Priority - You are high priority! Idrk what this means either tbh... - Example Options 1 + Freeze + Teleport + Call Meeting + Win Game + Captain + You can call a meeting from anywhere on the map. + Freezed + High Priority + You are high priority! Idrk what this means either tbh... + Example Options 1 Toggle Opt 1 Toggle Opt 2 Number Opt Best API - Example Options 2 + Example Options 2 YOU MUST CHOSE A PLAYER Eh whatever Toggle Option 1 Toggle Option 2 Enum Opt - Captain Settings + Captain Settings Amount Chance Uses - Freeze + Freeze Use Color - General + General Some Boolean Option Number Option - Custom Role + Custom Role Freeze Duration Freeze Uses - Teleporter + Teleporter Teleport Cooldown Teleport Duration Zoom Distance - Mira Example + Mira Example Example Bool Example Bool 2 Slider diff --git a/MiraAPI.Example/Roles/ChameleonRole.cs b/MiraAPI.Example/Roles/ChameleonRole.cs index d396fe6..e3f91b7 100644 --- a/MiraAPI.Example/Roles/ChameleonRole.cs +++ b/MiraAPI.Example/Roles/ChameleonRole.cs @@ -10,7 +10,7 @@ namespace MiraAPI.Example.Roles; public class ChameloenRole : CrewmateRole, ICustomRole { - public string IdPart => "chamelon"; + public string IdPart => "ApiExample.Role.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 33656c0..d365b37 100644 --- a/MiraAPI.Example/Roles/FreezerRole.cs +++ b/MiraAPI.Example/Roles/FreezerRole.cs @@ -6,7 +6,7 @@ namespace MiraAPI.Example.Roles; public class FreezerRole : ImpostorRole, ICustomRole { - public string IdPart => "freezer"; + public string IdPart => "ApiExample.Role.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 b06d350..6dae223 100644 --- a/MiraAPI.Example/Roles/MayorRole.cs +++ b/MiraAPI.Example/Roles/MayorRole.cs @@ -5,7 +5,7 @@ namespace MiraAPI.Example.Roles; public class MayorRole : CrewmateRole, ICustomRole { - public string IdPart => "mayor"; + public string IdPart => "ApiExample.Role.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 4202cd1..e952703 100644 --- a/MiraAPI.Example/Roles/NeutralKillerRole.cs +++ b/MiraAPI.Example/Roles/NeutralKillerRole.cs @@ -8,7 +8,7 @@ namespace MiraAPI.Example.Roles; public class NeutralKillerRole : ImpostorRole, ICustomRole { - public string IdPart => "outcastKiller"; + public string IdPart => "ApiExample.Role.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 7136ff0..8c114b8 100644 --- a/MiraAPI.Example/Roles/TeleporterRole.cs +++ b/MiraAPI.Example/Roles/TeleporterRole.cs @@ -5,7 +5,7 @@ namespace MiraAPI.Example.Roles; public class TeleporterRole : CrewmateRole, ICustomRole { - public string IdPart => "teleporter"; + public string IdPart => "ApiExample.Role.Teleporter"; public Color RoleColor => new Color32(221, 176, 152, 255); public ModdedRoleTeams Team => ModdedRoleTeams.Crewmate; diff --git a/MiraAPI/Patches/Options/RoleSettingMenuPatches.cs b/MiraAPI/Patches/Options/RoleSettingMenuPatches.cs index ac444da..ff31dfa 100644 --- a/MiraAPI/Patches/Options/RoleSettingMenuPatches.cs +++ b/MiraAPI/Patches/Options/RoleSettingMenuPatches.cs @@ -575,7 +575,7 @@ public static class RoleSettingMenuPatches return; } - __instance.roleDescriptionText.text = customRole.RoleLongDescription.Translate(); + __instance.roleDescriptionText.text = customRole.RoleMedDescription; __instance.roleTitleText.text = role.GetRoleName(); var imgBg = __instance.AdvancedRolesSettings.transform.FindChild("Imagebackground"); diff --git a/MiraAPI/PluginLoading/IMiraPlugin.cs b/MiraAPI/PluginLoading/IMiraPlugin.cs index 6fb13ed..21cd9d9 100644 --- a/MiraAPI/PluginLoading/IMiraPlugin.cs +++ b/MiraAPI/PluginLoading/IMiraPlugin.cs @@ -1,7 +1,6 @@ -using System.Linq; +using System.Globalization; +using System.Linq; using BepInEx.Configuration; -using MiraAPI.Utilities.Assets; -using UnityEngine; namespace MiraAPI.PluginLoading; @@ -15,11 +14,16 @@ public interface IMiraPlugin /// public virtual bool DisplayOnOptionsMenu => true; + /// + /// Gets or sets a value for the localization id to use for anything registered under this mod. + /// + public virtual string ParentLocaleId => GetType().Name.ToLower(CultureInfo.InvariantCulture); + /// /// Gets the name to display on the options menu. /// string OptionsTitleText { get; } - + /// /// Gets the abbreviated name to display for other mods to pick up. /// diff --git a/MiraAPI/Roles/CustomRoleManager.cs b/MiraAPI/Roles/CustomRoleManager.cs index 0f4e839..bc93252 100644 --- a/MiraAPI/Roles/CustomRoleManager.cs +++ b/MiraAPI/Roles/CustomRoleManager.cs @@ -132,10 +132,10 @@ public static class CustomRoleManager roleBehaviour.Role = (RoleTypes)roleId; roleBehaviour.TeamType = customRole.Team == ModdedRoleTeams.Custom ? RoleTeamTypes.Crewmate : (RoleTeamTypes)customRole.Team; roleBehaviour.NameColor = customRole.RoleColor; - roleBehaviour.StringName = MiraLocaleManager.GetOrCreateLocaleString(customRole.RoleName); - roleBehaviour.BlurbName = MiraLocaleManager.GetOrCreateLocaleString(customRole.RoleDescription); - roleBehaviour.BlurbNameMed = MiraLocaleManager.GetOrCreateLocaleString(customRole.RoleMedDescription); - roleBehaviour.BlurbNameLong = MiraLocaleManager.GetOrCreateLocaleString(customRole.RoleLongDescription); + roleBehaviour.StringName = MiraLocaleManager.GetOrCreateLocaleString(customRole.RoleNameLocale); + roleBehaviour.BlurbName = MiraLocaleManager.GetOrCreateLocaleString(customRole.RoleDescriptionLocale); + roleBehaviour.BlurbNameMed = MiraLocaleManager.GetOrCreateLocaleString(customRole.RoleMedDescriptionLocale); + roleBehaviour.BlurbNameLong = MiraLocaleManager.GetOrCreateLocaleString(customRole.RoleLongDescriptionLocale); roleBehaviour.AffectedByLightAffectors = customRole.Configuration.AffectedByLightOnAirship; roleBehaviour.CanBeKilled = customRole.Configuration.CanGetKilled; roleBehaviour.CanUseKillButton = customRole.Configuration.UseVanillaKillButton; @@ -187,7 +187,7 @@ public static class CustomRoleManager if (useTaskHint && !overridesTaskText) { - Error($"Role {customRole.RoleName.Translate()} is using RoleHintType.TaskHint but does not override SpawnTaskHeader!"); + Error($"Role {customRole.RoleName} is using RoleHintType.TaskHint but does not override SpawnTaskHeader!"); } CustomRoles.Add(roleId, roleBehaviour); @@ -255,9 +255,9 @@ public static class CustomRoleManager { var tabText = panel.tab.gameObject.GetComponentInChildren(); var ogPanel = HudManager.Instance.TaskStuff.transform.FindChild("TaskPanel").gameObject.GetComponent(); - if (tabText.text != role.RoleName.Translate()) + if (tabText.text != role.RoleName) { - tabText.text = role.RoleName.Translate(); + tabText.text = role.RoleName; } var y = ogPanel.taskText.textBounds.size.y + 1; diff --git a/MiraAPI/Roles/CustomRoleUtils.cs b/MiraAPI/Roles/CustomRoleUtils.cs index c418a30..d43acbe 100644 --- a/MiraAPI/Roles/CustomRoleUtils.cs +++ b/MiraAPI/Roles/CustomRoleUtils.cs @@ -104,9 +104,9 @@ public static class CustomRoleUtils public static StringBuilder CreateForRole(ICustomRole role) { var taskStringBuilder = new StringBuilder(); - taskStringBuilder.AppendLine(CultureInfo.InvariantCulture, $"{role.RoleColor.ToTextColor()}Your role is {role.RoleName.Translate()}."); + taskStringBuilder.AppendLine(CultureInfo.InvariantCulture, $"{role.RoleColor.ToTextColor()}Your role is {role.RoleName}."); taskStringBuilder.Append(""); - taskStringBuilder.AppendLine(CultureInfo.InvariantCulture, $"{role.RoleLongDescription.Translate()}"); + taskStringBuilder.AppendLine(CultureInfo.InvariantCulture, $"{role.RoleLongDescription}"); return taskStringBuilder; } diff --git a/MiraAPI/Roles/ICustomRole.cs b/MiraAPI/Roles/ICustomRole.cs index 77d4ce8..c214619 100644 --- a/MiraAPI/Roles/ICustomRole.cs +++ b/MiraAPI/Roles/ICustomRole.cs @@ -1,5 +1,4 @@ using System; -using System.Globalization; using System.Text; using BepInEx.Configuration; using MiraAPI.GameOptions; @@ -18,27 +17,57 @@ public interface ICustomRole : IOptionable /// /// Gets the id part used to build the role's translation keys. /// - string IdPart => GetType().Name.ToLower(CultureInfo.InvariantCulture); + string IdPart => GetType().Name; /// /// Gets the name of the role. /// - string RoleName => MiraLocaleManager.BuildTranslationId(IdPart, "name"); + string RoleName => MiraLocaleManager.Get(RoleNameLocale); + + /// + /// Gets the role's name id for localization. + /// + string RoleNameLocale => IdPart; /// /// Gets the description of the role. Used in the Intro Cutscene. /// - string RoleDescription => MiraLocaleManager.BuildTranslationId(IdPart, "description"); + string RoleDescription => MiraLocaleManager.Get(RoleDescriptionLocale); /// - /// Gets the medium description of the role. Used in the role guide. + /// Gets the role's intro blurb id for localization. /// - string RoleMedDescription => RoleDescription; + string RoleDescriptionLocale => MiraLocaleManager.BuildTranslationId(IdPart, "IntroBlurb"); /// - /// Gets the long description of the role. Used in the Role Tab and Role Options. + /// Gets the medium description of the role. Used in the role guide and options menu. /// - string RoleLongDescription => MiraLocaleManager.BuildTranslationId(IdPart, "description"); + string RoleMedDescription => MiraLocaleManager.Get(RoleMedDescriptionLocale); + + /// + /// Gets the role's medium description id for localization. + /// + string RoleMedDescriptionLocale => MiraLocaleManager.BuildTranslationId(IdPart, "MedDescription"); + + /// + /// Gets the long description of the role. Used in the Role Tab. + /// + string RoleLongDescription => MiraLocaleManager.Get(RoleLongDescriptionLocale); + + /// + /// Gets the role's long description id for localization. + /// + string RoleLongDescriptionLocale => MiraLocaleManager.BuildTranslationId(IdPart, "TabDescription"); + + /// + /// Gets the wiki description of the role. Used in the wiki, but not currently required. + /// + string RoleWikiDescription => MiraLocaleManager.Get(RoleLongDescriptionLocale); + + /// + /// Gets the role's wiki description id for localization. + /// + string RoleWikiDescriptionLocale => MiraLocaleManager.BuildTranslationId(IdPart, "WikiDescription"); /// /// Gets the faction / alignment of the role. Used in the role guide. @@ -187,7 +216,7 @@ public interface ICustomRole : IOptionable { if (!Configuration.CanModifyChance) { - Error($"Cannot modify chance for role: {RoleName.Translate()}"); + Error($"Cannot modify chance for role: {RoleName}"); return; } @@ -197,7 +226,7 @@ public interface ICustomRole : IOptionable return; } - Error($"Error getting chance configuration for role: {RoleName.Translate()}"); + Error($"Error getting chance configuration for role: {RoleName}"); } /// @@ -212,7 +241,7 @@ public interface ICustomRole : IOptionable return; } - Error($"Error getting count configuration for role: {RoleName.Translate()}"); + Error($"Error getting count configuration for role: {RoleName}"); } /// @@ -252,7 +281,7 @@ public interface ICustomRole : IOptionable /// A string with a custom ejection message or . string? GetCustomEjectionMessage(NetworkedPlayerInfo player) { - return Team == ModdedRoleTeams.Impostor ? $"{player.PlayerName} was The {RoleName.Translate()}" : null; + return Team == ModdedRoleTeams.Impostor ? $"{player.PlayerName} was The {RoleName}" : null; } /// diff --git a/MiraAPI/Utilities/Helpers.cs b/MiraAPI/Utilities/Helpers.cs index 54f1674..687298e 100644 --- a/MiraAPI/Utilities/Helpers.cs +++ b/MiraAPI/Utilities/Helpers.cs @@ -537,7 +537,7 @@ public static class Helpers { if (role is ICustomRole custom) { - return custom.RoleName.Translate(); + return custom.RoleName; } return role.NiceName; }