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"))
|
if (ImGui.MenuItem("From Fallbacks"))
|
||||||
{
|
{
|
||||||
Loc.SetupWithFallbacks();
|
this.dalamud.LocalizationManager.SetupWithFallbacks();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ImGui.MenuItem("From UICulture"))
|
if (ImGui.MenuItem("From UICulture"))
|
||||||
|
|
|
||||||
|
|
@ -13,8 +13,11 @@ namespace Dalamud
|
||||||
class Localization {
|
class Localization {
|
||||||
private readonly string workingDirectory;
|
private readonly string workingDirectory;
|
||||||
|
|
||||||
|
private const string FallbackLangCode = "en";
|
||||||
public static readonly string[] ApplicableLangCodes = { "de", "ja", "fr", "it", "es", "ko", "no", "ru" };
|
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) {
|
public Localization(string workingDirectory) {
|
||||||
this.workingDirectory = workingDirectory;
|
this.workingDirectory = workingDirectory;
|
||||||
}
|
}
|
||||||
|
|
@ -28,22 +31,28 @@ namespace Dalamud
|
||||||
if (ApplicableLangCodes.Any(x => currentUiLang.TwoLetterISOLanguageName == x)) {
|
if (ApplicableLangCodes.Any(x => currentUiLang.TwoLetterISOLanguageName == x)) {
|
||||||
SetupWithLangCode(currentUiLang.TwoLetterISOLanguageName);
|
SetupWithLangCode(currentUiLang.TwoLetterISOLanguageName);
|
||||||
} else {
|
} else {
|
||||||
Loc.SetupWithFallbacks();
|
SetupWithFallbacks();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Log.Error(ex, "Could not get language information. Setting up fallbacks.");
|
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) {
|
public void SetupWithLangCode(string langCode) {
|
||||||
if (langCode.ToLower() == "en") {
|
if (langCode.ToLower() == FallbackLangCode) {
|
||||||
Loc.SetupWithFallbacks();
|
SetupWithFallbacks();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
OnLocalizationChanged?.Invoke(langCode);
|
||||||
Loc.Setup(File.ReadAllText(Path.Combine(this.workingDirectory, "UIRes", "loc", "dalamud", $"dalamud_{langCode}.json")));
|
Loc.Setup(File.ReadAllText(Path.Combine(this.workingDirectory, "UIRes", "loc", "dalamud", $"dalamud_{langCode}.json")));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -87,7 +87,23 @@ namespace Dalamud.Plugin
|
||||||
#else
|
#else
|
||||||
public bool IsDebugging => this.dalamud.DalamudUi.IsDevMenu;
|
public bool IsDebugging => this.dalamud.DalamudUi.IsDevMenu;
|
||||||
#endif
|
#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 Dalamud dalamud;
|
||||||
private readonly string pluginName;
|
private readonly string pluginName;
|
||||||
private readonly PluginConfigurations configs;
|
private readonly PluginConfigurations configs;
|
||||||
|
|
@ -109,6 +125,14 @@ namespace Dalamud.Plugin
|
||||||
this.dalamud = dalamud;
|
this.dalamud = dalamud;
|
||||||
this.pluginName = pluginName;
|
this.pluginName = pluginName;
|
||||||
this.configs = configs;
|
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>
|
/// <summary>
|
||||||
|
|
@ -117,6 +141,7 @@ namespace Dalamud.Plugin
|
||||||
public void Dispose() {
|
public void Dispose() {
|
||||||
this.UiBuilder.Dispose();
|
this.UiBuilder.Dispose();
|
||||||
this.Framework.Gui.Chat.RemoveChatLinkHandler(this.pluginName);
|
this.Framework.Gui.Chat.RemoveChatLinkHandler(this.pluginName);
|
||||||
|
this.dalamud.LocalizationManager.OnLocalizationChanged -= OnLocalizationChanged;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue