From 40ab42605270a2e3972746a710ad739249d7b214 Mon Sep 17 00:00:00 2001 From: Genteure Date: Sun, 3 Jan 2021 13:21:36 +0800 Subject: [PATCH] prepare translation works --- .../BililiveRecorder.WPF.csproj | 15 +++ .../Controls/TaskbarIconControl.xaml | 2 +- .../Controls/TaskbarIconControl.xaml.cs | 9 +- .../Controls/WorkDirectorySelectorDialog.xaml | 14 ++ BililiveRecorder.WPF/NewMainWindow.xaml | 23 +++- BililiveRecorder.WPF/NewMainWindow.xaml.cs | 57 ++++---- BililiveRecorder.WPF/Pages/RoomListPage.xaml | 11 ++ BililiveRecorder.WPF/Pages/RootPage.xaml.cs | 7 +- .../Properties/Strings.Designer.cs | 72 ++++++++++ .../Properties/Strings.en.resx | 123 ++++++++++++++++++ .../Properties/Strings.ja.resx | 123 ++++++++++++++++++ BililiveRecorder.WPF/Properties/Strings.resx | 104 +++++++++++++++ .../Properties/Strings.zh-Hant.resx | 123 ++++++++++++++++++ .../Resources/IconResources.xaml | 3 + BililiveRecorder.sln | 1 + 15 files changed, 652 insertions(+), 35 deletions(-) create mode 100644 BililiveRecorder.WPF/Properties/Strings.Designer.cs create mode 100644 BililiveRecorder.WPF/Properties/Strings.en.resx create mode 100644 BililiveRecorder.WPF/Properties/Strings.ja.resx create mode 100644 BililiveRecorder.WPF/Properties/Strings.resx create mode 100644 BililiveRecorder.WPF/Properties/Strings.zh-Hant.resx diff --git a/BililiveRecorder.WPF/BililiveRecorder.WPF.csproj b/BililiveRecorder.WPF/BililiveRecorder.WPF.csproj index 43fb0d3..89597a3 100644 --- a/BililiveRecorder.WPF/BililiveRecorder.WPF.csproj +++ b/BililiveRecorder.WPF/BililiveRecorder.WPF.csproj @@ -129,6 +129,11 @@ + + True + True + Strings.resx + Designer MSBuild:Compile @@ -232,6 +237,13 @@ ResXFileCodeGenerator Resources.Designer.cs + + + + PublicResXFileCodeGenerator + Strings.Designer.cs + + @@ -295,6 +307,9 @@ 1.1.1 + + 3.8.0 + diff --git a/BililiveRecorder.WPF/Controls/TaskbarIconControl.xaml b/BililiveRecorder.WPF/Controls/TaskbarIconControl.xaml index 63fdd04..6f18435 100644 --- a/BililiveRecorder.WPF/Controls/TaskbarIconControl.xaml +++ b/BililiveRecorder.WPF/Controls/TaskbarIconControl.xaml @@ -9,7 +9,7 @@ xmlns:local="clr-namespace:BililiveRecorder.WPF.Controls" mc:Ignorable="d"> diff --git a/BililiveRecorder.WPF/Controls/TaskbarIconControl.xaml.cs b/BililiveRecorder.WPF/Controls/TaskbarIconControl.xaml.cs index 83b7b5f..0b0eb4b 100644 --- a/BililiveRecorder.WPF/Controls/TaskbarIconControl.xaml.cs +++ b/BililiveRecorder.WPF/Controls/TaskbarIconControl.xaml.cs @@ -1,6 +1,6 @@ +using System; using System.Windows; using System.Windows.Controls; -using Hardcodet.Wpf.TaskbarNotification; namespace BililiveRecorder.WPF.Controls { @@ -11,14 +11,17 @@ namespace BililiveRecorder.WPF.Controls { public TaskbarIconControl() { - InitializeComponent(); + this.InitializeComponent(); + + using var iconStream = Application.GetResourceStream(new Uri("pack://application:,,,/BililiveRecorder.WPF;component/ico.ico")).Stream; + this.TaskbarIcon.Icon = new System.Drawing.Icon(iconStream); // AddHandler(NewMainWindow.ShowBalloonTipEvent, (RoutedEventHandler)UserControl_ShowBalloonTip); if (Application.Current.MainWindow is NewMainWindow nmw) { nmw.ShowBalloonTipCallback = (title, msg, sym) => { - TaskbarIcon.ShowBalloonTip(title, msg, sym); + this.TaskbarIcon.ShowBalloonTip(title, msg, sym); }; } } diff --git a/BililiveRecorder.WPF/Controls/WorkDirectorySelectorDialog.xaml b/BililiveRecorder.WPF/Controls/WorkDirectorySelectorDialog.xaml index 17c11db..af74e04 100644 --- a/BililiveRecorder.WPF/Controls/WorkDirectorySelectorDialog.xaml +++ b/BililiveRecorder.WPF/Controls/WorkDirectorySelectorDialog.xaml @@ -5,6 +5,7 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:ui="http://schemas.modernwpf.com/2019" + xmlns:l="https://github.com/XAMLMarkupExtensions/WPFLocalizationExtension" xmlns:local="clr-namespace:BililiveRecorder.WPF.Controls" mc:Ignorable="d" d:DataContext="{d:DesignInstance Type=local:WorkDirectorySelectorDialog}" @@ -16,9 +17,21 @@ + + + + + + + + + + + + @@ -28,5 +41,6 @@ + diff --git a/BililiveRecorder.WPF/NewMainWindow.xaml b/BililiveRecorder.WPF/NewMainWindow.xaml index 4cf6c6a..64b5b40 100644 --- a/BililiveRecorder.WPF/NewMainWindow.xaml +++ b/BililiveRecorder.WPF/NewMainWindow.xaml @@ -4,22 +4,31 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:ui="http://schemas.modernwpf.com/2019" + xmlns:l="https://github.com/XAMLMarkupExtensions/WPFLocalizationExtension" + l:LocalizeDictionary.DesignCulture="" + l:ResxLocalizationProvider.DefaultAssembly="BililiveRecorder.WPF" + l:ResxLocalizationProvider.DefaultDictionary="Strings" xmlns:local="clr-namespace:BililiveRecorder.WPF" xmlns:pages="clr-namespace:BililiveRecorder.WPF.Pages" mc:Ignorable="d" - WindowStartupLocation="CenterScreen" Background="{DynamicResource SystemControlPageBackgroundAltHighBrush}" Foreground="{DynamicResource SystemControlPageTextBaseHighBrush}" ui:ThemeManager.IsThemeAware="True" + ui:ThemeManager.RequestedTheme="Default" ui:WindowHelper.UseModernWindowStyle="True" ui:TitleBar.IsBackEnabled="False" ui:TitleBar.IsBackButtonVisible="False" ui:TitleBar.IsIconVisible="True" - Width="960" Height="650" - MinHeight="400" MinWidth="340" - Closing="Window_Closing" - StateChanged="Window_StateChanged" - ui:ThemeManager.RequestedTheme="Default" - Title="录播姬"> + Width="960" Height="650" MinHeight="400" MinWidth="340" + WindowStartupLocation="CenterScreen" + FontFamily="Microsoft YaHei" + Closing="Window_Closing" StateChanged="Window_StateChanged" + > + + + + + + diff --git a/BililiveRecorder.WPF/NewMainWindow.xaml.cs b/BililiveRecorder.WPF/NewMainWindow.xaml.cs index 6a1a164..0c65fa3 100644 --- a/BililiveRecorder.WPF/NewMainWindow.xaml.cs +++ b/BililiveRecorder.WPF/NewMainWindow.xaml.cs @@ -4,6 +4,7 @@ using System.Windows; using BililiveRecorder.WPF.Controls; using Hardcodet.Wpf.TaskbarNotification; using ModernWpf.Controls; +using WPFLocalizeExtension.Engine; namespace BililiveRecorder.WPF { @@ -12,16 +13,28 @@ namespace BililiveRecorder.WPF /// public partial class NewMainWindow : Window { + public string SoftwareVersion { get; } + public NewMainWindow() { - InitializeComponent(); + this.SoftwareVersion = BuildInfo.Version + " " + BuildInfo.HeadShaShort; + + LocalizeDictionary.Instance.OutputMissingKeys = true; + LocalizeDictionary.Instance.MissingKeyEvent += this.Instance_MissingKeyEvent; - Title = "B站录播姬 " + BuildInfo.Version + " " + BuildInfo.HeadShaShort; + this.InitializeComponent(); - SingleInstance.NotificationReceived += SingleInstance_NotificationReceived; + // this.Title = "B站录播姬 " + BuildInfo.Version + " " + BuildInfo.HeadShaShort; + + SingleInstance.NotificationReceived += this.SingleInstance_NotificationReceived; } - private void SingleInstance_NotificationReceived(object sender, EventArgs e) => SuperActivateAction(); + private void Instance_MissingKeyEvent(object sender, MissingKeyEventArgs e) + { + MessageBox.Show("Missing: " + e.Key); + } + + private void SingleInstance_NotificationReceived(object sender, EventArgs e) => this.SuperActivateAction(); public event EventHandler NativeBeforeWindowClose; @@ -29,20 +42,20 @@ namespace BililiveRecorder.WPF internal void CloseWithoutConfirmAction() { - CloseConfirmed = true; - Close(); + this.CloseConfirmed = true; + this.Close(); } internal void SuperActivateAction() { try { - Show(); - WindowState = WindowState.Normal; - Topmost = true; - Activate(); - Topmost = false; - Focus(); + this.Show(); + this.WindowState = WindowState.Normal; + this.Topmost = true; + this.Activate(); + this.Topmost = false; + this.Focus(); } catch (Exception) { } @@ -50,10 +63,10 @@ namespace BililiveRecorder.WPF private void Window_StateChanged(object sender, EventArgs e) { - if (WindowState == WindowState.Minimized) + if (this.WindowState == WindowState.Minimized) { - Hide(); - ShowBalloonTipCallback?.Invoke("B站录播姬", "录播姬已最小化到托盘,左键单击图标恢复界面", BalloonIcon.Info); + this.Hide(); + this.ShowBalloonTipCallback?.Invoke("B站录播姬", "录播姬已最小化到托盘,左键单击图标恢复界面", BalloonIcon.Info); } } @@ -67,28 +80,28 @@ namespace BililiveRecorder.WPF private async void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) { - if (PromptCloseConfirm && !CloseConfirmed) + if (this.PromptCloseConfirm && !this.CloseConfirmed) { e.Cancel = true; - if (CloseWindowSemaphoreSlim.Wait(0)) + if (this.CloseWindowSemaphoreSlim.Wait(0)) { try { if (await new CloseWindowConfirmDialog().ShowAsync() == ContentDialogResult.Primary) { - CloseConfirmed = true; - CloseWindowSemaphoreSlim.Release(); - Close(); + this.CloseConfirmed = true; + this.CloseWindowSemaphoreSlim.Release(); + this.Close(); return; } } catch (Exception) { } - CloseWindowSemaphoreSlim.Release(); + this.CloseWindowSemaphoreSlim.Release(); } } else { - SingleInstance.NotificationReceived -= SingleInstance_NotificationReceived; + SingleInstance.NotificationReceived -= this.SingleInstance_NotificationReceived; NativeBeforeWindowClose?.Invoke(this, EventArgs.Empty); return; } diff --git a/BililiveRecorder.WPF/Pages/RoomListPage.xaml b/BililiveRecorder.WPF/Pages/RoomListPage.xaml index 9d61b1b..d0fb7f9 100644 --- a/BililiveRecorder.WPF/Pages/RoomListPage.xaml +++ b/BililiveRecorder.WPF/Pages/RoomListPage.xaml @@ -5,6 +5,7 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:ui="http://schemas.modernwpf.com/2019" + xmlns:l="https://github.com/XAMLMarkupExtensions/WPFLocalizationExtension" xmlns:local="clr-namespace:BililiveRecorder.WPF.Pages" xmlns:mock="clr-namespace:BililiveRecorder.WPF.MockData" xmlns:controls="clr-namespace:BililiveRecorder.WPF.Controls" @@ -45,6 +46,16 @@ + + + + + + + + + + diff --git a/BililiveRecorder.WPF/Pages/RootPage.xaml.cs b/BililiveRecorder.WPF/Pages/RootPage.xaml.cs index a4fa2d8..b0c6009 100644 --- a/BililiveRecorder.WPF/Pages/RootPage.xaml.cs +++ b/BililiveRecorder.WPF/Pages/RootPage.xaml.cs @@ -59,7 +59,10 @@ namespace BililiveRecorder.WPF.Pages InitializeComponent(); AdvancedSettingsPageItem.Visibility = Visibility.Hidden; - (Application.Current.MainWindow as NewMainWindow).NativeBeforeWindowClose += RootPage_NativeBeforeWindowClose; + var mw = Application.Current.MainWindow as NewMainWindow; + if (mw is not null) + mw.NativeBeforeWindowClose += this.RootPage_NativeBeforeWindowClose; + Loaded += RootPage_Loaded; } @@ -124,7 +127,7 @@ namespace BililiveRecorder.WPF.Pages Error = error, Path = lastdir }; - + if (await dialog.ShowAsync() != ContentDialogResult.Primary) { (Application.Current.MainWindow as NewMainWindow).CloseWithoutConfirmAction(); diff --git a/BililiveRecorder.WPF/Properties/Strings.Designer.cs b/BililiveRecorder.WPF/Properties/Strings.Designer.cs new file mode 100644 index 0000000..fe5e758 --- /dev/null +++ b/BililiveRecorder.WPF/Properties/Strings.Designer.cs @@ -0,0 +1,72 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace BililiveRecorder.WPF.Properties { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + public class Strings { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Strings() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + public static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("BililiveRecorder.WPF.Properties.Strings", typeof(Strings).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + public static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Looks up a localized string similar to B站录播姬 {0}. + /// + public static string Window_Title { + get { + return ResourceManager.GetString("Window_Title", resourceCulture); + } + } + } +} diff --git a/BililiveRecorder.WPF/Properties/Strings.en.resx b/BililiveRecorder.WPF/Properties/Strings.en.resx new file mode 100644 index 0000000..d7c4a23 --- /dev/null +++ b/BililiveRecorder.WPF/Properties/Strings.en.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + BililiveRecorder {0} + + \ No newline at end of file diff --git a/BililiveRecorder.WPF/Properties/Strings.ja.resx b/BililiveRecorder.WPF/Properties/Strings.ja.resx new file mode 100644 index 0000000..1a3520b --- /dev/null +++ b/BililiveRecorder.WPF/Properties/Strings.ja.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + ビリビリ録画機 {0} + + \ No newline at end of file diff --git a/BililiveRecorder.WPF/Properties/Strings.resx b/BililiveRecorder.WPF/Properties/Strings.resx new file mode 100644 index 0000000..bbdccd3 --- /dev/null +++ b/BililiveRecorder.WPF/Properties/Strings.resx @@ -0,0 +1,104 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 1.3 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + B站录播姬 {0} + + + \ No newline at end of file diff --git a/BililiveRecorder.WPF/Properties/Strings.zh-Hant.resx b/BililiveRecorder.WPF/Properties/Strings.zh-Hant.resx new file mode 100644 index 0000000..36314ba --- /dev/null +++ b/BililiveRecorder.WPF/Properties/Strings.zh-Hant.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + B站錄播姬 {0} + + \ No newline at end of file diff --git a/BililiveRecorder.WPF/Resources/IconResources.xaml b/BililiveRecorder.WPF/Resources/IconResources.xaml index 9d06606..38000cc 100644 --- a/BililiveRecorder.WPF/Resources/IconResources.xaml +++ b/BililiveRecorder.WPF/Resources/IconResources.xaml @@ -64,6 +64,9 @@ + diff --git a/BililiveRecorder.sln b/BililiveRecorder.sln index dd46da1..23abb1d 100644 --- a/BililiveRecorder.sln +++ b/BililiveRecorder.sln @@ -46,6 +46,7 @@ Global HideSolutionNode = FALSE EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution + RESX_NeutralResourcesLanguage = zh-Hans SolutionGuid = {F3CB8B14-077A-458F-BD8E-1747ED0F5170} EndGlobalSection EndGlobal