mirror of
https://github.com/knah/VRCMelonAssistant.git
synced 2024-06-15 00:44:36 +12:00
Language select and refactor
This commit is contained in:
parent
3fe99bb5e2
commit
ff327ecffc
|
@ -36,7 +36,7 @@ namespace ModAssistant
|
||||||
System.Net.ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls12;
|
System.Net.ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls12;
|
||||||
|
|
||||||
// Load localisation languages
|
// Load localisation languages
|
||||||
Utils.LoadLanguage(CultureInfo.CurrentCulture.Name);
|
Languages.LoadLanguage(CultureInfo.CurrentCulture.Name);
|
||||||
|
|
||||||
// Uncomment the next line to debug localisation
|
// Uncomment the next line to debug localisation
|
||||||
// LoadLanguage("en-DEBUG");
|
// LoadLanguage("en-DEBUG");
|
||||||
|
@ -142,7 +142,7 @@ namespace ModAssistant
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Utils.LoadLanguage(args[1]);
|
Languages.LoadLanguage(args[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
args = Shift(args, 2);
|
args = Shift(args, 2);
|
||||||
|
|
58
ModAssistant/Classes/Languages.cs
Normal file
58
ModAssistant/Classes/Languages.cs
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Globalization;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows;
|
||||||
|
using ModAssistant.Pages;
|
||||||
|
|
||||||
|
namespace ModAssistant
|
||||||
|
{
|
||||||
|
class Languages
|
||||||
|
{
|
||||||
|
public static string LoadedLanguage { get; private set; }
|
||||||
|
public static List<CultureInfo> LoadedLanguages { get => availableCultures.ToList(); }
|
||||||
|
|
||||||
|
private static string[] availableLanguageCodes = { "de", "en", "fr", "it", "ko", "nl", "ru", "zh" };
|
||||||
|
|
||||||
|
private static IEnumerable<CultureInfo> availableCultures;
|
||||||
|
public static void LoadLanguages()
|
||||||
|
{
|
||||||
|
var allCultures = CultureInfo.GetCultures(CultureTypes.AllCultures);
|
||||||
|
|
||||||
|
// Get CultureInfo for any of the available translations
|
||||||
|
availableCultures = allCultures.Where(cultureInfo => availableLanguageCodes.Any(code => code.CompareTo(cultureInfo.Name) == 0));
|
||||||
|
|
||||||
|
if (Options.Instance != null && Options.Instance.LanguageSelectComboBox != null)
|
||||||
|
{
|
||||||
|
Options.Instance.LanguageSelectComboBox.ItemsSource = availableCultures.Select(cultureInfo => cultureInfo.EnglishName).ToList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -439,29 +439,5 @@ namespace ModAssistant
|
||||||
ShowMessageBoxDelegate caller = new ShowMessageBoxDelegate(ShowMessageBox);
|
ShowMessageBoxDelegate caller = new ShowMessageBoxDelegate(ShowMessageBox);
|
||||||
caller.BeginInvoke(Message, null, null, null);
|
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,6 +65,9 @@ namespace ModAssistant
|
||||||
Themes.LoadThemes();
|
Themes.LoadThemes();
|
||||||
Themes.FirstLoad(Properties.Settings.Default.SelectedTheme);
|
Themes.FirstLoad(Properties.Settings.Default.SelectedTheme);
|
||||||
|
|
||||||
|
// Load languages into combobox
|
||||||
|
Languages.LoadLanguages();
|
||||||
|
|
||||||
Task.Run(() => LoadVersionsAsync());
|
Task.Run(() => LoadVersionsAsync());
|
||||||
|
|
||||||
if (!Properties.Settings.Default.Agreed || string.IsNullOrEmpty(Properties.Settings.Default.LastTab))
|
if (!Properties.Settings.Default.Agreed || string.IsNullOrEmpty(Properties.Settings.Default.LastTab))
|
||||||
|
|
|
@ -72,6 +72,7 @@
|
||||||
<Compile Include="Classes\External Interfaces\Utils.cs" />
|
<Compile Include="Classes\External Interfaces\Utils.cs" />
|
||||||
<Compile Include="Classes\Http.cs" />
|
<Compile Include="Classes\Http.cs" />
|
||||||
<Compile Include="Classes\HyperlinkExtensions.cs" />
|
<Compile Include="Classes\HyperlinkExtensions.cs" />
|
||||||
|
<Compile Include="Classes\Languages.cs" />
|
||||||
<Compile Include="Classes\Promotions.cs" />
|
<Compile Include="Classes\Promotions.cs" />
|
||||||
<Compile Include="Classes\Diagnostics.cs" />
|
<Compile Include="Classes\Diagnostics.cs" />
|
||||||
<Compile Include="Classes\Themes.cs" />
|
<Compile Include="Classes\Themes.cs" />
|
||||||
|
|
|
@ -337,12 +337,14 @@ namespace ModAssistant.Pages
|
||||||
{
|
{
|
||||||
// Apply default language
|
// Apply default language
|
||||||
Console.WriteLine("Applying default language");
|
Console.WriteLine("Applying default language");
|
||||||
|
Languages.LoadLanguage("en");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Set new language
|
// Get the matching language from the LoadedLanguages array, then try and use it
|
||||||
Console.WriteLine("Setting language to:" + (sender as ComboBox).SelectedItem.ToString());
|
var languageName = (sender as ComboBox).SelectedItem.ToString();
|
||||||
//LoadLanguage((sender as ComboBox).SelectedItem.ToString())
|
var selectedLanguage = Languages.LoadedLanguages.Find(language => language.EnglishName.CompareTo(languageName) == 0);
|
||||||
|
Languages.LoadLanguage(selectedLanguage.Name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue