2025-04-03 12:25:45 +00:00
|
|
|
|
namespace AIStudio.Tools.Services;
|
|
|
|
|
|
|
|
|
|
|
|
public sealed partial class RustService
|
|
|
|
|
|
{
|
2026-02-25 18:30:46 +00:00
|
|
|
|
public async Task<string> ReadUserLanguage(bool forceRequest = false)
|
2025-04-03 12:25:45 +00:00
|
|
|
|
{
|
2026-02-25 18:30:46 +00:00
|
|
|
|
if (!forceRequest && !string.IsNullOrWhiteSpace(this.cachedUserLanguage))
|
|
|
|
|
|
return this.cachedUserLanguage;
|
|
|
|
|
|
|
|
|
|
|
|
await this.userLanguageLock.WaitAsync();
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!forceRequest && !string.IsNullOrWhiteSpace(this.cachedUserLanguage))
|
|
|
|
|
|
return this.cachedUserLanguage;
|
|
|
|
|
|
|
|
|
|
|
|
var response = await this.http.GetAsync("/system/language");
|
|
|
|
|
|
if (!response.IsSuccessStatusCode)
|
|
|
|
|
|
{
|
|
|
|
|
|
this.logger!.LogError($"Failed to read the user language from Rust: '{response.StatusCode}'");
|
|
|
|
|
|
return string.Empty;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var userLanguage = (await response.Content.ReadAsStringAsync()).Trim();
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(userLanguage))
|
|
|
|
|
|
return string.Empty;
|
|
|
|
|
|
|
|
|
|
|
|
this.cachedUserLanguage = userLanguage;
|
|
|
|
|
|
return userLanguage;
|
|
|
|
|
|
}
|
|
|
|
|
|
finally
|
2025-04-03 12:25:45 +00:00
|
|
|
|
{
|
2026-02-25 18:30:46 +00:00
|
|
|
|
this.userLanguageLock.Release();
|
2025-04-03 12:25:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|