]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Localize preset labels on chem dispenser (#24617)
authorErrant <35878406+Errant-4@users.noreply.github.com>
Sun, 28 Jan 2024 22:31:16 +0000 (23:31 +0100)
committerGitHub <noreply@github.com>
Sun, 28 Jan 2024 22:31:16 +0000 (14:31 -0800)
Content.Server/Labels/Label/Components/LabelComponent.cs
Content.Server/Labels/Label/LabelSystem.cs
Resources/Prototypes/Entities/Objects/Specific/chemical-containers.yml

index d697d6260a62d3a7e7b97351ad67c14191402c80..a23acc55da56f7aef654147fd758dc840d48715a 100644 (file)
@@ -7,12 +7,17 @@ namespace Content.Server.Labels.Components
     public sealed partial class LabelComponent : Component
     {
         /// <summary>
-        /// The actual text in the label
+        /// Current text on the label. If set before map init, during map init this string will be localized.
+        /// This permits localized preset labels with fallback to the text written on the label.
         /// </summary>
         [ViewVariables(VVAccess.ReadWrite)]
         [DataField("currentLabel")]
         public string? CurrentLabel { get; set; }
 
+        /// <summary>
+        ///  The original name of the entity
+        ///  Used for reverting the modified entity name when the label is removed
+        /// </summary>
         [DataField("originalName")]
         public string? OriginalName { get; set; }
     }
index d20295d072718a48bc601cbf6313ae136caef651..69b4b47f4cdbfc4dfb0f5bb949ec5bd338956758 100644 (file)
@@ -27,6 +27,7 @@ namespace Content.Server.Labels
             base.Initialize();
 
             SubscribeLocalEvent<LabelComponent, ExaminedEvent>(OnExamine);
+            SubscribeLocalEvent<LabelComponent, MapInitEvent>(OnLabelCompMapInit);
             SubscribeLocalEvent<PaperLabelComponent, ComponentInit>(OnComponentInit);
             SubscribeLocalEvent<PaperLabelComponent, ComponentRemove>(OnComponentRemove);
             SubscribeLocalEvent<PaperLabelComponent, EntInsertedIntoContainerMessage>(OnContainerModified);
@@ -34,6 +35,12 @@ namespace Content.Server.Labels
             SubscribeLocalEvent<PaperLabelComponent, ExaminedEvent>(OnExamined);
         }
 
+        private void OnLabelCompMapInit(EntityUid uid, LabelComponent component, MapInitEvent args)
+        {
+            if (!string.IsNullOrEmpty(component.CurrentLabel))
+                component.CurrentLabel = Loc.GetString(component.CurrentLabel);
+        }
+
         /// <summary>
         /// Apply or remove a label on an entity.
         /// </summary>
index 01f5e45c471a15b63a1c0580a910bd29d0c5fa73..c8a204e11531a5bf7c2f0fa807f2df959b905bcd 100644 (file)
@@ -58,7 +58,7 @@
   noSpawn: true
   components:
     - type: Label
-      currentLabel: carbon
+      currentLabel: reagent-name-carbon
     - type: SolutionContainerManager
       solutions:
         beaker:
@@ -73,7 +73,7 @@
   noSpawn: true
   components:
     - type: Label
-      currentLabel: iodine
+      currentLabel: reagent-name-iodine
     - type: SolutionContainerManager
       solutions:
         beaker:
@@ -88,7 +88,7 @@
   noSpawn: true
   components:
     - type: Label
-      currentLabel: fluorine
+      currentLabel: reagent-name-fluorine
     - type: SolutionContainerManager
       solutions:
         beaker:
   noSpawn: true
   components:
     - type: Label
-      currentLabel: chlorine
+      currentLabel: reagent-name-chlorine
     - type: SolutionContainerManager
       solutions:
         beaker:
   noSpawn: true
   components:
     - type: Label
-      currentLabel: aluminium
+      currentLabel: reagent-name-aluminium
     - type: SolutionContainerManager
       solutions:
         beaker:
   noSpawn: true
   components:
     - type: Label
-      currentLabel: phosphorus
+      currentLabel: reagent-name-phosphorus
     - type: SolutionContainerManager
       solutions:
         beaker:
   noSpawn: true
   components:
     - type: Label
-      currentLabel: sulfur
+      currentLabel: reagent-name-sulfur
     - type: SolutionContainerManager
       solutions:
         beaker:
   noSpawn: true
   components:
     - type: Label
-      currentLabel: silicon
+      currentLabel: reagent-name-silicon
     - type: SolutionContainerManager
       solutions:
         beaker:
   noSpawn: true
   components:
     - type: Label
-      currentLabel: hydrogen
+      currentLabel: reagent-name-hydrogen
     - type: SolutionContainerManager
       solutions:
         beaker:
   noSpawn: true
   components:
     - type: Label
-      currentLabel: lithium
+      currentLabel: reagent-name-lithium
     - type: SolutionContainerManager
       solutions:
         beaker:
   noSpawn: true
   components:
     - type: Label
-      currentLabel: sodium
+      currentLabel: reagent-name-sodium
     - type: SolutionContainerManager
       solutions:
         beaker:
   noSpawn: true
   components:
     - type: Label
-      currentLabel: potassium
+      currentLabel: reagent-name-potassium
     - type: SolutionContainerManager
       solutions:
         beaker:
   noSpawn: true
   components:
     - type: Label
-      currentLabel: radium
+      currentLabel: reagent-name-radium
     - type: SolutionContainerManager
       solutions:
         beaker:
   noSpawn: true
   components:
     - type: Label
-      currentLabel: iron
+      currentLabel: reagent-name-iron
     - type: SolutionContainerManager
       solutions:
         beaker:
   noSpawn: true
   components:
     - type: Label
-      currentLabel: copper
+      currentLabel: reagent-name-copper
     - type: SolutionContainerManager
       solutions:
         beaker:
   noSpawn: true
   components:
     - type: Label
-      currentLabel: gold
+      currentLabel: reagent-name-gold
     - type: SolutionContainerManager
       solutions:
         beaker:
   noSpawn: true
   components:
     - type: Label
-      currentLabel: mercury
+      currentLabel: reagent-name-mercury
     - type: SolutionContainerManager
       solutions:
         beaker:
   noSpawn: true
   components:
     - type: Label
-      currentLabel: silver
+      currentLabel: reagent-name-silver
     - type: SolutionContainerManager
       solutions:
         beaker:
   noSpawn: true
   components:
     - type: Label
-      currentLabel: ethanol
+      currentLabel: reagent-name-ethanol
     - type: SolutionContainerManager
       solutions:
         beaker:
   noSpawn: true
   components:
     - type: Label
-      currentLabel: sugar
+      currentLabel: reagent-name-sugar
     - type: SolutionContainerManager
       solutions:
         beaker:
   noSpawn: true
   components:
     - type: Label
-      currentLabel: nitrogen
+      currentLabel: reagent-name-nitrogen
     - type: SolutionContainerManager
       solutions:
         beaker:
   noSpawn: true
   components:
     - type: Label
-      currentLabel: oxygen
+      currentLabel: reagent-name-oxygen
     - type: SolutionContainerManager
       solutions:
         beaker:
   noSpawn: true
   components:
     - type: Label
-      currentLabel: Plant-B-Gone
+      currentLabel: reagent-name-plant-b-gone
     - type: SolutionContainerManager
       solutions:
         beaker:
   noSpawn: true
   components:
     - type: Label
-      currentLabel: welding fuel
+      currentLabel: reagent-name-welding-fuel
     - type: SolutionContainerManager
       solutions:
         beaker: