mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-24 01:19:18 +01:00
add current ui lang and change event
This commit is contained in:
parent
208055b0a4
commit
6ac126a743
3 changed files with 41 additions and 7 deletions
|
|
@ -223,7 +223,7 @@ namespace Dalamud.Interface
|
|||
{
|
||||
if (ImGui.MenuItem("From Fallbacks"))
|
||||
{
|
||||
Loc.SetupWithFallbacks();
|
||||
this.dalamud.LocalizationManager.SetupWithFallbacks();
|
||||
}
|
||||
|
||||
if (ImGui.MenuItem("From UICulture"))
|
||||
|
|
|
|||
|
|
@ -13,7 +13,10 @@ namespace Dalamud
|
|||
class Localization {
|
||||
private readonly string workingDirectory;
|
||||
|
||||
private const string FallbackLangCode = "en";
|
||||
public static readonly string[] ApplicableLangCodes = { "de", "ja", "fr", "it", "es", "ko", "no", "ru" };
|
||||
public delegate void LocalizationChangedDelegate(string langCode);
|
||||
public event LocalizationChangedDelegate OnLocalizationChanged;
|
||||
|
||||
public Localization(string workingDirectory) {
|
||||
this.workingDirectory = workingDirectory;
|
||||
|
|
@ -28,22 +31,28 @@ namespace Dalamud
|
|||
if (ApplicableLangCodes.Any(x => currentUiLang.TwoLetterISOLanguageName == x)) {
|
||||
SetupWithLangCode(currentUiLang.TwoLetterISOLanguageName);
|
||||
} else {
|
||||
Loc.SetupWithFallbacks();
|
||||
SetupWithFallbacks();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, "Could not get language information. Setting up fallbacks.");
|
||||
Loc.SetupWithFallbacks();
|
||||
SetupWithFallbacks();
|
||||
}
|
||||
}
|
||||
|
||||
public void SetupWithFallbacks() {
|
||||
OnLocalizationChanged?.Invoke(FallbackLangCode);
|
||||
Loc.SetupWithFallbacks();
|
||||
}
|
||||
|
||||
public void SetupWithLangCode(string langCode) {
|
||||
if (langCode.ToLower() == "en") {
|
||||
Loc.SetupWithFallbacks();
|
||||
if (langCode.ToLower() == FallbackLangCode) {
|
||||
SetupWithFallbacks();
|
||||
return;
|
||||
}
|
||||
|
||||
OnLocalizationChanged?.Invoke(langCode);
|
||||
Loc.Setup(File.ReadAllText(Path.Combine(this.workingDirectory, "UIRes", "loc", "dalamud", $"dalamud_{langCode}.json")));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -88,6 +88,22 @@ namespace Dalamud.Plugin
|
|||
public bool IsDebugging => this.dalamud.DalamudUi.IsDevMenu;
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Event that gets fired when loc is changed
|
||||
/// </summary>
|
||||
public event LanguageChangedDelegate OnLanguageChanged;
|
||||
|
||||
/// <summary>
|
||||
/// Delegate for localization change with two-letter iso lang code
|
||||
/// </summary>
|
||||
/// <param name="langCode"></param>
|
||||
public delegate void LanguageChangedDelegate(string langCode);
|
||||
|
||||
/// <summary>
|
||||
/// Current ui language in two-letter iso format
|
||||
/// </summary>
|
||||
public string UiLanguage { get; private set; }
|
||||
|
||||
private readonly Dalamud dalamud;
|
||||
private readonly string pluginName;
|
||||
private readonly PluginConfigurations configs;
|
||||
|
|
@ -109,6 +125,14 @@ namespace Dalamud.Plugin
|
|||
this.dalamud = dalamud;
|
||||
this.pluginName = pluginName;
|
||||
this.configs = configs;
|
||||
|
||||
this.UiLanguage = this.dalamud.Configuration.LanguageOverride;
|
||||
dalamud.LocalizationManager.OnLocalizationChanged += OnLocalizationChanged;
|
||||
}
|
||||
|
||||
private void OnLocalizationChanged(string langCode) {
|
||||
this.UiLanguage = langCode;
|
||||
OnLanguageChanged?.Invoke(langCode);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -117,6 +141,7 @@ namespace Dalamud.Plugin
|
|||
public void Dispose() {
|
||||
this.UiBuilder.Dispose();
|
||||
this.Framework.Gui.Chat.RemoveChatLinkHandler(this.pluginName);
|
||||
this.dalamud.LocalizationManager.OnLocalizationChanged -= OnLocalizationChanged;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue