From 876993e62037c68bd0badcfa95a4cf2688e543c2 Mon Sep 17 00:00:00 2001
From: goat <16760685+goaaats@users.noreply.github.com>
Date: Wed, 31 Mar 2021 15:26:16 +0200
Subject: [PATCH] refactor: new code style in Localization.cs
---
Dalamud/Localization.cs | 85 +++++++++++++++++++++++++++++------------
1 file changed, 61 insertions(+), 24 deletions(-)
diff --git a/Dalamud/Localization.cs b/Dalamud/Localization.cs
index b109db62d..ad2e06dd8 100644
--- a/Dalamud/Localization.cs
+++ b/Dalamud/Localization.cs
@@ -1,58 +1,95 @@
using System;
-using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
+
using CheapLoc;
using Serilog;
namespace Dalamud
-{
- class Localization {
- private readonly string workingDirectory;
+{
+ ///
+ /// Class handling localization.
+ ///
+ public class Localization
+ {
+ ///
+ /// Array of language codes which have a valid translation in Dalamud.
+ ///
+ public static readonly string[] ApplicableLangCodes = { "de", "ja", "fr", "it", "es", "ko", "no", "ru" };
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) {
+
+ private readonly string workingDirectory;
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The working directory to load language files from.
+ public Localization(string workingDirectory)
+ {
this.workingDirectory = workingDirectory;
}
- public void SetupWithUiCulture() {
+ ///
+ /// Delegate for the event that occurs when the language is changed.
+ ///
+ /// The language code of the new language.
+ public delegate void LocalizationChangedDelegate(string langCode);
+
+ ///
+ /// Event that occurs when the language is changed.
+ ///
+ public event LocalizationChangedDelegate OnLocalizationChanged;
+
+ ///
+ /// Set up the UI language with the users' local UI culture.
+ ///
+ public void SetupWithUiCulture()
+ {
try
{
var currentUiLang = CultureInfo.CurrentUICulture;
Log.Information("Trying to set up Loc for culture {0}", currentUiLang.TwoLetterISOLanguageName);
- if (ApplicableLangCodes.Any(x => currentUiLang.TwoLetterISOLanguageName == x)) {
- SetupWithLangCode(currentUiLang.TwoLetterISOLanguageName);
- } else {
- SetupWithFallbacks();
+ if (ApplicableLangCodes.Any(x => currentUiLang.TwoLetterISOLanguageName == x))
+ {
+ this.SetupWithLangCode(currentUiLang.TwoLetterISOLanguageName);
+ }
+ else
+ {
+ this.SetupWithFallbacks();
}
}
catch (Exception ex)
{
Log.Error(ex, "Could not get language information. Setting up fallbacks.");
- SetupWithFallbacks();
+ this.SetupWithFallbacks();
}
}
- public void SetupWithFallbacks() {
- OnLocalizationChanged?.Invoke(FallbackLangCode);
+ ///
+ /// Set up the UI language with "fallbacks"(original English text).
+ ///
+ public void SetupWithFallbacks()
+ {
+ this.OnLocalizationChanged?.Invoke(FallbackLangCode);
Loc.SetupWithFallbacks();
}
- public void SetupWithLangCode(string langCode) {
- if (langCode.ToLower() == FallbackLangCode) {
- SetupWithFallbacks();
+ ///
+ /// Set up the UI language with the provided language code.
+ ///
+ /// The language code to set up the UI language with.
+ public void SetupWithLangCode(string langCode)
+ {
+ if (langCode.ToLower() == FallbackLangCode)
+ {
+ this.SetupWithFallbacks();
return;
}
-
- OnLocalizationChanged?.Invoke(langCode);
+
+ this.OnLocalizationChanged?.Invoke(langCode);
Loc.Setup(File.ReadAllText(Path.Combine(this.workingDirectory, "UIRes", "loc", "dalamud", $"dalamud_{langCode}.json")));
}
}