diff --git a/IdeapadToolkit.sln b/IdeapadToolkit.sln index 67fba56..0d2e4e8 100644 --- a/IdeapadToolkit.sln +++ b/IdeapadToolkit.sln @@ -26,6 +26,7 @@ Global HideSolutionNode = FALSE EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution + RESX_SortFileContentOnSave = True SolutionGuid = {88081EEF-3938-46A8-B49A-9AD2C92E4E1A} EndGlobalSection EndGlobal diff --git a/IdeapadToolkit/App.config b/IdeapadToolkit/App.config new file mode 100644 index 0000000..8b5e25b --- /dev/null +++ b/IdeapadToolkit/App.config @@ -0,0 +1,15 @@ + + + + +
+ + + + + + + + + + \ No newline at end of file diff --git a/IdeapadToolkit/App.xaml.cs b/IdeapadToolkit/App.xaml.cs index 8599291..dc98963 100644 --- a/IdeapadToolkit/App.xaml.cs +++ b/IdeapadToolkit/App.xaml.cs @@ -9,6 +9,8 @@ using Serilog; using System.Windows; using Serilog.Core; +using System.Globalization; +using System.Threading; namespace IdeapadToolkit { @@ -29,10 +31,10 @@ public void ConfigureServices(Container container) .MinimumLevel.ControlledBy(logLevel) .WriteTo.File("log.txt", rollingInterval: RollingInterval.Day, retainedFileCountLimit: 7, levelSwitch: logLevel); var logger = _logger = loggerConfig.CreateLogger(); - + container.RegisterInstance(logger); container.RegisterInstance(logLevel); - + container.RegisterSingleton(); container.RegisterSingleton(); container.RegisterSingleton(); @@ -75,7 +77,7 @@ protected override void OnStartup(StartupEventArgs e) { ShowMainWindow(null, null); } - + var iconview = _container.GetInstance(); iconview.MakeVisible(); iconview.TrayIconClicked += ShowMainWindow; @@ -90,6 +92,19 @@ public void ShowMainWindow(object? sender, EventArgs? e) { if (App.Current.MainWindow == null) { + var culture = Settings.Default.Language; + if (!String.IsNullOrWhiteSpace(culture)) + { + var cultureInfo = CultureInfo.GetCultureInfo(culture); + if (cultureInfo != null) + { + Application.Current.Dispatcher.Invoke(() => + { + Thread.CurrentThread.CurrentUICulture = cultureInfo; + }); + } + } + App.Current.MainWindow = _container.GetInstance(); } App.Current.MainWindow.Show(); diff --git a/IdeapadToolkit/IdeapadToolkit.csproj b/IdeapadToolkit/IdeapadToolkit.csproj index 51dc706..f596814 100644 --- a/IdeapadToolkit/IdeapadToolkit.csproj +++ b/IdeapadToolkit/IdeapadToolkit.csproj @@ -51,10 +51,34 @@ + + + True + True + Strings.resx + + + True + True + Settings.settings + + + + + + PublicResXFileCodeGenerator + Strings.Designer.cs + + + Always + + SettingsSingleFileGenerator + Settings.Designer.cs + diff --git a/IdeapadToolkit/Localization/Strings.Designer.cs b/IdeapadToolkit/Localization/Strings.Designer.cs new file mode 100644 index 0000000..49d55a3 --- /dev/null +++ b/IdeapadToolkit/Localization/Strings.Designer.cs @@ -0,0 +1,189 @@ +//------------------------------------------------------------------------------ +// +// 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 IdeapadToolkit.Localization { + 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", "17.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("IdeapadToolkit.Localization.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 Always on USB. + /// + public static string ALWAYS_ON_USB { + get { + return ResourceManager.GetString("ALWAYS_ON_USB", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Always on USB on battery. + /// + public static string ALWAYS_ON_USB_BATTERY { + get { + return ResourceManager.GetString("ALWAYS_ON_USB_BATTERY", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Battery Charging Mode. + /// + public static string BATTERY_CHARGING_MODE { + get { + return ResourceManager.GetString("BATTERY_CHARGING_MODE", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Battery Saving. + /// + public static string BATTERY_SAVING { + get { + return ResourceManager.GetString("BATTERY_SAVING", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Conservation. + /// + public static string CONSERVATION { + get { + return ResourceManager.GetString("CONSERVATION", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Extreme Performance. + /// + public static string EXTREME_PERFORMANCE { + get { + return ResourceManager.GetString("EXTREME_PERFORMANCE", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Flip to Boot. + /// + public static string FLIP_TO_BOOT { + get { + return ResourceManager.GetString("FLIP_TO_BOOT", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Intelligent Cooling. + /// + public static string INTELLIGENT_COOLING { + get { + return ResourceManager.GetString("INTELLIGENT_COOLING", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Language. + /// + public static string LANGUAGE { + get { + return ResourceManager.GetString("LANGUAGE", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Normal. + /// + public static string NORMAL { + get { + return ResourceManager.GetString("NORMAL", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Other. + /// + public static string OTHER { + get { + return ResourceManager.GetString("OTHER", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Power Profile. + /// + public static string POWER_PROFILE { + get { + return ResourceManager.GetString("POWER_PROFILE", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Rapid. + /// + public static string RAPID { + get { + return ResourceManager.GetString("RAPID", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Run On Startup. + /// + public static string RUN_ON_STARTUP { + get { + return ResourceManager.GetString("RUN_ON_STARTUP", resourceCulture); + } + } + } +} diff --git a/IdeapadToolkit/Localization/Strings.cs-CZ.resx b/IdeapadToolkit/Localization/Strings.cs-CZ.resx new file mode 100644 index 0000000..60c72df --- /dev/null +++ b/IdeapadToolkit/Localization/Strings.cs-CZ.resx @@ -0,0 +1,162 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + USB vždy zapnuté + + + USB vždy zapnuté i na baterii + + + Režim nabíjení baterie + + + Úspora baterie + + + Šetrný + + + Extrémní výkon + + + Zapnout při otevření + + + Chytré chlazení + + + Jazyk + + + Normální + + + Ostatní + + + Výkonostní profil + + + Rychlý + + + Spustit při startu + + \ No newline at end of file diff --git a/IdeapadToolkit/Localization/Strings.fr-FR.resx b/IdeapadToolkit/Localization/Strings.fr-FR.resx new file mode 100644 index 0000000..d58980a --- /dev/null +++ b/IdeapadToolkit/Localization/Strings.fr-FR.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + \ No newline at end of file diff --git a/IdeapadToolkit/Localization/Strings.resx b/IdeapadToolkit/Localization/Strings.resx new file mode 100644 index 0000000..812d143 --- /dev/null +++ b/IdeapadToolkit/Localization/Strings.resx @@ -0,0 +1,162 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + Always on USB + + + Always on USB on battery + + + Battery Charging Mode + + + Battery Saving + + + Conservation + + + Extreme Performance + + + Flip to Boot + + + Intelligent Cooling + + + Language + + + Normal + + + Other + + + Power Profile + + + Rapid + + + Run On Startup + + \ No newline at end of file diff --git a/IdeapadToolkit/MainWindow.xaml b/IdeapadToolkit/MainWindow.xaml index 700bbde..a7683f5 100644 --- a/IdeapadToolkit/MainWindow.xaml +++ b/IdeapadToolkit/MainWindow.xaml @@ -11,14 +11,15 @@ x:Name="_mainwindow" Title="Ideapad Toolkit" Width="400" - Height="450" + Height="670" MinWidth="400" ui:TitleBar.ButtonStyle="{DynamicResource TitleBarButtonStyle}" ui:TitleBar.ExtendViewIntoTitleBar="True" ui:TitleBar.IsBackButtonVisible="False" ui:TitleBar.Style="{DynamicResource TitleBarStyle}" ui:WindowHelper.UseModernWindowStyle="True" - Background="{DynamicResource SystemControlBackgroundChromeBlackMediumBrush}" + Background="#0b0b0b" + SizeToContent="Width" WindowStartupLocation="CenterScreen" mc:Ignorable="d"> diff --git a/IdeapadToolkit/Settings.Designer.cs b/IdeapadToolkit/Settings.Designer.cs new file mode 100644 index 0000000..8475400 --- /dev/null +++ b/IdeapadToolkit/Settings.Designer.cs @@ -0,0 +1,38 @@ +//------------------------------------------------------------------------------ +// +// 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 IdeapadToolkit { + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.12.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default { + get { + return defaultInstance; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("")] + public string Language { + get { + return ((string)(this["Language"])); + } + set { + this["Language"] = value; + } + } + } +} diff --git a/IdeapadToolkit/Settings.settings b/IdeapadToolkit/Settings.settings new file mode 100644 index 0000000..e228e62 --- /dev/null +++ b/IdeapadToolkit/Settings.settings @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/IdeapadToolkit/ViewModels/SettingsViewModel.cs b/IdeapadToolkit/ViewModels/SettingsViewModel.cs index 6f96fc9..34b9dad 100644 --- a/IdeapadToolkit/ViewModels/SettingsViewModel.cs +++ b/IdeapadToolkit/ViewModels/SettingsViewModel.cs @@ -2,9 +2,16 @@ using IdeapadToolkit.Services; using ModernWpf.Controls; using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading; +using System.Windows; namespace IdeapadToolkit.ViewModels { + public record Locale(string Name, string CultureInfoCode); [INotifyPropertyChanged] public partial class SettingsViewModel @@ -16,12 +23,14 @@ public SettingsViewModel(IRunOnStartupService runOnStartupService) _runOnStartupService = runOnStartupService; } + public Locale[] SupportedLanguages { get; init; } = + [new Locale("English", "en-US"), + new Locale("Čeština", "cs-CZ"), + new Locale("Français", "fr-FR")]; + public bool IsRunOnStartupEnabled { - get - { - return _runOnStartupService.IsRunOnStartupEnabled(); - } + get => _runOnStartupService.IsRunOnStartupEnabled(); set { try @@ -36,9 +45,32 @@ public bool IsRunOnStartupEnabled Content = ex.Message, CloseButtonText = "Ok" }.ShowAsync(); - } } } + + public Locale SelectedLocale + { + get + { + var setting = Settings.Default.Language; + var locale = SupportedLanguages.FirstOrDefault(x => x.CultureInfoCode == setting); + return locale ?? new Locale(String.Empty, String.Empty); + } + set + { + if (String.IsNullOrEmpty(value?.Name)) + return; + + Settings.Default.Language = value.CultureInfoCode; + var culture = CultureInfo.GetCultureInfo(value.CultureInfoCode); + if (culture != null) + Application.Current.Dispatcher.Invoke(() => + { + Thread.CurrentThread.CurrentUICulture = culture; + }); + Settings.Default.Save(); + } + } } } diff --git a/IdeapadToolkit/Views/MainPage.xaml b/IdeapadToolkit/Views/MainPage.xaml index b654e7b..b60c41c 100644 --- a/IdeapadToolkit/Views/MainPage.xaml +++ b/IdeapadToolkit/Views/MainPage.xaml @@ -3,6 +3,7 @@ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:loc="clr-namespace:IdeapadToolkit.Localization" xmlns:local="clr-namespace:IdeapadToolkit.Views" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:system="clr-namespace:System;assembly=mscorlib" @@ -13,18 +14,17 @@ Background="Transparent" Loaded="Page_Loaded" mc:Ignorable="d"> - - + @@ -33,7 +33,7 @@ @@ -42,7 +42,7 @@ @@ -50,11 +50,11 @@ - + @@ -63,7 +63,7 @@ @@ -72,7 +72,7 @@ @@ -83,12 +83,12 @@ + Text="{x:Static loc:Strings.OTHER}" /> - - + diff --git a/IdeapadToolkit/Views/SettingsPage.xaml b/IdeapadToolkit/Views/SettingsPage.xaml index bbf2c8a..cf5baf6 100644 --- a/IdeapadToolkit/Views/SettingsPage.xaml +++ b/IdeapadToolkit/Views/SettingsPage.xaml @@ -3,6 +3,7 @@ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:loc="clr-namespace:IdeapadToolkit.Localization" xmlns:local="clr-namespace:IdeapadToolkit.Views" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:ui="http://schemas.modernwpf.com/2019" @@ -10,10 +11,20 @@ d:DesignHeight="450" d:DesignWidth="800" mc:Ignorable="d"> - - + + + + + + + + \ No newline at end of file diff --git a/IdeapadToolkit/Views/TrayIconView.xaml b/IdeapadToolkit/Views/TrayIconView.xaml index 7a418e9..8a952c4 100644 --- a/IdeapadToolkit/Views/TrayIconView.xaml +++ b/IdeapadToolkit/Views/TrayIconView.xaml @@ -3,6 +3,7 @@ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:loc="clr-namespace:IdeapadToolkit.Localization" xmlns:local="clr-namespace:IdeapadToolkit.Views" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:system="clr-namespace:System;assembly=mscorlib" @@ -25,7 +26,7 @@ 1 @@ -34,7 +35,7 @@ 0 @@ -43,7 +44,7 @@ 2 @@ -53,7 +54,7 @@ 2 @@ -62,7 +63,7 @@ 1 @@ -71,7 +72,7 @@ 3