]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Add test that entity prototypes don't use LocIds for name/description (#38234)
authorTayrtahn <tayrtahn@gmail.com>
Wed, 11 Jun 2025 00:47:04 +0000 (20:47 -0400)
committerGitHub <noreply@github.com>
Wed, 11 Jun 2025 00:47:04 +0000 (02:47 +0200)
* Add test that entity prototypes don't use LocIds for name/description

* Fix violation

Content.IntegrationTests/Tests/Localization/EntityPrototypeLocalizationTest.cs [new file with mode: 0644]
Resources/Locale/en-US/actions/actions/mapping.ftl [deleted file]
Resources/Prototypes/Actions/mapping.yml

diff --git a/Content.IntegrationTests/Tests/Localization/EntityPrototypeLocalizationTest.cs b/Content.IntegrationTests/Tests/Localization/EntityPrototypeLocalizationTest.cs
new file mode 100644 (file)
index 0000000..69d44fd
--- /dev/null
@@ -0,0 +1,50 @@
+using Robust.Shared.Localization;
+using Robust.Shared.Prototypes;
+
+namespace Content.IntegrationTests.Tests.Localization;
+
+public sealed class EntityPrototypeLocalizationTest
+{
+    /// <summary>
+    /// An explanation of why LocIds should not be used for entity prototype names/descriptions.
+    /// Appended to the error message when the test is failed.
+    /// </summary>
+    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.";
+
+    /// <summary>
+    /// Checks that no entity prototypes have a LocId as their name or description.
+    /// See <see href="https://docs.spacestation14.com/en/ss14-by-example/fluent-and-localization.html#localizing-prototypes"/> for why this is important.
+    /// </summary>
+    [Test]
+    public async Task TestNoManualEntityLocStrings()
+    {
+        await using var pair = await PoolManager.GetServerClient();
+        var server = pair.Server;
+        var protoMan = server.ProtoMan;
+        var locMan = server.ResolveDependency<ILocalizationManager>();
+
+        var protos = protoMan.EnumeratePrototypes<EntityPrototype>();
+
+        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 (file)
index ce6c4d9..0000000
+++ /dev/null
@@ -1 +0,0 @@
-action-name-mapping-erase = Erase Entity
\ No newline at end of file
index 937fc9263c74adc0e39e50193ab46acea5371ffd..f944d715dda29273e96ec4de737b95ee66ea49e2 100644 (file)
@@ -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