Skip to content

Commit 20b27ed

Browse files
authored
Merge branch 'Flow-Launcher:dev' into jsonrpc_api
2 parents 1bd9bc2 + 32bedde commit 20b27ed

File tree

5 files changed

+139
-15
lines changed

5 files changed

+139
-15
lines changed

Flow.Launcher.Core/Resource/AvailableLanguages.cs

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ internal static class AvailableLanguages
3030
public static Language Vietnamese = new Language("vi-vn", "Tiếng Việt");
3131
public static Language Hebrew = new Language("he", "עברית");
3232

33-
3433
public static List<Language> GetAvailableLanguages()
3534
{
3635
List<Language> languages = new List<Language>
@@ -63,5 +62,38 @@ public static List<Language> GetAvailableLanguages()
6362
};
6463
return languages;
6564
}
65+
66+
public static string GetSystemTranslation(string languageCode)
67+
{
68+
return languageCode switch
69+
{
70+
"en" => "System",
71+
"zh-cn" => "系统",
72+
"zh-tw" => "系統",
73+
"uk-UA" => "Система",
74+
"ru" => "Система",
75+
"fr" => "Système",
76+
"ja" => "システム",
77+
"nl" => "Systeem",
78+
"pl" => "System",
79+
"da" => "System",
80+
"de" => "System",
81+
"ko" => "시스템",
82+
"sr" => "Систем",
83+
"pt-pt" => "Sistema",
84+
"pt-br" => "Sistema",
85+
"es" => "Sistema",
86+
"es-419" => "Sistema",
87+
"it" => "Sistema",
88+
"nb-NO" => "System",
89+
"sk" => "Systém",
90+
"tr" => "Sistem",
91+
"cs" => "Systém",
92+
"ar" => "النظام",
93+
"vi-vn" => "Hệ thống",
94+
"he" => "מערכת",
95+
_ => "System",
96+
};
97+
}
6698
}
6799
}

Flow.Launcher.Core/Resource/Internationalization.cs

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,52 @@ public class Internationalization
1818
{
1919
public Settings Settings { get; set; }
2020
private const string Folder = "Languages";
21+
private const string DefaultLanguageCode = "en";
2122
private const string DefaultFile = "en.xaml";
2223
private const string Extension = ".xaml";
2324
private readonly List<string> _languageDirectories = new List<string>();
2425
private readonly List<ResourceDictionary> _oldResources = new List<ResourceDictionary>();
26+
private readonly string SystemLanguageCode;
2527

2628
public Internationalization()
2729
{
2830
AddFlowLauncherLanguageDirectory();
31+
SystemLanguageCode = GetSystemLanguageCodeAtStartup();
2932
}
3033

31-
3234
private void AddFlowLauncherLanguageDirectory()
3335
{
3436
var directory = Path.Combine(Constant.ProgramDirectory, Folder);
3537
_languageDirectories.Add(directory);
3638
}
3739

40+
private static string GetSystemLanguageCodeAtStartup()
41+
{
42+
var availableLanguages = AvailableLanguages.GetAvailableLanguages();
43+
44+
// Retrieve the language identifiers for the current culture.
45+
// ChangeLanguage method overrides the CultureInfo.CurrentCulture, so this needs to
46+
// be called at startup in order to get the correct lang code of system.
47+
var currentCulture = CultureInfo.CurrentCulture;
48+
var twoLetterCode = currentCulture.TwoLetterISOLanguageName;
49+
var threeLetterCode = currentCulture.ThreeLetterISOLanguageName;
50+
var fullName = currentCulture.Name;
51+
52+
// Try to find a match in the available languages list
53+
foreach (var language in availableLanguages)
54+
{
55+
var languageCode = language.LanguageCode;
56+
57+
if (string.Equals(languageCode, twoLetterCode, StringComparison.OrdinalIgnoreCase) ||
58+
string.Equals(languageCode, threeLetterCode, StringComparison.OrdinalIgnoreCase) ||
59+
string.Equals(languageCode, fullName, StringComparison.OrdinalIgnoreCase))
60+
{
61+
return languageCode;
62+
}
63+
}
64+
65+
return DefaultLanguageCode;
66+
}
3867

3968
internal void AddPluginLanguageDirectories(IEnumerable<PluginPair> plugins)
4069
{
@@ -68,8 +97,18 @@ private void LoadDefaultLanguage()
6897
public void ChangeLanguage(string languageCode)
6998
{
7099
languageCode = languageCode.NonNull();
71-
Language language = GetLanguageByLanguageCode(languageCode);
72-
ChangeLanguage(language);
100+
101+
// Get actual language if language code is system
102+
var isSystem = false;
103+
if (languageCode == Constant.SystemLanguageCode)
104+
{
105+
languageCode = SystemLanguageCode;
106+
isSystem = true;
107+
}
108+
109+
// Get language by language code and change language
110+
var language = GetLanguageByLanguageCode(languageCode);
111+
ChangeLanguage(language, isSystem);
73112
}
74113

75114
private Language GetLanguageByLanguageCode(string languageCode)
@@ -87,11 +126,10 @@ private Language GetLanguageByLanguageCode(string languageCode)
87126
}
88127
}
89128

90-
public void ChangeLanguage(Language language)
129+
private void ChangeLanguage(Language language, bool isSystem)
91130
{
92131
language = language.NonNull();
93132

94-
95133
RemoveOldLanguageFiles();
96134
if (language != AvailableLanguages.English)
97135
{
@@ -103,7 +141,7 @@ public void ChangeLanguage(Language language)
103141
CultureInfo.CurrentUICulture = CultureInfo.CurrentCulture;
104142

105143
// Raise event after culture is set
106-
Settings.Language = language.LanguageCode;
144+
Settings.Language = isSystem ? Constant.SystemLanguageCode : language.LanguageCode;
107145
_ = Task.Run(() =>
108146
{
109147
UpdatePluginMetadataTranslations();
@@ -167,7 +205,9 @@ private void LoadLanguage(Language language)
167205

168206
public List<Language> LoadAvailableLanguages()
169207
{
170-
return AvailableLanguages.GetAvailableLanguages();
208+
var list = AvailableLanguages.GetAvailableLanguages();
209+
list.Insert(0, new Language(Constant.SystemLanguageCode, AvailableLanguages.GetSystemTranslation(SystemLanguageCode)));
210+
return list;
171211
}
172212

173213
public string GetTranslation(string key)

Flow.Launcher.Infrastructure/Constant.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,7 @@ public static class Constant
5252
public const string SponsorPage = "https://github.com/sponsors/Flow-Launcher";
5353
public const string GitHub = "https://github.com/Flow-Launcher/Flow.Launcher";
5454
public const string Docs = "https://flowlauncher.com/docs";
55+
56+
public const string SystemLanguageCode = "system";
5557
}
5658
}

Flow.Launcher.Infrastructure/UserSettings/Settings.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace Flow.Launcher.Infrastructure.UserSettings
1313
{
1414
public class Settings : BaseModel, IHotkeySettings
1515
{
16-
private string language = "en";
16+
private string language = Constant.SystemLanguageCode;
1717
private string _theme = Constant.DefaultTheme;
1818
public string Hotkey { get; set; } = $"{KeyConstant.Alt} + {KeyConstant.Space}";
1919
public string OpenResultModifiers { get; set; } = KeyConstant.Alt;

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

Lines changed: 56 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,36 @@ public class Main : ISettingProvider, IAsyncPlugin, IPluginI18n, IContextMenu, I
4141
"uninst000.exe",
4242
"uninstall.exe"
4343
};
44-
// For cases when the uninstaller is named like "Uninstall Program Name.exe"
45-
private const string CommonUninstallerPrefix = "uninstall";
46-
private const string CommonUninstallerSuffix = ".exe";
44+
private static readonly string[] commonUninstallerPrefixs =
45+
{
46+
"uninstall",//en
47+
"卸载",//zh-cn
48+
"卸載",//zh-tw
49+
"видалити",//uk-UA
50+
"удалить",//ru
51+
"désinstaller",//fr
52+
"アンインストール",//ja
53+
"deïnstalleren",//nl
54+
"odinstaluj",//pl
55+
"afinstallere",//da
56+
"deinstallieren",//de
57+
"삭제",//ko
58+
"деинсталирај",//sr
59+
"desinstalar",//pt-pt
60+
"desinstalar",//pt-br
61+
"desinstalar",//es
62+
"desinstalar",//es-419
63+
"disinstallare",//it
64+
"avinstallere",//nb-NO
65+
"odinštalovať",//sk
66+
"kaldır",//tr
67+
"odinstalovat",//cs
68+
"إلغاء التثبيت",//ar
69+
"gỡ bỏ",//vi-vn
70+
"הסרה"//he
71+
};
72+
private const string ExeUninstallerSuffix = ".exe";
73+
private const string InkUninstallerSuffix = ".lnk";
4774

4875
static Main()
4976
{
@@ -96,10 +123,33 @@ private bool HideUninstallersFilter(IProgram program)
96123
{
97124
if (!_settings.HideUninstallers) return true;
98125
if (program is not Win32 win32) return true;
126+
127+
// First check the executable path
99128
var fileName = Path.GetFileName(win32.ExecutablePath);
100-
return !commonUninstallerNames.Contains(fileName, StringComparer.OrdinalIgnoreCase) &&
101-
!(fileName.StartsWith(CommonUninstallerPrefix, StringComparison.OrdinalIgnoreCase) &&
102-
fileName.EndsWith(CommonUninstallerSuffix, StringComparison.OrdinalIgnoreCase));
129+
// For cases when the uninstaller is named like "uninst.exe"
130+
if (commonUninstallerNames.Contains(fileName, StringComparer.OrdinalIgnoreCase)) return false;
131+
// For cases when the uninstaller is named like "Uninstall Program Name.exe"
132+
foreach (var prefix in commonUninstallerPrefixs)
133+
{
134+
if (fileName.StartsWith(prefix, StringComparison.OrdinalIgnoreCase) &&
135+
fileName.EndsWith(ExeUninstallerSuffix, StringComparison.OrdinalIgnoreCase))
136+
return false;
137+
}
138+
139+
// Second check the lnk path
140+
if (!string.IsNullOrEmpty(win32.LnkResolvedPath))
141+
{
142+
var inkFileName = Path.GetFileName(win32.FullPath);
143+
// For cases when the uninstaller is named like "Uninstall Program Name.ink"
144+
foreach (var prefix in commonUninstallerPrefixs)
145+
{
146+
if (inkFileName.StartsWith(prefix, StringComparison.OrdinalIgnoreCase) &&
147+
inkFileName.EndsWith(InkUninstallerSuffix, StringComparison.OrdinalIgnoreCase))
148+
return false;
149+
}
150+
}
151+
152+
return true;
103153
}
104154

105155
public async Task InitAsync(PluginInitContext context)

0 commit comments

Comments
 (0)