Move LoadLanguage to Utils

This commit is contained in:
Megalon 2020-05-29 18:30:46 -07:00
parent 83760c6a0a
commit 3fe99bb5e2
2 changed files with 26 additions and 26 deletions

View file

@ -36,7 +36,7 @@ namespace ModAssistant
System.Net.ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls12;
// Load localisation languages
LoadLanguage(CultureInfo.CurrentCulture.Name);
Utils.LoadLanguage(CultureInfo.CurrentCulture.Name);
// Uncomment the next line to debug localisation
// LoadLanguage("en-DEBUG");
@ -142,7 +142,7 @@ namespace ModAssistant
}
else
{
LoadLanguage(args[1]);
Utils.LoadLanguage(args[1]);
}
args = Shift(args, 2);
@ -213,29 +213,5 @@ namespace ModAssistant
e.Handled = true;
Application.Current.Shutdown();
}
private ResourceDictionary LanguagesDict
{
get
{
return Resources.MergedDictionaries[1];
}
}
private void LoadLanguage(string culture)
{
try
{
LanguagesDict.Source = new Uri($"Localisation/{culture}.xaml", UriKind.Relative);
}
catch (IOException)
{
if (culture.Contains("-"))
{
LoadLanguage(culture.Split('-').First());
}
// Can't load language file
}
}
}
}

View file

@ -439,5 +439,29 @@ namespace ModAssistant
ShowMessageBoxDelegate caller = new ShowMessageBoxDelegate(ShowMessageBox);
caller.BeginInvoke(Message, null, null, null);
}
private static ResourceDictionary LanguagesDict
{
get
{
return Application.Current.Resources.MergedDictionaries[1];
}
}
public static void LoadLanguage(string culture)
{
try
{
LanguagesDict.Source = new Uri($"Localisation/{culture}.xaml", UriKind.Relative);
}
catch (IOException)
{
if (culture.Contains("-"))
{
LoadLanguage(culture.Split('-').First());
}
// Can't load language file
}
}
}
}