From 3dbb8905b5d7713003992344303d2a98b49ed3b5 Mon Sep 17 00:00:00 2001 From: Tayrtahn Date: Tue, 10 Jun 2025 20:47:04 -0400 Subject: [PATCH] Add test that entity prototypes don't use LocIds for name/description (#38234) * Add test that entity prototypes don't use LocIds for name/description * Fix violation --- .../EntityPrototypeLocalizationTest.cs | 50 +++++++++++++++++++ .../Locale/en-US/actions/actions/mapping.ftl | 1 - Resources/Prototypes/Actions/mapping.yml | 2 +- 3 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 Content.IntegrationTests/Tests/Localization/EntityPrototypeLocalizationTest.cs delete mode 100644 Resources/Locale/en-US/actions/actions/mapping.ftl diff --git a/Content.IntegrationTests/Tests/Localization/EntityPrototypeLocalizationTest.cs b/Content.IntegrationTests/Tests/Localization/EntityPrototypeLocalizationTest.cs new file mode 100644 index 0000000000..69d44fd08b --- /dev/null +++ b/Content.IntegrationTests/Tests/Localization/EntityPrototypeLocalizationTest.cs @@ -0,0 +1,50 @@ +using Robust.Shared.Localization; +using Robust.Shared.Prototypes; + +namespace Content.IntegrationTests.Tests.Localization; + +public sealed class EntityPrototypeLocalizationTest +{ + /// + /// An explanation of why LocIds should not be used for entity prototype names/descriptions. + /// Appended to the error message when the test is failed. + /// + private const string NoLocIdExplanation = "Entity prototypes should not use LocIds for names/descriptions, as localization IDs are automated for entity prototypes. See https://docs.spacestation14.com/en/ss14-by-example/fluent-and-localization.html#localizing-prototypes for more information."; + + /// + /// Checks that no entity prototypes have a LocId as their name or description. + /// See for why this is important. + /// + [Test] + public async Task TestNoManualEntityLocStrings() + { + await using var pair = await PoolManager.GetServerClient(); + var server = pair.Server; + var protoMan = server.ProtoMan; + var locMan = server.ResolveDependency(); + + var protos = protoMan.EnumeratePrototypes(); + + Assert.Multiple(() => + { + foreach (var proto in protos) + { + // Check name + if (!string.IsNullOrEmpty(proto.SetName)) + { + Assert.That(locMan.HasString(proto.SetName), Is.False, + $"Entity prototype {proto.ID} has a LocId ({proto.SetName}) as a name. {NoLocIdExplanation}"); + } + + // Check description + if (!string.IsNullOrEmpty(proto.SetDesc)) + { + Assert.That(locMan.HasString(proto.SetDesc), Is.False, + $"Entity prototype {proto.ID} has a LocId ({proto.SetDesc}) as a description. {NoLocIdExplanation}"); + } + } + }); + + await pair.CleanReturnAsync(); + } +} diff --git a/Resources/Locale/en-US/actions/actions/mapping.ftl b/Resources/Locale/en-US/actions/actions/mapping.ftl deleted file mode 100644 index ce6c4d9e56..0000000000 --- a/Resources/Locale/en-US/actions/actions/mapping.ftl +++ /dev/null @@ -1 +0,0 @@ -action-name-mapping-erase = Erase Entity \ No newline at end of file diff --git a/Resources/Prototypes/Actions/mapping.yml b/Resources/Prototypes/Actions/mapping.yml index 937fc9263c..f944d715dd 100644 --- a/Resources/Prototypes/Actions/mapping.yml +++ b/Resources/Prototypes/Actions/mapping.yml @@ -28,7 +28,7 @@ - type: entity parent: BaseMappingAction id: ActionMappingEraser - name: action-name-mapping-erase + name: Erase Entity components: - type: Action icon: Interface/VerbIcons/delete.svg.192dpi.png