Skip to content

Commit

Permalink
fix: Fixes language casing and adds localization reset command (#1703)
Browse files Browse the repository at this point in the history
  • Loading branch information
kamronbatman authored Mar 9, 2024
1 parent 1147a80 commit b5342a8
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
12 changes: 11 additions & 1 deletion Projects/Server/Localization/Localization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static class Localization
public const string FallbackLanguage = "enu";

private static Dictionary<int, LocalizationEntry> _fallbackEntries;
private static Dictionary<string, Dictionary<int, LocalizationEntry>> _localizations = new();
private static readonly Dictionary<string, Dictionary<int, LocalizationEntry>> _localizations = new();

public static void Configure()
{
Expand All @@ -44,6 +44,7 @@ public static void Configure()

public static void Add(string lang, int number, string text)
{
lang = lang.ToLower();
var entry = new LocalizationEntry(lang, number, text);
if (!_localizations.TryGetValue(lang, out var entries))
{
Expand All @@ -60,6 +61,7 @@ public static void Add(string lang, int number, string text)

public static bool Remove(string lang, int number)
{
lang = lang.ToLower();
if (!_localizations.TryGetValue(lang, out var entries) || !entries.Remove(number))
{
return false;
Expand All @@ -73,11 +75,18 @@ public static bool Remove(string lang, int number)
return true;
}

public static void Clear()
{
_localizations.Clear();
_fallbackEntries = null;
}

public static Dictionary<int, LocalizationEntry> LoadClilocs(string lang) =>
LoadClilocs(lang, Core.FindDataFile($"cliloc.{lang}", false));

private static Dictionary<int, LocalizationEntry> LoadClilocs(string lang, string file)
{
lang = lang.ToLower();
Dictionary<int, LocalizationEntry> entries = _localizations[lang] = new Dictionary<int, LocalizationEntry>();
if (lang == FallbackLanguage)
{
Expand Down Expand Up @@ -145,6 +154,7 @@ public static bool TryGetLocalization(int number, out LocalizationEntry entry) =
/// <returns>True if the entry exists, otherwise false.</returns>
public static bool TryGetLocalization(string lang, int number, out LocalizationEntry entry)
{
lang = lang.ToLower();
if (lang != FallbackLanguage)
{
if (!_localizations.TryGetValue(lang, out var entries))
Expand Down
20 changes: 20 additions & 0 deletions Projects/UOContent/Commands/ResetLocalization.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
namespace Server.Commands;

public static class ResetLocalization
{
public static void Configure()
{
CommandSystem.Register("ResetLocalization", AccessLevel.Developer, ResetLocalization_OnCommand);
}

[Usage("ResetLocalization [<command>]")]
[Aliases("ResetLoc")]
[Description(
"Clears the localization table. Cliloc will be reloaded the next time they are used for that language."
)]
private static void ResetLocalization_OnCommand(CommandEventArgs e)
{
Localization.Clear();
e.Mobile.SendMessage("Localization table cleared.");
}
}
Binary file modified docs/commands/commands.7z
Binary file not shown.

0 comments on commit b5342a8

Please sign in to comment.