Added culture settings
This commit is contained in:
parent
90be288d17
commit
f27366e0a2
@ -2,6 +2,7 @@
|
||||
|
||||
public static class SettingNames
|
||||
{
|
||||
public static readonly string CULTURE = "Culture";
|
||||
public static readonly string DEEPL_ACTION = "DeepL Action";
|
||||
public static readonly string DEEPL_API_KEY = "DeepL API Key";
|
||||
public static readonly string DEEPL_MODE = "DeepL Mode";
|
||||
|
@ -7,6 +7,8 @@ namespace Processor;
|
||||
|
||||
public static class AppSettings
|
||||
{
|
||||
#region DeepL Settings
|
||||
|
||||
#region DeepL Mode
|
||||
|
||||
private static SettingDeepLMode CACHE_DEEPL_MODE = SettingDeepLMode.DISABLED;
|
||||
@ -204,4 +206,80 @@ public static class AppSettings
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region Translation Settings
|
||||
|
||||
#region Number of cultures
|
||||
|
||||
public static async Task<int> GetNumberCultures()
|
||||
{
|
||||
// Get the database:
|
||||
await using var db = ProcessorMeta.ServiceProvider.GetRequiredService<DataContext>();
|
||||
|
||||
// Count the number of cultures:
|
||||
var count = await db.Settings.CountAsync(n => n.Code == SettingNames.CULTURE);
|
||||
|
||||
// We have at least one default culture:
|
||||
if(count == 0)
|
||||
return 1;
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Get a culture
|
||||
|
||||
public static async Task<string> GetCultureCode(int index)
|
||||
{
|
||||
// Get the database:
|
||||
await using var db = ProcessorMeta.ServiceProvider.GetRequiredService<DataContext>();
|
||||
|
||||
// Get the culture code:
|
||||
var code = await db.Settings.FirstOrDefaultAsync(n => n.Code == SettingNames.CULTURE && n.IntegerValue == index);
|
||||
|
||||
// When the culture code is not set, fake the default culture as en-US:
|
||||
if(code == null)
|
||||
return "en-US";
|
||||
|
||||
// Return the code:
|
||||
return code.TextValue;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Set a culture
|
||||
|
||||
public static async Task SetCultureCode(int index, string code)
|
||||
{
|
||||
// Get the database:
|
||||
await using var db = ProcessorMeta.ServiceProvider.GetRequiredService<DataContext>();
|
||||
|
||||
// Check, if the setting is already set:
|
||||
if (await db.Settings.FirstOrDefaultAsync(n => n.Code == SettingNames.CULTURE && n.IntegerValue == index) is {} existingSetting)
|
||||
{
|
||||
existingSetting.TextValue = code;
|
||||
await db.SaveChangesAsync();
|
||||
}
|
||||
|
||||
// Does not exist, so create it:
|
||||
else
|
||||
{
|
||||
var setting = new Setting
|
||||
{
|
||||
Code = SettingNames.CULTURE,
|
||||
IntegerValue = index,
|
||||
TextValue = code,
|
||||
};
|
||||
|
||||
await db.Settings.AddAsync(setting);
|
||||
await db.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
}
|
Loading…
Reference in New Issue
Block a user