Skip to content

Commit

Permalink
Fix system language detection
Browse files Browse the repository at this point in the history
  • Loading branch information
JungleDruid committed Aug 30, 2023
1 parent b0f1a4e commit b43e663
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
1 change: 1 addition & 0 deletions BG3LocalizationMerger.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<PlatformTarget>x64</PlatformTarget>
<NeutralLanguage>en</NeutralLanguage>
<Version>$(VersionPrefix)1.0.1</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
31 changes: 27 additions & 4 deletions MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,46 @@ public MainWindow()
ReferencePackTextBox.Text = props.ReferencePackPath;
ExportPathTextBox.Text = props.ExportPath;

InitCulture();
}

private void InitCulture()
{
LanguageComboBox.ItemsSource = TranslationSource.GetAllCultures();

string defaultCultureName = Properties.Settings.Default.CultureName;
var defaultCulture = string.IsNullOrEmpty(defaultCultureName)
? CultureInfo.CurrentCulture
? CultureInfo.CurrentUICulture
: new CultureInfo(defaultCultureName);

foreach (CultureInfo culture in LanguageComboBox.ItemsSource)
{
if (culture.Equals(defaultCulture))
{
LanguageComboBox.SelectedItem = culture;
break;
return;
}
}
if (LanguageComboBox.SelectedIndex < 0)
LanguageComboBox.SelectedIndex = 0;

foreach (CultureInfo culture in LanguageComboBox.ItemsSource)
{
if (culture.Equals(defaultCulture.Parent))
{
LanguageComboBox.SelectedItem = culture;
return;
}
}

foreach (CultureInfo culture in LanguageComboBox.ItemsSource)
{
if (culture.TwoLetterISOLanguageName == defaultCulture.TwoLetterISOLanguageName)
{
LanguageComboBox.SelectedItem = culture;
return;
}
}

LanguageComboBox.SelectedIndex = 0;
}

public static void Log(string text)
Expand Down

0 comments on commit b43e663

Please sign in to comment.