diff --git a/Libraries/SPTarkov.Server.Core/Callbacks/DataCallbacks.cs b/Libraries/SPTarkov.Server.Core/Callbacks/DataCallbacks.cs index 9b60baf8..8f740905 100644 --- a/Libraries/SPTarkov.Server.Core/Callbacks/DataCallbacks.cs +++ b/Libraries/SPTarkov.Server.Core/Callbacks/DataCallbacks.cs @@ -11,7 +11,8 @@ public class DataCallbacks( HttpResponseUtil _httpResponseUtil, DatabaseService _databaseService, TraderController _traderController, - HideoutController _hideoutController + HideoutController _hideoutController, + LocaleService _localeService ) { /// @@ -133,10 +134,9 @@ public class DataCallbacks( public string GetLocalesGlobal(string url, EmptyRequestData _, string sessionID) { var localeId = url.Replace("/client/locale/", ""); - var locales = _databaseService.GetLocales(); - var result = locales.Global?[localeId].Value ?? locales.Global?.FirstOrDefault(m => m.Key == "en").Value.Value; + var locales = _localeService.GetLocaleDb(localeId); - return _httpResponseUtil.GetUnclearedBody(result); + return _httpResponseUtil.GetUnclearedBody(locales); } /// diff --git a/Libraries/SPTarkov.Server.Core/Helpers/Dialogue/Commando/SptCommands/GiveCommand/GiveSptCommand.cs b/Libraries/SPTarkov.Server.Core/Helpers/Dialogue/Commando/SptCommands/GiveCommand/GiveSptCommand.cs index 2810c938..0a0e5715 100644 --- a/Libraries/SPTarkov.Server.Core/Helpers/Dialogue/Commando/SptCommands/GiveCommand/GiveSptCommand.cs +++ b/Libraries/SPTarkov.Server.Core/Helpers/Dialogue/Commando/SptCommands/GiveCommand/GiveSptCommand.cs @@ -296,15 +296,13 @@ public class GiveSptCommand( } /// - /// Return the desired locale, falls back to english if it cannot be found + /// Return the desired locale, falls back to english if it cannot be found /// /// Locale code, e.g. "fr" for french /// protected Dictionary GetGlobalsLocale(string desiredLocale) { - return _databaseService.GetLocales().Global.TryGetValue(desiredLocale, out var locale) - ? locale.Value - : _databaseService.GetLocales().Global["en"].Value; + return _localeService.GetLocaleDb(desiredLocale); } /** diff --git a/Libraries/SPTarkov.Server.Core/Services/I18nService.cs b/Libraries/SPTarkov.Server.Core/Services/I18nService.cs index fdfa4cc0..f49ad083 100644 --- a/Libraries/SPTarkov.Server.Core/Services/I18nService.cs +++ b/Libraries/SPTarkov.Server.Core/Services/I18nService.cs @@ -11,7 +11,7 @@ public class I18nService private readonly Dictionary _fallbacks; private readonly FileUtil _fileUtil; private readonly JsonUtil _jsonUtil; - private readonly CustomLocaleService _customLocaleService; + private readonly LocaleService _localeService; private readonly Dictionary>> _loadedLocales = new(); private HashSet _locales; @@ -20,11 +20,11 @@ public class I18nService public I18nService( FileUtil fileUtil, JsonUtil jsonUtil, - CustomLocaleService customLocaleService, HashSet locales, Dictionary fallbacks, string defaultLocale, - string directory + string directory, + LocaleService localeService ) { _locales = locales; @@ -32,8 +32,8 @@ public class I18nService _defaultLocale = defaultLocale; _directory = directory; _jsonUtil = jsonUtil; - _customLocaleService = customLocaleService; _fileUtil = fileUtil; + _localeService = localeService; Initialize(); } @@ -91,22 +91,28 @@ public class I18nService public string GetLocalisedValue(string key) { + // get loaded locales for set key if (!_loadedLocales.TryGetValue(_setLocale, out var locales)) { + // if we are unable to get the "loadedLocales" for the set locale, return the key return key; } + // searching through loaded locales for given key if (!locales.Value.TryGetValue(key, out var value)) { + // if the key is not found in loaded locales + // check if the key is found in the default locale _loadedLocales.TryGetValue(_defaultLocale, out var defaults); if (!defaults.Value.TryGetValue(key, out value)) { - value = _customLocaleService.GetClientValue(_defaultLocale, key); + value = _localeService.GetLocaleDb(_defaultLocale).FirstOrDefault(x => x.Key == key).Value; } return value ?? key; } + // if the key is found in the server locale, return the value return value; } diff --git a/Libraries/SPTarkov.Server.Core/Services/LocalisationService.cs b/Libraries/SPTarkov.Server.Core/Services/LocalisationService.cs index e4a5eb21..681114f6 100644 --- a/Libraries/SPTarkov.Server.Core/Services/LocalisationService.cs +++ b/Libraries/SPTarkov.Server.Core/Services/LocalisationService.cs @@ -22,7 +22,6 @@ public class LocalisationService public LocalisationService( ISptLogger logger, RandomUtil randomUtil, - CustomLocaleService customLocaleService, DatabaseServer databaseServer, LocaleService localeService, JsonUtil jsonUtil, @@ -36,11 +35,11 @@ public class LocalisationService _i18nService = new I18nService( fileUtil, jsonUtil, - customLocaleService, localeService.GetServerSupportedLocales().ToHashSet(), localeService.GetLocaleFallbacks(), "en", - "./Assets/database/locales/server" + "./Assets/database/locales/server", + localeService ); _i18nService.SetLocaleByKey(localeService.GetDesiredServerLocale()); } diff --git a/Libraries/SPTarkov.Server.Core/Services/Mod/CustomItemService.cs b/Libraries/SPTarkov.Server.Core/Services/Mod/CustomItemService.cs index 0339a16c..a9943d17 100644 --- a/Libraries/SPTarkov.Server.Core/Services/Mod/CustomItemService.cs +++ b/Libraries/SPTarkov.Server.Core/Services/Mod/CustomItemService.cs @@ -17,7 +17,8 @@ public class CustomItemService( DatabaseService databaseService, ItemHelper itemHelper, ItemBaseClassService itemBaseClassService, - ICloner cloner + ICloner cloner, + LocaleService localeService ) { /// @@ -206,17 +207,9 @@ public class CustomItemService( newLocaleDetails ??= localeDetails[localeDetails.Keys.FirstOrDefault()]; - // Create new record in locale file - if (!databaseService.GetLocales().Global.TryGetValue(shortNameKey.Key, out var desiredGlobal)) - { - logger.Error($"Unable to add locale keys to {shortNameKey.Key}"); - - return; - } - - desiredGlobal.Value[$"{newItemId} Name"] = newLocaleDetails.Name; - desiredGlobal.Value[$"{newItemId} ShortName"] = newLocaleDetails.ShortName; - desiredGlobal.Value[$"{newItemId} Description"] = newLocaleDetails.Description; + localeService.AddCustomClientLocale(shortNameKey.Key, $"{newItemId} Name", newLocaleDetails.Name); + localeService.AddCustomClientLocale(shortNameKey.Key, $"{newItemId} ShortName", newLocaleDetails.ShortName); + localeService.AddCustomClientLocale(shortNameKey.Key, $"{newItemId} Description", newLocaleDetails.Description); } } diff --git a/Libraries/SPTarkov.Server.Core/Services/SeasonalEventService.cs b/Libraries/SPTarkov.Server.Core/Services/SeasonalEventService.cs index 93868b81..006514d9 100644 --- a/Libraries/SPTarkov.Server.Core/Services/SeasonalEventService.cs +++ b/Libraries/SPTarkov.Server.Core/Services/SeasonalEventService.cs @@ -21,7 +21,8 @@ public class SeasonalEventService( BotHelper _botHelper, ProfileHelper _profileHelper, //DatabaseImporter _databaseImporter, - ConfigServer _configServer + ConfigServer _configServer, + LocaleService _localeService ) { private bool _christmasEventActive; @@ -1060,9 +1061,8 @@ public class SeasonalEventService( protected void RenameBitcoin() { - var enLocale = _databaseService.GetLocales().Global["en"]; - enLocale.Value[$"{ItemTpl.BARTER_PHYSICAL_BITCOIN} Name"] = "Physical SPT Coin"; - enLocale.Value[$"{ItemTpl.BARTER_PHYSICAL_BITCOIN} ShortName"] = "0.2SPT"; + _localeService.AddCustomClientLocale("en", $"{ItemTpl.BARTER_PHYSICAL_BITCOIN} Name", "Physical SPT Coin"); + _localeService.AddCustomClientLocale("en", $"{ItemTpl.BARTER_PHYSICAL_BITCOIN} ShortName", "0.2SPT"); } ///