Update uasges to use LocalService
This commit is contained in:
@@ -11,7 +11,8 @@ public class DataCallbacks(
|
||||
HttpResponseUtil _httpResponseUtil,
|
||||
DatabaseService _databaseService,
|
||||
TraderController _traderController,
|
||||
HideoutController _hideoutController
|
||||
HideoutController _hideoutController,
|
||||
LocaleService _localeService
|
||||
)
|
||||
{
|
||||
/// <summary>
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
+2
-4
@@ -296,15 +296,13 @@ public class GiveSptCommand(
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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
|
||||
/// </summary>
|
||||
/// <param name="desiredLocale">Locale code, e.g. "fr" for french</param>
|
||||
/// <returns></returns>
|
||||
protected Dictionary<string, string> GetGlobalsLocale(string desiredLocale)
|
||||
{
|
||||
return _databaseService.GetLocales().Global.TryGetValue(desiredLocale, out var locale)
|
||||
? locale.Value
|
||||
: _databaseService.GetLocales().Global["en"].Value;
|
||||
return _localeService.GetLocaleDb(desiredLocale);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -11,7 +11,7 @@ public class I18nService
|
||||
private readonly Dictionary<string, string> _fallbacks;
|
||||
private readonly FileUtil _fileUtil;
|
||||
private readonly JsonUtil _jsonUtil;
|
||||
private readonly CustomLocaleService _customLocaleService;
|
||||
private readonly LocaleService _localeService;
|
||||
|
||||
private readonly Dictionary<string, LazyLoad<Dictionary<string, string>>> _loadedLocales = new();
|
||||
private HashSet<string> _locales;
|
||||
@@ -20,11 +20,11 @@ public class I18nService
|
||||
public I18nService(
|
||||
FileUtil fileUtil,
|
||||
JsonUtil jsonUtil,
|
||||
CustomLocaleService customLocaleService,
|
||||
HashSet<string> locales,
|
||||
Dictionary<string, string> 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;
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,6 @@ public class LocalisationService
|
||||
public LocalisationService(
|
||||
ISptLogger<LocalisationService> 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());
|
||||
}
|
||||
|
||||
@@ -17,7 +17,8 @@ public class CustomItemService(
|
||||
DatabaseService databaseService,
|
||||
ItemHelper itemHelper,
|
||||
ItemBaseClassService itemBaseClassService,
|
||||
ICloner cloner
|
||||
ICloner cloner,
|
||||
LocaleService localeService
|
||||
)
|
||||
{
|
||||
/// <summary>
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user