diff --git a/Dalamud/Configuration/DalamudConfiguration.cs b/Dalamud/Configuration/DalamudConfiguration.cs index 6953ac76b..e21397326 100644 --- a/Dalamud/Configuration/DalamudConfiguration.cs +++ b/Dalamud/Configuration/DalamudConfiguration.cs @@ -27,6 +27,8 @@ namespace Dalamud public Dictionary PreferredRoleReminders { get; set; } + public string LanguageOverride { get; set; } + public string LastVersion { get; set; } public static DalamudConfiguration Load(string path) { diff --git a/Dalamud/Dalamud.cs b/Dalamud/Dalamud.cs index 08394abd6..c56d481c3 100644 --- a/Dalamud/Dalamud.cs +++ b/Dalamud/Dalamud.cs @@ -23,6 +23,8 @@ using Dalamud.Interface; using Dalamud.Plugin; using ImGuiNET; using Serilog; +using Serilog.Core; +using Serilog.Events; namespace Dalamud { public sealed class Dalamud : IDisposable { @@ -50,6 +52,7 @@ namespace Dalamud { public readonly ClientState ClientState; public readonly DalamudStartInfo StartInfo; + private readonly LoggingLevelSwitch loggingLevelSwitch; public readonly DalamudConfiguration Configuration; @@ -67,14 +70,19 @@ namespace Dalamud { private readonly string assemblyVersion = Assembly.GetAssembly(typeof(ChatHandlers)).GetName().Version.ToString(); - public Dalamud(DalamudStartInfo info) { + public Dalamud(DalamudStartInfo info, LoggingLevelSwitch loggingLevelSwitch) { this.StartInfo = info; - - this.localizationMgr = new Localization(this.StartInfo.WorkingDirectory); - this.localizationMgr.SetupWithUiCulture(); + this.loggingLevelSwitch = loggingLevelSwitch; this.Configuration = DalamudConfiguration.Load(info.ConfigurationPath); - + this.localizationMgr = new Localization(this.StartInfo.WorkingDirectory); + + if (!string.IsNullOrEmpty(this.Configuration.LanguageOverride)) { + this.localizationMgr.SetupWithLangCode(this.Configuration.LanguageOverride); + } else { + this.localizationMgr.SetupWithUiCulture(); + } + this.baseDirectory = info.WorkingDirectory; this.unloadSignal = new ManualResetEvent(false); @@ -207,6 +215,18 @@ namespace Dalamud { this.logWindow = new DalamudLogWindow(); this.isImguiDrawLogWindow = true; } + if (ImGui.BeginMenu("Set log level...")) + { + foreach (var logLevel in Enum.GetValues(typeof(LogEventLevel)).Cast()) { + if (ImGui.MenuItem(logLevel + "##logLevelSwitch", "", this.loggingLevelSwitch.MinimumLevel == logLevel)) + { + this.loggingLevelSwitch.MinimumLevel = logLevel; + } + } + + ImGui.EndMenu(); + } + ImGui.Separator(); if (ImGui.MenuItem("Open Data window")) { this.dataWindow = new DalamudDataWindow(this); @@ -424,6 +444,11 @@ namespace Dalamud { this.CommandManager.AddHandler("/xlcredits", new CommandInfo(OnOpenCreditsCommand) { HelpMessage = Loc.Localize("DalamudCreditsHelp", "Opens the credits for dalamud.") }); + + this.CommandManager.AddHandler("/xllanguage", new CommandInfo(OnSetLanguageCommand) + { + HelpMessage = Loc.Localize("DalamudLanguageHelp", "Set the language for the in-game addon and plugins that support it.") + }); } private void OnUnloadCommand(string command, string arguments) { @@ -624,6 +649,19 @@ namespace Dalamud { this.isImguiDrawCreditsWindow = true; } + private void OnSetLanguageCommand(string command, string arguments) + { + if (Localization.ApplicableLangCodes.Contains(arguments.ToLower())) { + this.localizationMgr.SetupWithLangCode(arguments.ToLower()); + this.Configuration.LanguageOverride = arguments.ToLower(); + } else { + this.localizationMgr.SetupWithUiCulture(); + this.Configuration.LanguageOverride = null; + } + + this.Configuration.Save(this.StartInfo.ConfigurationPath); + } + private int RouletteSlugToKey(string slug) => slug.ToLower() switch { "leveling" => 1, "506070" => 2, diff --git a/Dalamud/EntryPoint.cs b/Dalamud/EntryPoint.cs index 4d5bc571d..3e09596cc 100644 --- a/Dalamud/EntryPoint.cs +++ b/Dalamud/EntryPoint.cs @@ -6,6 +6,7 @@ using Dalamud.Interface; using EasyHook; using Serilog; using Serilog.Core; +using Serilog.Events; namespace Dalamud { public sealed class EntryPoint : IEntryPoint { @@ -15,7 +16,8 @@ namespace Dalamud { public void Run(RemoteHooking.IContext ctx, DalamudStartInfo info) { // Setup logger - Log.Logger = NewLogger(info.WorkingDirectory); + var (logger, levelSwitch) = NewLogger(info.WorkingDirectory); + Log.Logger = logger; try { Log.Information("Initializing a session.."); @@ -28,7 +30,7 @@ namespace Dalamud { AppDomain.CurrentDomain.UnhandledException += OnUnhandledException; TaskScheduler.UnobservedTaskException += OnUnobservedTaskException; - using var dalamud = new Dalamud(info); + using var dalamud = new Dalamud(info, levelSwitch); Log.Information("Starting a session.."); // Run session @@ -44,18 +46,24 @@ namespace Dalamud { } } - private Logger NewLogger(string baseDirectory) { + private (Logger logger, LoggingLevelSwitch levelSwitch) NewLogger(string baseDirectory) { var logPath = Path.Combine(baseDirectory, "dalamud.txt"); - return new LoggerConfiguration() + var levelSwitch = new LoggingLevelSwitch(); + +#if DEBUG + levelSwitch.MinimumLevel = LogEventLevel.Verbose; +#else + levelSwitch.MinimumLevel = LogEventLevel.Information; +#endif + + var newLogger = new LoggerConfiguration() .WriteTo.Async(a => a.File(logPath)) .WriteTo.EventSink() -#if DEBUG - .MinimumLevel.Verbose() -#else - .MinimumLevel.Information() -#endif + .MinimumLevel.ControlledBy(levelSwitch) .CreateLogger(); + + return (newLogger, levelSwitch); } private void OnUnhandledException(object sender, UnhandledExceptionEventArgs arg) { diff --git a/Dalamud/Localization.cs b/Dalamud/Localization.cs index ea791f548..b4a856aeb 100644 --- a/Dalamud/Localization.cs +++ b/Dalamud/Localization.cs @@ -39,6 +39,11 @@ namespace Dalamud } public void SetupWithLangCode(string langCode) { + if (langCode.ToLower() == "en") { + Loc.SetupWithFallbacks(); + return; + } + Loc.Setup(File.ReadAllText(Path.Combine(this.workingDirectory, "UIRes", "loc", "dalamud", $"dalamud_{langCode}.json"))); } }