Skip to content

Commit

Permalink
Fix an error in translation support logic
Browse files Browse the repository at this point in the history
TranslationDataProvider will now properly load translation data from the local cache.
  • Loading branch information
Yuubari committed Feb 8, 2016
1 parent 7318d47 commit 994ff92
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
6 changes: 4 additions & 2 deletions source/Grabacr07.KanColleWrapper/KanColleClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
}

Expand Down
6 changes: 4 additions & 2 deletions source/Grabacr07.KanColleWrapper/TranslationDataProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,20 @@ private static string SerialisationPath(TranslationProviderType type)
/// Changes culture and loads or re-loads translation files.
/// </summary>
/// <param name="culture">The culture to use for translations.</param>
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();
}
Expand Down
8 changes: 8 additions & 0 deletions source/Grabacr07.KanColleWrapper/Updater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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
}
Expand Down

0 comments on commit 994ff92

Please sign in to comment.