Skip to content

Commit

Permalink
Merge branch 'main' into improve-locations
Browse files Browse the repository at this point in the history
  • Loading branch information
Razzmatazzz authored Aug 17, 2023
2 parents 065f957 + 9aa1c1e commit 2ee088e
Show file tree
Hide file tree
Showing 14 changed files with 610 additions and 195 deletions.
3 changes: 3 additions & 0 deletions RemnantSaveGuardian/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@
<setting name="WindowHeight" serializeAs="String">
<value>650</value>
</setting>
<setting name="Language" serializeAs="String">
<value />
</setting>
</RemnantSaveGuardian.Properties.Settings>
</userSettings>
</configuration>
26 changes: 24 additions & 2 deletions RemnantSaveGuardian/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using RemnantSaveGuardian.Models;
using RemnantSaveGuardian.Properties;
using RemnantSaveGuardian.Services;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Resources;
using System.Threading;
using System.Windows;
using System.Windows.Markup;
Expand Down Expand Up @@ -81,15 +86,32 @@ public static T GetService<T>()
private async void OnStartup(object sender, StartupEventArgs e)
{
var culture = CultureInfo.CurrentCulture;
//var culture = new CultureInfo("zh-TW");
var cultures = EnumerateSupportedCultures();
Current.Properties["langs"] = cultures;
if(Settings.Default.Language != "")
{
culture = cultures.First(e => e.Name == Settings.Default.Language);
}

Thread.CurrentThread.CurrentCulture = culture;
WPFLocalizeExtension.Engine.LocalizeDictionary.Instance.Culture = culture;

FrameworkElement.LanguageProperty.OverrideMetadata(
typeof(FrameworkElement),
new FrameworkPropertyMetadata(XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag)));
new FrameworkPropertyMetadata(XmlLanguage.GetLanguage(culture.IetfLanguageTag)));
await _host.StartAsync();
}

private CultureInfo[] EnumerateSupportedCultures()
{
CultureInfo[] culture = CultureInfo.GetCultures(CultureTypes.AllCultures);

string exeLocation = Path.GetDirectoryName(Uri.UnescapeDataString(new UriBuilder(Assembly.GetExecutingAssembly().CodeBase).Path));

var c = culture.Where(cultureInfo => Directory.Exists(Path.Combine(exeLocation, cultureInfo.Name)) && cultureInfo.Name != "").ToArray();
return c;
}

/// <summary>
/// Occurs when the application is closing.
/// </summary>
Expand Down
15 changes: 11 additions & 4 deletions RemnantSaveGuardian/LocalizationProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,18 @@ public static string GameT(string key)
{
return T(key, new LocalizationOptions { { "namespace", "GameStrings" } });
}

public static List<string> AvailableLocalizations()
public static bool Has(string key, LocalizationOptions options)
{
var val = GetLocalizedValue<string>(key, options);
if (val == null || val == "")
{
return false;
}
return true;
}
public static bool GameTHas(string key)
{
var cultures = WPFLocalizeExtension.Engine.LocalizeDictionary.Instance.MergedAvailableCultures;
return cultures.Select(c => c.Name).ToList();
return Has(key, new LocalizationOptions { { "namespace", "GameStrings" } });
}
}

Expand Down
14 changes: 13 additions & 1 deletion RemnantSaveGuardian/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions RemnantSaveGuardian/Properties/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -110,5 +110,8 @@
<Setting Name="WindowHeight" Type="System.Int32" Scope="User">
<Value Profile="(Default)">650</Value>
</Setting>
<Setting Name="Language" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
</Settings>
</SettingsFile>
8 changes: 7 additions & 1 deletion RemnantSaveGuardian/Views/Pages/BackupsPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public BackupsPage(ViewModels.BackupsViewModel viewModel)
SaveWatcher.SaveUpdated += SaveWatcher_SaveUpdated;

btnStartGame.IsEnabled = !IsRemnantRunning();

Properties.Settings.Default.PropertyChanged += Default_PropertyChanged;
loadBackups();
} catch (Exception ex) {
Logger.Error($"Error loading backups page: {ex}");
Expand Down Expand Up @@ -771,6 +771,12 @@ private void refreshBackups()
dataBackups.ItemsSource = listBackups;
dataBackups.Items.SortDescriptions.Add(sorting);
}

private void Default_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
{
if(e.PropertyName == "Language")
dataBackups.Items.Refresh();
}
}

public class BackupSaveViewedEventArgs : EventArgs
Expand Down
8 changes: 7 additions & 1 deletion RemnantSaveGuardian/Views/Pages/SettingsPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,17 @@
</ComboBox>
<TextBlock Name="lblMissingItemColor" Text="{lex:Loc}" ToolTip="{lex:Loc}" VerticalAlignment="Center" Margin="20,0,0,0"/>
</WrapPanel>
<WrapPanel Margin="0,2,0,0">
<ComboBox Name="cmbSwitchLanguage" VerticalAlignment="Center" Width="Auto"/>
<TextBlock Name="lblSwitchLanguage" Text="{lex:Loc}" ToolTip="{lex:Loc}" VerticalAlignment="Center" Margin="20,0,0,0"/>
</WrapPanel>
<WrapPanel Margin="0,2,0,0">
<ui:ToggleSwitch Name="chkAutoCheckUpdate" Content="{lex:Loc}" IsChecked="{Binding AutoCheckUpdate}" VerticalAlignment="Center"/>
<Button Name="btnCheckUpdate" Content="{lex:Loc}" VerticalAlignment="Top" Click="BtnCheckUpdate_Click" Margin="4,0,0,0"/>
</WrapPanel>
<ui:ToggleSwitch Name="chkCreateLogFile" IsChecked="{Binding CreateLogFile}" Content="{lex:Loc}" Margin="0,2,0,0"/>
<WrapPanel Margin="0,2,0,0">
<ui:ToggleSwitch Name="chkCreateLogFile" IsChecked="{Binding CreateLogFile}" Content="{lex:Loc}" />
</WrapPanel>
<TextBlock Margin="0,12,0,0" Text="{lex:Loc Theme}" />
<RadioButton
Name="radThemeLight"
Expand Down
38 changes: 37 additions & 1 deletion RemnantSaveGuardian/Views/Pages/SettingsPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
using Wpf.Ui.Common.Interfaces;
Expand All @@ -20,6 +21,8 @@ public ViewModels.SettingsViewModel ViewModel
get;
}

private CultureInfo[] AvailableCultures = new CultureInfo[] { };

public SettingsPage(ViewModels.SettingsViewModel viewModel)
{
ViewModel = viewModel;
Expand Down Expand Up @@ -47,6 +50,24 @@ public SettingsPage(ViewModels.SettingsViewModel viewModel)
}
}

var langs = Application.Current.Properties["langs"] as CultureInfo[];

cmbSwitchLanguage.ItemsSource = langs.Select(e => e.NativeName);
if (Properties.Settings.Default.Language != "")
{
cmbSwitchLanguage.SelectedItem = langs.First(e => Properties.Settings.Default.Language == e.Name).NativeName;
}
else
{
var culture = Thread.CurrentThread.CurrentCulture;

if (culture.Parent != null || culture.Name != "pt-BR")
cmbSwitchLanguage.SelectedItem = culture.Parent.NativeName;
else
cmbSwitchLanguage.SelectedItem = culture.NativeName;
}
cmbSwitchLanguage.SelectionChanged += cmbSwitchLanguage_SelectionChanged;

radThemeLight.IsChecked = Properties.Settings.Default.Theme == "Light";

radThemeDark.IsChecked = Properties.Settings.Default.Theme != "Light";
Expand Down Expand Up @@ -283,5 +304,20 @@ private void cmbStartPage_SelectionChanged(object sender, SelectionChangedEventA
}
Properties.Settings.Default.StartPage = startPage;
}

private void cmbSwitchLanguage_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (cmbSwitchLanguage.SelectedIndex > -1)
{
var langs = Application.Current.Properties["langs"] as CultureInfo[];
var culture = langs[cmbSwitchLanguage.SelectedIndex];

Thread.CurrentThread.CurrentCulture = culture;
WPFLocalizeExtension.Engine.LocalizeDictionary.Instance.Culture = culture;
Application.Current.MainWindow.Language = System.Windows.Markup.XmlLanguage.GetLanguage(culture.IetfLanguageTag);
Properties.Settings.Default.Language = langs[cmbSwitchLanguage.SelectedIndex].Name;
Logger.Success(Loc.T("Language_change_notice_{chosenLanguage}", new() { { "chosenLanguage", culture.DisplayName } }));
}
}
}
}
11 changes: 10 additions & 1 deletion RemnantSaveGuardian/Views/Pages/WorldAnalyzerPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,15 @@ private void Default_PropertyChanged(object? sender, System.ComponentModel.Prope
CharacterControl_SelectionChanged(null, null);
});
}

if(e.PropertyName == "Language")
{
Dispatcher.Invoke(() =>
{
reloadEventGrids();
CharacterControl_SelectionChanged(null, null);
});
}
}

private void Data_AutoGeneratingColumn(object? sender, DataGridAutoGeneratingColumnEventArgs e)
Expand Down Expand Up @@ -256,7 +265,7 @@ private void CharacterControl_SelectionChanged(object sender, SelectionChangedEv
item.Expanded += GameType_CollapsedExpanded;
itemNode[(int)rItem.ItemMode].Add(item) ;
}
itemChild[idx].Add(new TreeListClass() { Name = rItem.Name, Notes = $"{Loc.GameT(rItem.ItemNotes)}", Tag = rItem });
itemChild[idx].Add(new TreeListClass() { Name = rItem.Name, Notes = Loc.GameTHas($"{rItem.RawName}_Notes") ? Loc.GameT($"{rItem.RawName}_Notes") : rItem.ItemNotes, Tag = rItem });
}

treeMissingItems.ItemsSource = null;
Expand Down
Loading

0 comments on commit 2ee088e

Please sign in to comment.