Use DefaultThreadCurrentCulture for culture in app domain

This commit is contained in:
Vic 2022-11-25 12:00:37 +08:00
parent a15a408077
commit 30987f9c95
6 changed files with 16 additions and 14 deletions

View file

@ -17,7 +17,6 @@ namespace Flow.Launcher.Core.Resource
public class Internationalization
{
public Settings Settings { get; set; }
public CultureInfo CurrentCulture { get; private set; }
private const string Folder = "Languages";
private const string DefaultFile = "en.xaml";
private const string Extension = ".xaml";
@ -63,7 +62,6 @@ namespace Flow.Launcher.Core.Resource
{
LoadLanguage(AvailableLanguages.English);
_oldResources.Clear();
CurrentCulture = new CultureInfo("en");
}
public void ChangeLanguage(string languageCode)
@ -98,11 +96,15 @@ namespace Flow.Launcher.Core.Resource
{
LoadLanguage(language);
}
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;
CurrentCulture = CultureInfo.CurrentCulture;
// App domain
CultureInfo.DefaultThreadCurrentCulture = CultureInfo.CreateSpecificCulture(language.LanguageCode);
CultureInfo.DefaultThreadCurrentUICulture = CultureInfo.DefaultThreadCurrentCulture;
// Raise event after this.CurrentCulture is set
// Raise event after culture is set
Settings.Language = language.LanguageCode;
_ = Task.Run(() =>
{
@ -191,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)
{

View file

@ -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

View file

@ -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();
}
}
}
}

View file

@ -335,7 +335,7 @@ namespace Flow.Launcher.ViewModel
public Settings Settings { get; }
public string ClockText { get; private set; }
public string DateText { get; private set; }
public CultureInfo Culture => InternationalizationManager.Instance.CurrentCulture;
public CultureInfo Culture => CultureInfo.DefaultThreadCurrentCulture;
private async Task RegisterClockAndDateUpdateAsync()
{

View file

@ -85,7 +85,7 @@ namespace Flow.Launcher.ViewModel
}
}
public CultureInfo Culture => InternationalizationManager.Instance.CurrentCulture;
public CultureInfo Culture => CultureInfo.DefaultThreadCurrentCulture;
public bool StartFlowLauncherOnSystemStartup
{

View file

@ -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;