diff --git a/Flow.Launcher.Core/Resource/Internationalization.cs b/Flow.Launcher.Core/Resource/Internationalization.cs index 4568e92f3..acc693ed5 100644 --- a/Flow.Launcher.Core/Resource/Internationalization.cs +++ b/Flow.Launcher.Core/Resource/Internationalization.cs @@ -96,9 +96,16 @@ namespace Flow.Launcher.Core.Resource { LoadLanguage(language); } - Settings.Language = language.LanguageCode; - CultureInfo.CurrentCulture = new CultureInfo(language.LanguageCode); + // Culture of this thread + // Use CreateSpecificCulture to preserve possible user-override settings in Windows + CultureInfo.CurrentCulture = CultureInfo.CreateSpecificCulture(language.LanguageCode); CultureInfo.CurrentUICulture = CultureInfo.CurrentCulture; + // App domain + CultureInfo.DefaultThreadCurrentCulture = CultureInfo.CreateSpecificCulture(language.LanguageCode); + CultureInfo.DefaultThreadCurrentUICulture = CultureInfo.DefaultThreadCurrentCulture; + + // Raise event after culture is set + Settings.Language = language.LanguageCode; _ = Task.Run(() => { UpdatePluginMetadataTranslations(); @@ -186,7 +193,7 @@ namespace Flow.Launcher.Core.Resource { p.Metadata.Name = pluginI18N.GetTranslatedPluginTitle(); p.Metadata.Description = pluginI18N.GetTranslatedPluginDescription(); - pluginI18N.OnCultureInfoChanged(CultureInfo.CurrentCulture); + pluginI18N.OnCultureInfoChanged(CultureInfo.DefaultThreadCurrentCulture); } catch (Exception e) { diff --git a/Flow.Launcher.Infrastructure/UserSettings/Settings.cs b/Flow.Launcher.Infrastructure/UserSettings/Settings.cs index 33072b53d..3561c6ffe 100644 --- a/Flow.Launcher.Infrastructure/UserSettings/Settings.cs +++ b/Flow.Launcher.Infrastructure/UserSettings/Settings.cs @@ -6,7 +6,6 @@ using System.Text.Json.Serialization; using System.Windows; using Flow.Launcher.Plugin; using Flow.Launcher.Plugin.SharedModels; -using Flow.Launcher; using Flow.Launcher.ViewModel; namespace Flow.Launcher.Infrastructure.UserSettings diff --git a/Flow.Launcher/Converters/QuerySuggestionBoxConverter.cs b/Flow.Launcher/Converters/QuerySuggestionBoxConverter.cs index ecdfc5851..1e39473e0 100644 --- a/Flow.Launcher/Converters/QuerySuggestionBoxConverter.cs +++ b/Flow.Launcher/Converters/QuerySuggestionBoxConverter.cs @@ -52,7 +52,8 @@ namespace Flow.Launcher.Converters // Check if Text will be larger then our QueryTextBox System.Windows.Media.Typeface typeface = new Typeface(QueryTextBox.FontFamily, QueryTextBox.FontStyle, QueryTextBox.FontWeight, QueryTextBox.FontStretch); - System.Windows.Media.FormattedText ft = new FormattedText(QueryTextBox.Text, System.Globalization.CultureInfo.CurrentCulture, System.Windows.FlowDirection.LeftToRight, typeface, QueryTextBox.FontSize, Brushes.Black); + // TODO: Obsolete warning? + System.Windows.Media.FormattedText ft = new FormattedText(QueryTextBox.Text, System.Globalization.CultureInfo.DefaultThreadCurrentCulture, System.Windows.FlowDirection.LeftToRight, typeface, QueryTextBox.FontSize, Brushes.Black); var offset = QueryTextBox.Padding.Right; @@ -75,4 +76,4 @@ namespace Flow.Launcher.Converters throw new NotImplementedException(); } } -} \ No newline at end of file +} diff --git a/Flow.Launcher/ViewModel/MainViewModel.cs b/Flow.Launcher/ViewModel/MainViewModel.cs index 29aef88fd..4db8e3df3 100644 --- a/Flow.Launcher/ViewModel/MainViewModel.cs +++ b/Flow.Launcher/ViewModel/MainViewModel.cs @@ -65,9 +65,10 @@ namespace Flow.Launcher.ViewModel Settings = settings; Settings.PropertyChanged += (_, args) => { - if (args.PropertyName == nameof(Settings.WindowSize)) - { - OnPropertyChanged(nameof(MainWindowWidth)); + switch (args.PropertyName) { + case nameof(Settings.WindowSize): + OnPropertyChanged(nameof(MainWindowWidth)); + break; } }; @@ -334,8 +335,8 @@ namespace Flow.Launcher.ViewModel public Settings Settings { get; } public string ClockText { get; private set; } public string DateText { get; private set; } + public CultureInfo Culture => CultureInfo.DefaultThreadCurrentCulture; - public CultureInfo cultureInfo => new CultureInfo(Settings.Language); private async Task RegisterClockAndDateUpdateAsync() { var timer = new PeriodicTimer(TimeSpan.FromSeconds(1)); @@ -343,11 +344,12 @@ namespace Flow.Launcher.ViewModel while (await timer.WaitForNextTickAsync().ConfigureAwait(false)) { if (Settings.UseClock) - ClockText = DateTime.Now.ToString(Settings.TimeFormat, cultureInfo); + ClockText = DateTime.Now.ToString(Settings.TimeFormat, Culture); if (Settings.UseDate) - DateText = DateTime.Now.ToString(Settings.DateFormat, cultureInfo); + DateText = DateTime.Now.ToString(Settings.DateFormat, Culture); } } + public ResultsViewModel Results { get; private set; } public ResultsViewModel ContextMenu { get; private set; } diff --git a/Flow.Launcher/ViewModel/SettingWindowViewModel.cs b/Flow.Launcher/ViewModel/SettingWindowViewModel.cs index 0c25dcc85..d9e9a3469 100644 --- a/Flow.Launcher/ViewModel/SettingWindowViewModel.cs +++ b/Flow.Launcher/ViewModel/SettingWindowViewModel.cs @@ -61,6 +61,7 @@ namespace Flow.Launcher.ViewModel break; } }; + } public Settings Settings { get; set; } @@ -84,7 +85,7 @@ namespace Flow.Launcher.ViewModel } } - public CultureInfo cultureInfo => new CultureInfo(Settings.Language); + public CultureInfo Culture => CultureInfo.DefaultThreadCurrentCulture; public bool StartFlowLauncherOnSystemStartup { @@ -496,20 +497,19 @@ namespace Flow.Launcher.ViewModel public string TimeFormat { - get { return Settings.TimeFormat; } - set { Settings.TimeFormat = value; } + get => Settings.TimeFormat; + set => Settings.TimeFormat = value; } public string DateFormat { - get { return Settings.DateFormat; } - set { Settings.DateFormat = value; } + get => Settings.DateFormat; + set => Settings.DateFormat = value; } - public string ClockText => DateTime.Now.ToString(TimeFormat, cultureInfo); - - public string DateText => DateTime.Now.ToString(DateFormat, cultureInfo); + public string ClockText => DateTime.Now.ToString(TimeFormat, Culture); + public string DateText => DateTime.Now.ToString(DateFormat, Culture); public double WindowWidthSize { diff --git a/Plugins/Flow.Launcher.Plugin.Calculator/Main.cs b/Plugins/Flow.Launcher.Plugin.Calculator/Main.cs index bc79219b6..d5dcdacea 100644 --- a/Plugins/Flow.Launcher.Plugin.Calculator/Main.cs +++ b/Plugins/Flow.Launcher.Plugin.Calculator/Main.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Globalization; using System.Runtime.InteropServices; @@ -61,7 +61,7 @@ namespace Flow.Launcher.Plugin.Caculator switch (_settings.DecimalSeparator) { case DecimalSeparator.Comma: - case DecimalSeparator.UseSystemLocale when CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator == ",": + case DecimalSeparator.UseSystemLocale when CultureInfo.DefaultThreadCurrentCulture.NumberFormat.NumberDecimalSeparator == ",": expression = query.Search.Replace(",", "."); break; default: @@ -157,7 +157,7 @@ namespace Flow.Launcher.Plugin.Caculator private string GetDecimalSeparator() { - string systemDecimalSeperator = CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator; + string systemDecimalSeperator = CultureInfo.DefaultThreadCurrentCulture.NumberFormat.NumberDecimalSeparator; switch (_settings.DecimalSeparator) { case DecimalSeparator.UseSystemLocale: return systemDecimalSeperator;