Skip to content

Commit 30987f9

Browse files
Use DefaultThreadCurrentCulture for culture in app domain
1 parent a15a408 commit 30987f9

File tree

6 files changed

+16
-14
lines changed

6 files changed

+16
-14
lines changed

Flow.Launcher.Core/Resource/Internationalization.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ namespace Flow.Launcher.Core.Resource
1717
public class Internationalization
1818
{
1919
public Settings Settings { get; set; }
20-
public CultureInfo CurrentCulture { get; private set; }
2120
private const string Folder = "Languages";
2221
private const string DefaultFile = "en.xaml";
2322
private const string Extension = ".xaml";
@@ -63,7 +62,6 @@ private void LoadDefaultLanguage()
6362
{
6463
LoadLanguage(AvailableLanguages.English);
6564
_oldResources.Clear();
66-
CurrentCulture = new CultureInfo("en");
6765
}
6866

6967
public void ChangeLanguage(string languageCode)
@@ -98,11 +96,15 @@ public void ChangeLanguage(Language language)
9896
{
9997
LoadLanguage(language);
10098
}
101-
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);
102102
CultureInfo.CurrentUICulture = CultureInfo.CurrentCulture;
103-
CurrentCulture = CultureInfo.CurrentCulture;
103+
// App domain
104+
CultureInfo.DefaultThreadCurrentCulture = CultureInfo.CreateSpecificCulture(language.LanguageCode);
105+
CultureInfo.DefaultThreadCurrentUICulture = CultureInfo.DefaultThreadCurrentCulture;
104106

105-
// Raise event after this.CurrentCulture is set
107+
// Raise event after culture is set
106108
Settings.Language = language.LanguageCode;
107109
_ = Task.Run(() =>
108110
{
@@ -191,7 +193,7 @@ private void UpdatePluginMetadataTranslations()
191193
{
192194
p.Metadata.Name = pluginI18N.GetTranslatedPluginTitle();
193195
p.Metadata.Description = pluginI18N.GetTranslatedPluginDescription();
194-
pluginI18N.OnCultureInfoChanged(CultureInfo.CurrentCulture);
196+
pluginI18N.OnCultureInfoChanged(CultureInfo.DefaultThreadCurrentCulture);
195197
}
196198
catch (Exception e)
197199
{

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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ private void Esc()
335335
public Settings Settings { get; }
336336
public string ClockText { get; private set; }
337337
public string DateText { get; private set; }
338-
public CultureInfo Culture => InternationalizationManager.Instance.CurrentCulture;
338+
public CultureInfo Culture => CultureInfo.DefaultThreadCurrentCulture;
339339

340340
private async Task RegisterClockAndDateUpdateAsync()
341341
{

Flow.Launcher/ViewModel/SettingWindowViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public bool AutoUpdates
8585
}
8686
}
8787

88-
public CultureInfo Culture => InternationalizationManager.Instance.CurrentCulture;
88+
public CultureInfo Culture => CultureInfo.DefaultThreadCurrentCulture;
8989

9090
public bool StartFlowLauncherOnSystemStartup
9191
{

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)