From 994ff928bffa84f86a0376fd09c9cd0db69d69da Mon Sep 17 00:00:00 2001 From: Yuubari Date: Mon, 8 Feb 2016 22:54:46 +0300 Subject: [PATCH] Fix an error in translation support logic TranslationDataProvider will now properly load translation data from the local cache. --- source/Grabacr07.KanColleWrapper/KanColleClient.cs | 6 ++++-- .../Models/Updater/kcvapi_version.cs | 1 + .../Grabacr07.KanColleWrapper/TranslationDataProvider.cs | 6 ++++-- source/Grabacr07.KanColleWrapper/Updater.cs | 8 ++++++++ 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/source/Grabacr07.KanColleWrapper/KanColleClient.cs b/source/Grabacr07.KanColleWrapper/KanColleClient.cs index 95f7eb4b5..b9b7ec4b2 100644 --- a/source/Grabacr07.KanColleWrapper/KanColleClient.cs +++ b/source/Grabacr07.KanColleWrapper/KanColleClient.cs @@ -156,8 +156,10 @@ public void Initialieze() public void DeferredInit(object sender, IKanColleClientSettings value) { - this.Translations = new Translations(value.Culture); - this.Updater = new Updater(ApiUrl, value.Culture); + TranslationDataProvider.ChangeCulture(value.Culture, true); + this.Translations = new Translations(TranslationDataProvider.CurrentCulture); + this.Updater = new Updater(ApiUrl, TranslationDataProvider.CurrentCulture); + TranslationDataProvider.ChangeCulture(value.Culture); } } } diff --git a/source/Grabacr07.KanColleWrapper/Models/Updater/kcvapi_version.cs b/source/Grabacr07.KanColleWrapper/Models/Updater/kcvapi_version.cs index c70cc8dee..74af923a9 100644 --- a/source/Grabacr07.KanColleWrapper/Models/Updater/kcvapi_version.cs +++ b/source/Grabacr07.KanColleWrapper/Models/Updater/kcvapi_version.cs @@ -5,6 +5,7 @@ public class kcvapi_version { public string api_version { get; set; } public string api_url { get; set; } + public string selected_culture { get; set; } public kcvapi_version_component[] components { get; set; } } diff --git a/source/Grabacr07.KanColleWrapper/TranslationDataProvider.cs b/source/Grabacr07.KanColleWrapper/TranslationDataProvider.cs index 5e4b51527..a9b35eaef 100644 --- a/source/Grabacr07.KanColleWrapper/TranslationDataProvider.cs +++ b/source/Grabacr07.KanColleWrapper/TranslationDataProvider.cs @@ -58,18 +58,20 @@ private static string SerialisationPath(TranslationProviderType type) /// Changes culture and loads or re-loads translation files. /// /// The culture to use for translations. - public static void ChangeCulture(string culture) + public static void ChangeCulture(string culture, bool firstRun = false) { if (culture == null) culture = CultureInfo.CurrentCulture.Name; culture = (culture.StartsWith("en")) ? "en" : culture; culture = (culture.StartsWith("ja")) ? "ja" : culture; - if (culture == CurrentCulture) + if (culture == CurrentCulture && !firstRun) return; Debug.WriteLine("TranslationDataProvider: got <" + culture + "> in a culture change request."); CurrentCulture = culture; LoadLocalTranslations(); + if (firstRun) return; + KanColleClient.Current.Translations.ChangeCulture(); KanColleClient.Current.Updater.ChangeCulture(); } diff --git a/source/Grabacr07.KanColleWrapper/Updater.cs b/source/Grabacr07.KanColleWrapper/Updater.cs index 7710f1981..25ec175b9 100644 --- a/source/Grabacr07.KanColleWrapper/Updater.cs +++ b/source/Grabacr07.KanColleWrapper/Updater.cs @@ -175,6 +175,11 @@ private bool LoadVersions(string url) kcvapi_version rawResult; if (!this.TryConvertTo(responseBytes, out rawResult)) return false; + bool cultureAvailable = rawResult.selected_culture == CurrentCulture; + + if (!cultureAvailable) + Debug.WriteLine("Updater: server returned a different culture; expected {0}, got {1}.", CurrentCulture, rawResult.selected_culture); + Version apiRemoteVersion; if (!Version.TryParse(rawResult.api_version, out apiRemoteVersion) && (apiRemoteVersion.CompareTo("1.0") >= 0)) @@ -192,6 +197,9 @@ private bool LoadVersions(string url) Debug.WriteLine("Updater: provider {0}: version {1}{2}.", component.type, component.version, string.IsNullOrEmpty(component.url) ? "" : " (" + component.url + ")"); var typeTemp = TranslationDataProvider.StringToTranslationProviderType(component.type); if (typeTemp == null) continue; + // Enforce version = 1 for unsupported cultures + // versions[typeTemp.Value] = (!cultureAvailable && (typeTemp != TranslationProviderType.App)) ? "1" : component.version; + // If not enforced, upon adding a new culture its components' versions must be set to values greater than those for 'en'. versions[typeTemp.Value] = component.version; if (typeTemp == TranslationProviderType.App) downloadUrl = component.url; // TODO: proper implementation of overrides for all resource types }