mirror of
https://github.com/goatcorp/Dalamud.git
synced 2026-01-03 06:13:40 +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
|
|
@ -13,8 +13,11 @@ 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")));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue