Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion Flow.Launcher.Core/Resource/AvailableLanguages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,11 @@
public static Language Norwegian_Bokmal = new Language("nb-NO", "Norsk Bokmål");
public static Language Slovak = new Language("sk", "Slovenčina");
public static Language Turkish = new Language("tr", "Türkçe");
public static Language Czech = new Language("cs", "čeština");

Check notice on line 28 in Flow.Launcher.Core/Resource/AvailableLanguages.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`Line` matches candidate pattern `[a-zA-Z]*[ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýÿĀāŁłŃńŅņŒœŚśŠšŜŝŸŽžź][a-zA-Z]{3}[a-zA-ZÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýÿĀāŁłŃńŅņŒœŚśŠšŜŝŸŽžź]*` (candidate-pattern)
public static Language Arabic = new Language("ar", "اللغة العربية");
public static Language Vietnamese = new Language("vi-vn", "Tiếng Việt");
public static Language Hebrew = new Language("he", "עברית");


public static List<Language> GetAvailableLanguages()
{
List<Language> languages = new List<Language>
Expand Down Expand Up @@ -63,5 +62,38 @@
};
return languages;
}

public static string GetSystemTranslation(string languageCode)
{
return languageCode switch
{
"en" => "System",
"zh-cn" => "系统",
"zh-tw" => "系統",
"uk-UA" => "Система",
"ru" => "Система",
"fr" => "Système",
"ja" => "システム",
"nl" => "Systeem",
"pl" => "System",
"da" => "System",
"de" => "System",
"ko" => "시스템",
"sr" => "Систем",
"pt-pt" => "Sistema",
"pt-br" => "Sistema",
"es" => "Sistema",
"es-419" => "Sistema",
"it" => "Sistema",
"nb-NO" => "System",
"sk" => "Systém",
"tr" => "Sistem",
"cs" => "Systém",
"ar" => "النظام",
"vi-vn" => "Hệ thống",
"he" => "מערכת",
_ => "System",
};
}
}
}
54 changes: 47 additions & 7 deletions Flow.Launcher.Core/Resource/Internationalization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,52 @@ public class Internationalization
{
public Settings Settings { get; set; }
private const string Folder = "Languages";
private const string DefaultLanguageCode = "en";
private const string DefaultFile = "en.xaml";
private const string Extension = ".xaml";
private readonly List<string> _languageDirectories = new List<string>();
private readonly List<ResourceDictionary> _oldResources = new List<ResourceDictionary>();
private readonly string SystemLanguageCode;

public Internationalization()
{
AddFlowLauncherLanguageDirectory();
SystemLanguageCode = GetSystemLanguageCodeAtStartup();
}


private void AddFlowLauncherLanguageDirectory()
{
var directory = Path.Combine(Constant.ProgramDirectory, Folder);
_languageDirectories.Add(directory);
}

private static string GetSystemLanguageCodeAtStartup()
{
var availableLanguages = AvailableLanguages.GetAvailableLanguages();

// Retrieve the language identifiers for the current culture.
// ChangeLanguage method overrides the CultureInfo.CurrentCulture, so this needs to
// be called at startup in order to get the correct lang code of system.
var currentCulture = CultureInfo.CurrentCulture;
var twoLetterCode = currentCulture.TwoLetterISOLanguageName;
var threeLetterCode = currentCulture.ThreeLetterISOLanguageName;
var fullName = currentCulture.Name;

// Try to find a match in the available languages list
foreach (var language in availableLanguages)
{
var languageCode = language.LanguageCode;

if (string.Equals(languageCode, twoLetterCode, StringComparison.OrdinalIgnoreCase) ||
string.Equals(languageCode, threeLetterCode, StringComparison.OrdinalIgnoreCase) ||
string.Equals(languageCode, fullName, StringComparison.OrdinalIgnoreCase))
{
return languageCode;
}
}

return DefaultLanguageCode;
}

internal void AddPluginLanguageDirectories(IEnumerable<PluginPair> plugins)
{
Expand Down Expand Up @@ -68,8 +97,18 @@ private void LoadDefaultLanguage()
public void ChangeLanguage(string languageCode)
{
languageCode = languageCode.NonNull();
Language language = GetLanguageByLanguageCode(languageCode);
ChangeLanguage(language);

// Get actual language if language code is system
var isSystem = false;
if (languageCode == Constant.SystemLanguageCode)
{
languageCode = SystemLanguageCode;
isSystem = true;
}

// Get language by language code and change language
var language = GetLanguageByLanguageCode(languageCode);
ChangeLanguage(language, isSystem);
}

private Language GetLanguageByLanguageCode(string languageCode)
Expand All @@ -87,11 +126,10 @@ private Language GetLanguageByLanguageCode(string languageCode)
}
}

public void ChangeLanguage(Language language)
private void ChangeLanguage(Language language, bool isSystem)
{
language = language.NonNull();


RemoveOldLanguageFiles();
if (language != AvailableLanguages.English)
{
Expand All @@ -103,7 +141,7 @@ public void ChangeLanguage(Language language)
CultureInfo.CurrentUICulture = CultureInfo.CurrentCulture;

// Raise event after culture is set
Settings.Language = language.LanguageCode;
Settings.Language = isSystem ? Constant.SystemLanguageCode : language.LanguageCode;
_ = Task.Run(() =>
{
UpdatePluginMetadataTranslations();
Expand Down Expand Up @@ -167,7 +205,9 @@ private void LoadLanguage(Language language)

public List<Language> LoadAvailableLanguages()
{
return AvailableLanguages.GetAvailableLanguages();
var list = AvailableLanguages.GetAvailableLanguages();
list.Insert(0, new Language(Constant.SystemLanguageCode, AvailableLanguages.GetSystemTranslation(SystemLanguageCode)));
return list;
}

public string GetTranslation(string key)
Expand Down
2 changes: 2 additions & 0 deletions Flow.Launcher.Infrastructure/Constant.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,7 @@ public static class Constant
public const string SponsorPage = "https://github.com/sponsors/Flow-Launcher";
public const string GitHub = "https://github.com/Flow-Launcher/Flow.Launcher";
public const string Docs = "https://flowlauncher.com/docs";

public const string SystemLanguageCode = "system";
}
}
2 changes: 1 addition & 1 deletion Flow.Launcher.Infrastructure/UserSettings/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace Flow.Launcher.Infrastructure.UserSettings
{
public class Settings : BaseModel, IHotkeySettings
{
private string language = "en";
private string language = Constant.SystemLanguageCode;
private string _theme = Constant.DefaultTheme;
public string Hotkey { get; set; } = $"{KeyConstant.Alt} + {KeyConstant.Space}";
public string OpenResultModifiers { get; set; } = KeyConstant.Alt;
Expand Down
Loading