Skip to content

Commit

Permalink
Merge pull request #528 from sailro/extract-strings
Browse files Browse the repository at this point in the history
[WIP] Extract strings
  • Loading branch information
sailro authored Aug 5, 2024
2 parents 7f6f294 + 7dac973 commit 0b974fe
Show file tree
Hide file tree
Showing 80 changed files with 4,703 additions and 235 deletions.
1 change: 1 addition & 0 deletions .github/RELEASE_TEMPLATE/content.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,6 @@ This is an universal installer for the trainer. In most cases you just need to r
- `Installer -c <command>` to disable a command. Example: `Installer -c Spawn`.
- `Installer uninstall` to remove the trainer.
- `Installer uninstall "C:\Battlestate Games\EFT"` to remove the trainer, adding `C:\Battlestate Games\EFT` to the search list.
- `Installer -l <language>` to compile the trainer for a specific language (like `fr`). See the supported ones [here](https://github.com/sailro/EscapeFromTarkov-Trainer/tree/master/Properties).

[![Sponsor](https://img.shields.io/badge/sponsor-%E2%9D%A4-lightgrey?logo=github&style=flat-square)](https://github.com/sponsors/sailro)
2 changes: 1 addition & 1 deletion BepInExPlugin/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

[assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyProduct("EFT Trainer, BepInEx plugin")]
[assembly: AssemblyCopyright("Copyright © 2023 Sebastien Lebreton")]
[assembly: AssemblyCopyright("Copyright © 2024 Sebastien Lebreton")]
45 changes: 27 additions & 18 deletions Configuration/ConfigurationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Reflection;
using System.Text;
using EFT.Trainer.Features;
using EFT.Trainer.Properties;
using EFT.UI;
using Newtonsoft.Json;

Expand All @@ -28,7 +29,7 @@ public static void Load(string filename, Feature[] features, bool warnIfNotExist
if (!File.Exists(filename))
{
if (warnIfNotExists)
AddConsoleLog($"{filename} not found!");
AddConsoleLog(string.Format(Strings.ErrorFileNotFoundFormat, filename));

return;
}
Expand All @@ -54,16 +55,16 @@ public static void Load(string filename, Feature[] features, bool warnIfNotExist
}
catch (JsonException)
{
AddConsoleLog($"{key} seems corrupted in {filename}. Please fix.".Red());
AddConsoleLog(string.Format(Strings.ErrorCorruptedPropertyFormat, key, filename).Red());
}
}
}

AddConsoleLog($"Loaded {filename}");
AddConsoleLog(string.Format(Strings.CommandLoadSuccessFormat, filename));
}
catch (Exception ioe)
{
AddConsoleLog($"Unable to load {filename}. {ioe.Message}".Red());
AddConsoleLog(string.Format(Strings.ErrorCannotLoadFormat, filename, ioe.Message).Red());
}
}

Expand All @@ -73,7 +74,7 @@ public static void LoadPropertyValue(string filename, Feature feature, string pr
{
if (!File.Exists(filename))
{
AddConsoleLog($"{filename} not found!");
AddConsoleLog(string.Format(Strings.ErrorFileNotFoundFormat, filename).Red());
return;
}

Expand All @@ -89,14 +90,14 @@ public static void LoadPropertyValue(string filename, Feature feature, string pr
}
catch (JsonException)
{
AddConsoleLog($"{filename} seems corrupted. Please fix.".Red());
AddConsoleLog(string.Format(Strings.ErrorCorruptedFileFormat, filename).Red());
}

AddConsoleLog($"Loaded {filename}");
AddConsoleLog(string.Format(Strings.CommandLoadSuccessFormat, filename));
}
catch (Exception ioe)
{
AddConsoleLog($"Unable to load {filename}. {ioe.Message}".Red());
AddConsoleLog(string.Format(Strings.ErrorCannotLoadFormat, filename, ioe.Message).Red());
}
}

Expand All @@ -105,9 +106,7 @@ public static void Save(string filename, Feature[] features)
try
{
var content = new StringBuilder();
content.AppendLine("; Be careful when updating this file :)");
content.AppendLine("; For keys, use https://docs.unity3d.com/ScriptReference/KeyCode.html");
content.AppendLine("; Colors are stored as an array of 'RGBA' floats");
content.AppendLine(Comment(Strings.CommandSaveHeader));
content.AppendLine();

foreach (var feature in features.OrderBy(f => f.GetType().FullName))
Expand All @@ -120,9 +119,9 @@ public static void Save(string filename, Feature[] features)
var key = $"{featureType.FullName}.{op.Property.Name}";
var value = JsonConvert.SerializeObject(op.Property.GetValue(feature), Formatting.None, Converters);

var comment = op.Attribute.Comment;
if (!string.IsNullOrEmpty(comment))
content.AppendLine($"; {comment}");
var resourceId = op.Attribute.CommentResourceId;
if (!string.IsNullOrEmpty(resourceId))
content.AppendLine(Comment(Strings.ResourceManager.GetString(resourceId)));

content.AppendLine($"{key}={value}");
}
Expand All @@ -132,14 +131,24 @@ public static void Save(string filename, Feature[] features)
}

File.WriteAllText(filename, content.ToString());
AddConsoleLog($"Saved {filename}");
AddConsoleLog(string.Format(Strings.CommandSaveSuccessFormat, filename));
}
catch (Exception ioe)
{
AddConsoleLog($"Unable to save {filename}. {ioe.Message}".Red());
AddConsoleLog(string.Format(Strings.ErrorCannotSaveFormat, filename, ioe.Message).Red());
}
}

private static string Comment(string? value)
{
if (string.IsNullOrEmpty(value))
return string.Empty;

const string commentToken = "; ";

return commentToken + value!.Replace(Environment.NewLine, Environment.NewLine + commentToken);
}

public static void SavePropertyValue(string filename, Feature feature, string propertyName)
{
try
Expand All @@ -150,11 +159,11 @@ public static void SavePropertyValue(string filename, Feature feature, string pr
var content = JsonConvert.SerializeObject(tlProperty.Property.GetValue(feature), Formatting.Indented, Converters);
File.WriteAllText(filename, content);

AddConsoleLog($"Saved {filename}");
AddConsoleLog(string.Format(Strings.CommandSaveSuccessFormat, filename));
}
catch (Exception ioe)
{
AddConsoleLog($"Unable to save {filename}. {ioe.Message}".Red());
AddConsoleLog(string.Format(Strings.ErrorCannotSaveFormat, filename, ioe.Message).Red());
}
}

Expand Down
2 changes: 1 addition & 1 deletion Configuration/ConfigurationPropertyAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ public class ConfigurationPropertyAttribute : Attribute
{
public bool Skip { get; set; } = false;
public int Order { get; set; } = int.MaxValue;
public string Comment { get; set; } = string.Empty;
public string CommentResourceId { get; set; } = string.Empty;
public bool Browsable { get; set; } = true;
}
3 changes: 2 additions & 1 deletion Configuration/TrackedItemConverter.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using EFT.Trainer.Features;
using EFT.Trainer.Properties;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

Expand Down Expand Up @@ -27,7 +28,7 @@ public override object ReadJson(JsonReader reader, Type objectType, object? exis
{
string name => new TrackedItem(name),
JObject jobject => jobject.ToObject<TrackedItem>()!,
_ => new TrackedItem("corrupted trainer.ini")
_ => new TrackedItem(string.Format(Strings.ErrorCorruptedFileFormat, "trainer.ini"))
};
}

Expand Down
9 changes: 5 additions & 4 deletions ConsoleCommands/BaseListCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using EFT.InventoryLogic;
using EFT.Trainer.Extensions;
using EFT.Trainer.Features;
using EFT.Trainer.Properties;
using JsonType;

#nullable enable
Expand Down Expand Up @@ -62,14 +63,14 @@ private void ListLootItems(Match match, ELootRarity? rarityFilter = null)
if (rarityFilter.HasValue && rarityFilter.Value != rarity)
continue;

var extra = rarity != ELootRarity.Not_exist ? $" ({rarity.Color()})" : string.Empty;
AddConsoleLog($"{itemName} [{list.Count.ToString().Cyan()}]{extra}");
var extra = rarity != ELootRarity.Not_exist ? string.Format(Strings.CommandListRarityFormat, rarity.Color()) : string.Empty;
AddConsoleLog(string.Format(Strings.CommandListEnumerateFormat, itemName, list.Count.ToString().Cyan(), extra));

count += list.Count;
}

AddConsoleLog("------");
AddConsoleLog($"found {count.ToString().Cyan()} item(s)");
AddConsoleLog(Strings.TextSeparator);
AddConsoleLog(string.Format(Strings.CommandListSuccessFormat, count.ToString().Cyan()));
}

private static void FindItemsInRootItem(Dictionary<string, List<Item>> itemsPerName, Item? rootItem)
Expand Down
5 changes: 3 additions & 2 deletions ConsoleCommands/ConsoleCommandWithArgument.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Text.RegularExpressions;
using EFT.Trainer.Properties;
using EFT.UI;

#nullable enable
Expand All @@ -20,7 +21,7 @@ internal abstract class ConsoleCommandWithArgument : ConsoleCommand
public override void Register()
{
#if DEBUG
AddConsoleLog($"Registering {Name} command with arguments...");
AddConsoleLog(string.Format(Strings.DebugRegisteringCommandWithArgumentsFormat, Name));
#endif
ConsoleScreen.Processor.RegisterCommand(Name, (string args) =>
{
Expand All @@ -31,7 +32,7 @@ public override void Register()
}
else
{
ConsoleScreen.LogError("Invalid arguments");
AddConsoleLog(Strings.ErrorInvalidArguments.Red());
}
});
}
Expand Down
5 changes: 3 additions & 2 deletions ConsoleCommands/ConsoleCommandWithoutArgument.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using EFT.UI;
using EFT.Trainer.Properties;
using EFT.UI;

#nullable enable

Expand All @@ -11,7 +12,7 @@ internal abstract class ConsoleCommandWithoutArgument : ConsoleCommand
public override void Register()
{
#if DEBUG
AddConsoleLog($"Registering {Name} command...");
AddConsoleLog(string.Format(Strings.DebugRegisteringCommandFormat, Name));
#endif
ConsoleScreen.Processor.RegisterCommand(Name, Execute);
}
Expand Down
9 changes: 5 additions & 4 deletions ConsoleCommands/Dump.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.IO;
using EFT.Trainer.Features;
using EFT.Trainer.Properties;
using JetBrains.Annotations;
using UnityEngine;
using UnityEngine.SceneManagement;
Expand All @@ -12,7 +13,7 @@ namespace EFT.Trainer.ConsoleCommands;
[UsedImplicitly]
internal class Dump : ConsoleCommandWithoutArgument
{
public override string Name => "dump";
public override string Name => Strings.CommandDump;

public override void Execute()
{
Expand All @@ -21,7 +22,7 @@ public override void Execute()

Directory.CreateDirectory(thisDump);

AddConsoleLog("Dumping scenes...");
AddConsoleLog(Strings.CommandDumpScenes);
for (int i = 0; i < SceneManager.sceneCount; i++)
{
var scene = SceneManager.GetSceneAt(i);
Expand All @@ -32,7 +33,7 @@ public override void Execute()
File.WriteAllText(Path.Combine(thisDump, GetSafeFilename($"@scene - {scene.name}.txt")), json);
}

AddConsoleLog("Dumping game objects...");
AddConsoleLog(Strings.CommandDumpGameObjects);
foreach (var go in UnityEngine.Object.FindObjectsOfType<GameObject>())
{
if (go == null || go.transform.parent != null || !go.activeSelf)
Expand All @@ -43,7 +44,7 @@ public override void Execute()
File.WriteAllText(Path.Combine(thisDump, filename), json);
}

AddConsoleLog($"Dump created in {thisDump}");
AddConsoleLog(string.Format(Strings.CommandDumpSuccessFormat, thisDump));
}

private static string GetSafeFilename(string filename)
Expand Down
5 changes: 3 additions & 2 deletions ConsoleCommands/List.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using JetBrains.Annotations;
using EFT.Trainer.Properties;
using JetBrains.Annotations;

#nullable enable

Expand All @@ -7,5 +8,5 @@ namespace EFT.Trainer.ConsoleCommands;
[UsedImplicitly]
internal class List : BaseListCommand
{
public override string Name => "list";
public override string Name => Strings.CommandList;
}
5 changes: 3 additions & 2 deletions ConsoleCommands/ListRare.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using JetBrains.Annotations;
using EFT.Trainer.Properties;
using JetBrains.Annotations;
using JsonType;

#nullable enable
Expand All @@ -8,6 +9,6 @@ namespace EFT.Trainer.ConsoleCommands;
[UsedImplicitly]
internal class ListRare : BaseListCommand
{
public override string Name => "listr";
public override string Name => Strings.CommandListRare;
protected override ELootRarity? Rarity => ELootRarity.Rare;
}
5 changes: 3 additions & 2 deletions ConsoleCommands/ListSuperRare.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using JetBrains.Annotations;
using EFT.Trainer.Properties;
using JetBrains.Annotations;
using JsonType;

#nullable enable
Expand All @@ -8,6 +9,6 @@ namespace EFT.Trainer.ConsoleCommands;
[UsedImplicitly]
internal class ListSuperRare : BaseListCommand
{
public override string Name => "listsr";
public override string Name => Strings.CommandListSuperRare;
protected override ELootRarity? Rarity => ELootRarity.Superrare;
}
3 changes: 2 additions & 1 deletion ConsoleCommands/LoadTrackList.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Text.RegularExpressions;
using EFT.Trainer.Configuration;
using EFT.Trainer.Properties;
using JetBrains.Annotations;

#nullable enable
Expand All @@ -9,7 +10,7 @@ namespace EFT.Trainer.ConsoleCommands;
[UsedImplicitly]
internal class LoadTrackList : BaseTrackListCommand
{
public override string Name => "loadtl";
public override string Name => Strings.CommandLoadTrackList;

public override void Execute(Match match)
{
Expand Down
3 changes: 2 additions & 1 deletion ConsoleCommands/SaveTrackList.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Text.RegularExpressions;
using EFT.Trainer.Configuration;
using EFT.Trainer.Properties;
using JetBrains.Annotations;

#nullable enable
Expand All @@ -9,7 +10,7 @@ namespace EFT.Trainer.ConsoleCommands;
[UsedImplicitly]
internal class SaveTrackList : BaseTrackListCommand
{
public override string Name => "savetl";
public override string Name => Strings.CommandSaveTrackList;

public override void Execute(Match match)
{
Expand Down
Loading

0 comments on commit 0b974fe

Please sign in to comment.