Skip to content

Commit 5b2990c

Browse files
authored
Merge pull request #1568 from VictoriousRaptor/FixNewCultureInfo
[Dev] Fix new culture info
2 parents 5044a21 + 30987f9 commit 5b2990c

File tree

6 files changed

+32
-23
lines changed

6 files changed

+32
-23
lines changed

Flow.Launcher.Core/Resource/Internationalization.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,16 @@ public void ChangeLanguage(Language language)
9696
{
9797
LoadLanguage(language);
9898
}
99-
Settings.Language = language.LanguageCode;
100-
CultureInfo.CurrentCulture = new CultureInfo(language.LanguageCode);
99+
// Culture of this thread
100+
// Use CreateSpecificCulture to preserve possible user-override settings in Windows
101+
CultureInfo.CurrentCulture = CultureInfo.CreateSpecificCulture(language.LanguageCode);
101102
CultureInfo.CurrentUICulture = CultureInfo.CurrentCulture;
103+
// App domain
104+
CultureInfo.DefaultThreadCurrentCulture = CultureInfo.CreateSpecificCulture(language.LanguageCode);
105+
CultureInfo.DefaultThreadCurrentUICulture = CultureInfo.DefaultThreadCurrentCulture;
106+
107+
// Raise event after culture is set
108+
Settings.Language = language.LanguageCode;
102109
_ = Task.Run(() =>
103110
{
104111
UpdatePluginMetadataTranslations();
@@ -186,7 +193,7 @@ private void UpdatePluginMetadataTranslations()
186193
{
187194
p.Metadata.Name = pluginI18N.GetTranslatedPluginTitle();
188195
p.Metadata.Description = pluginI18N.GetTranslatedPluginDescription();
189-
pluginI18N.OnCultureInfoChanged(CultureInfo.CurrentCulture);
196+
pluginI18N.OnCultureInfoChanged(CultureInfo.DefaultThreadCurrentCulture);
190197
}
191198
catch (Exception e)
192199
{

Flow.Launcher.Infrastructure/UserSettings/Settings.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
using System.Windows;
77
using Flow.Launcher.Plugin;
88
using Flow.Launcher.Plugin.SharedModels;
9-
using Flow.Launcher;
109
using Flow.Launcher.ViewModel;
1110

1211
namespace Flow.Launcher.Infrastructure.UserSettings

Flow.Launcher/Converters/QuerySuggestionBoxConverter.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ public object Convert(object[] values, Type targetType, object parameter, Cultur
5252

5353
// Check if Text will be larger then our QueryTextBox
5454
System.Windows.Media.Typeface typeface = new Typeface(QueryTextBox.FontFamily, QueryTextBox.FontStyle, QueryTextBox.FontWeight, QueryTextBox.FontStretch);
55-
System.Windows.Media.FormattedText ft = new FormattedText(QueryTextBox.Text, System.Globalization.CultureInfo.CurrentCulture, System.Windows.FlowDirection.LeftToRight, typeface, QueryTextBox.FontSize, Brushes.Black);
55+
// TODO: Obsolete warning?
56+
System.Windows.Media.FormattedText ft = new FormattedText(QueryTextBox.Text, System.Globalization.CultureInfo.DefaultThreadCurrentCulture, System.Windows.FlowDirection.LeftToRight, typeface, QueryTextBox.FontSize, Brushes.Black);
5657

5758
var offset = QueryTextBox.Padding.Right;
5859

@@ -75,4 +76,4 @@ public object[] ConvertBack(object value, Type[] targetTypes, object parameter,
7576
throw new NotImplementedException();
7677
}
7778
}
78-
}
79+
}

Flow.Launcher/ViewModel/MainViewModel.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,10 @@ public MainViewModel(Settings settings)
6565
Settings = settings;
6666
Settings.PropertyChanged += (_, args) =>
6767
{
68-
if (args.PropertyName == nameof(Settings.WindowSize))
69-
{
70-
OnPropertyChanged(nameof(MainWindowWidth));
68+
switch (args.PropertyName) {
69+
case nameof(Settings.WindowSize):
70+
OnPropertyChanged(nameof(MainWindowWidth));
71+
break;
7172
}
7273
};
7374

@@ -334,20 +335,21 @@ private void Esc()
334335
public Settings Settings { get; }
335336
public string ClockText { get; private set; }
336337
public string DateText { get; private set; }
338+
public CultureInfo Culture => CultureInfo.DefaultThreadCurrentCulture;
337339

338-
public CultureInfo cultureInfo => new CultureInfo(Settings.Language);
339340
private async Task RegisterClockAndDateUpdateAsync()
340341
{
341342
var timer = new PeriodicTimer(TimeSpan.FromSeconds(1));
342343
// ReSharper disable once MethodSupportsCancellation
343344
while (await timer.WaitForNextTickAsync().ConfigureAwait(false))
344345
{
345346
if (Settings.UseClock)
346-
ClockText = DateTime.Now.ToString(Settings.TimeFormat, cultureInfo);
347+
ClockText = DateTime.Now.ToString(Settings.TimeFormat, Culture);
347348
if (Settings.UseDate)
348-
DateText = DateTime.Now.ToString(Settings.DateFormat, cultureInfo);
349+
DateText = DateTime.Now.ToString(Settings.DateFormat, Culture);
349350
}
350351
}
352+
351353
public ResultsViewModel Results { get; private set; }
352354

353355
public ResultsViewModel ContextMenu { get; private set; }

Flow.Launcher/ViewModel/SettingWindowViewModel.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ public SettingWindowViewModel(Updater updater, IPortable portable)
6161
break;
6262
}
6363
};
64+
6465
}
6566

6667
public Settings Settings { get; set; }
@@ -84,7 +85,7 @@ public bool AutoUpdates
8485
}
8586
}
8687

87-
public CultureInfo cultureInfo => new CultureInfo(Settings.Language);
88+
public CultureInfo Culture => CultureInfo.DefaultThreadCurrentCulture;
8889

8990
public bool StartFlowLauncherOnSystemStartup
9091
{
@@ -496,20 +497,19 @@ public List<SearchWindowPosition> SearchWindowPositions
496497

497498
public string TimeFormat
498499
{
499-
get { return Settings.TimeFormat; }
500-
set { Settings.TimeFormat = value; }
500+
get => Settings.TimeFormat;
501+
set => Settings.TimeFormat = value;
501502
}
502503

503504
public string DateFormat
504505
{
505-
get { return Settings.DateFormat; }
506-
set { Settings.DateFormat = value; }
506+
get => Settings.DateFormat;
507+
set => Settings.DateFormat = value;
507508
}
508509

509-
public string ClockText => DateTime.Now.ToString(TimeFormat, cultureInfo);
510-
511-
public string DateText => DateTime.Now.ToString(DateFormat, cultureInfo);
510+
public string ClockText => DateTime.Now.ToString(TimeFormat, Culture);
512511

512+
public string DateText => DateTime.Now.ToString(DateFormat, Culture);
513513

514514
public double WindowWidthSize
515515
{

Plugins/Flow.Launcher.Plugin.Calculator/Main.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.Globalization;
44
using System.Runtime.InteropServices;
@@ -61,7 +61,7 @@ public List<Result> Query(Query query)
6161
switch (_settings.DecimalSeparator)
6262
{
6363
case DecimalSeparator.Comma:
64-
case DecimalSeparator.UseSystemLocale when CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator == ",":
64+
case DecimalSeparator.UseSystemLocale when CultureInfo.DefaultThreadCurrentCulture.NumberFormat.NumberDecimalSeparator == ",":
6565
expression = query.Search.Replace(",", ".");
6666
break;
6767
default:
@@ -157,7 +157,7 @@ private string ChangeDecimalSeparator(decimal value, string newDecimalSeparator)
157157

158158
private string GetDecimalSeparator()
159159
{
160-
string systemDecimalSeperator = CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator;
160+
string systemDecimalSeperator = CultureInfo.DefaultThreadCurrentCulture.NumberFormat.NumberDecimalSeparator;
161161
switch (_settings.DecimalSeparator)
162162
{
163163
case DecimalSeparator.UseSystemLocale: return systemDecimalSeperator;

0 commit comments

Comments
 (0)