diff --git a/I18N Commander/DataModel/Database/SettingNames.cs b/I18N Commander/DataModel/Database/SettingNames.cs index d507d63..d59e7d9 100644 --- a/I18N Commander/DataModel/Database/SettingNames.cs +++ b/I18N Commander/DataModel/Database/SettingNames.cs @@ -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"; diff --git a/I18N Commander/Processor/AppSettings.cs b/I18N Commander/Processor/AppSettings.cs index 90f1f94..a5eee75 100644 --- a/I18N Commander/Processor/AppSettings.cs +++ b/I18N Commander/Processor/AppSettings.cs @@ -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 GetNumberCultures() + { + // Get the database: + await using var db = ProcessorMeta.ServiceProvider.GetRequiredService(); + + // 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 GetCultureCode(int index) + { + // Get the database: + await using var db = ProcessorMeta.ServiceProvider.GetRequiredService(); + + // 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(); + + // 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 } \ No newline at end of file