Skip to content

Commit bb25774

Browse files
authored
Merge branch 'dev' into dev4
2 parents f9983b5 + 32bedde commit bb25774

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
@@ -19,23 +19,52 @@ public class Internationalization
1919
{
2020
public Settings Settings { get; set; }
2121
private const string Folder = "Languages";
22+
private const string DefaultLanguageCode = "en";
2223
private const string DefaultFile = "en.xaml";
2324
private const string Extension = ".xaml";
2425
private readonly List<string> _languageDirectories = new List<string>();
2526
private readonly List<ResourceDictionary> _oldResources = new List<ResourceDictionary>();
27+
private readonly string SystemLanguageCode;
2628

2729
public Internationalization()
2830
{
2931
AddFlowLauncherLanguageDirectory();
32+
SystemLanguageCode = GetSystemLanguageCodeAtStartup();
3033
}
3134

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

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

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

76115
private Language GetLanguageByLanguageCode(string languageCode)
@@ -88,11 +127,10 @@ private Language GetLanguageByLanguageCode(string languageCode)
88127
}
89128
}
90129

91-
public void ChangeLanguage(Language language)
130+
private void ChangeLanguage(Language language, bool isSystem)
92131
{
93132
language = language.NonNull();
94133

95-
96134
RemoveOldLanguageFiles();
97135
if (language != AvailableLanguages.English)
98136
{
@@ -104,7 +142,7 @@ public void ChangeLanguage(Language language)
104142
CultureInfo.CurrentUICulture = CultureInfo.CurrentCulture;
105143

106144
// Raise event after culture is set
107-
Settings.Language = language.LanguageCode;
145+
Settings.Language = isSystem ? Constant.SystemLanguageCode : language.LanguageCode;
108146
_ = Task.Run(() =>
109147
{
110148
UpdatePluginMetadataTranslations();
@@ -168,7 +206,9 @@ private void LoadLanguage(Language language)
168206

169207
public List<Language> LoadAvailableLanguages()
170208
{
171-
return AvailableLanguages.GetAvailableLanguages();
209+
var list = AvailableLanguages.GetAvailableLanguages();
210+
list.Insert(0, new Language(Constant.SystemLanguageCode, AvailableLanguages.GetSystemTranslation(SystemLanguageCode)));
211+
return list;
172212
}
173213

174214
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
@@ -25,7 +25,7 @@ public void Save()
2525
_storage.Save();
2626
}
2727

28-
private string language = "en";
28+
private string language = Constant.SystemLanguageCode;
2929
private string _theme = Constant.DefaultTheme;
3030
public string Hotkey { get; set; } = $"{KeyConstant.Alt} + {KeyConstant.Space}";
3131
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)