mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-23 06:59:39 +01:00
[General]Support language selection (#34971)
* Language setting * spellcheck * Set FileLocksmithContextMenu package version in AppManifest.xml * Fix ambigious symbol build error * Fix ambigious symbol build error #2 * Revert unneeded changes * Improve perf * try fix ci build
This commit is contained in:
@@ -3,10 +3,13 @@
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.IO.Abstractions;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text.Json;
|
||||
@@ -145,8 +148,38 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
||||
{
|
||||
_fileWatcher = Helper.GetFileWatcher(string.Empty, UpdatingSettings.SettingsFile, dispatcherAction);
|
||||
}
|
||||
|
||||
InitializeLanguages();
|
||||
}
|
||||
|
||||
// Supported languages. Taken from Resources.wxs + default + en-US
|
||||
private Dictionary<string, string> langTagsAndIds = new Dictionary<string, string>
|
||||
{
|
||||
{ string.Empty, "Default_language" },
|
||||
{ "ar-SA", "Arabic_Saudi_Arabia_Language" },
|
||||
{ "cs-CZ", "Czech_Language" },
|
||||
{ "de-DE", "German_Language" },
|
||||
{ "en-US", "English_Language" },
|
||||
{ "es-ES", "Spanish_Language" },
|
||||
{ "fa-IR", "Persian_Farsi_Language" },
|
||||
{ "fr-FR", "French_Language" },
|
||||
{ "he-IL", "Hebrew_Israel_Language" },
|
||||
{ "hu-HU", "Hungarian_Language" },
|
||||
{ "it-IT", "Italian_Language" },
|
||||
{ "ja-JP", "Japanese_Language" },
|
||||
{ "ko-KR", "Korean_Language" },
|
||||
{ "nl-NL", "Dutch_Language" },
|
||||
{ "pl-PL", "Polish_Language" },
|
||||
{ "pt-BR", "Portuguese_Brazil_Language" },
|
||||
{ "pt-PT", "Portuguese_Portugal_Language" },
|
||||
{ "ru-RU", "Russian_Language" },
|
||||
{ "sv-SE", "Swedish_Language" },
|
||||
{ "tr-TR", "Turkish_Language" },
|
||||
{ "uk-UA", "Ukrainian_Language" },
|
||||
{ "zh-CN", "Chinese_Simplified_Language" },
|
||||
{ "zh-TW", "Chinese_Traditional_Language" },
|
||||
};
|
||||
|
||||
private static bool _isDevBuild;
|
||||
private bool _startup;
|
||||
private bool _isElevated;
|
||||
@@ -177,6 +210,10 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
||||
private string _settingsBackupMessage;
|
||||
private string _backupRestoreMessageSeverity;
|
||||
|
||||
private int _languagesIndex;
|
||||
private int _initLanguagesIndex;
|
||||
private bool _languageChanged;
|
||||
|
||||
// Gets or sets a value indicating whether run powertoys on start-up.
|
||||
public bool Startup
|
||||
{
|
||||
@@ -740,6 +777,51 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
||||
}
|
||||
}
|
||||
|
||||
public ObservableCollection<LanguageModel> Languages { get; } = new ObservableCollection<LanguageModel>();
|
||||
|
||||
public int LanguagesIndex
|
||||
{
|
||||
get
|
||||
{
|
||||
return _languagesIndex;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (_languagesIndex != value)
|
||||
{
|
||||
_languagesIndex = value;
|
||||
OnPropertyChanged(nameof(LanguagesIndex));
|
||||
NotifyLanguageChanged();
|
||||
if (_initLanguagesIndex != value)
|
||||
{
|
||||
LanguageChanged = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
LanguageChanged = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool LanguageChanged
|
||||
{
|
||||
get
|
||||
{
|
||||
return _languageChanged;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (_languageChanged != value)
|
||||
{
|
||||
_languageChanged = value;
|
||||
OnPropertyChanged(nameof(LanguageChanged));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void NotifyPropertyChanged([CallerMemberName] string propertyName = null, bool reDoBackupDryRun = true)
|
||||
{
|
||||
// Notify UI of property change
|
||||
@@ -996,5 +1078,31 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
||||
NotifyPropertyChanged(nameof(IsDownloadAllowed));
|
||||
}
|
||||
}
|
||||
|
||||
private void InitializeLanguages()
|
||||
{
|
||||
var lang = LanguageModel.LoadSetting();
|
||||
int i = 0;
|
||||
|
||||
foreach (var item in langTagsAndIds)
|
||||
{
|
||||
Languages.Add(new LanguageModel { Tag = item.Key, ResourceID = item.Value, Language = GetResourceString(item.Value) });
|
||||
|
||||
if (item.Key.Equals(lang, StringComparison.Ordinal))
|
||||
{
|
||||
_initLanguagesIndex = i;
|
||||
LanguagesIndex = i;
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
private void NotifyLanguageChanged()
|
||||
{
|
||||
OutGoingLanguageSettings outsettings = new OutGoingLanguageSettings(langTagsAndIds.ElementAt(LanguagesIndex).Key);
|
||||
|
||||
SendConfigMSG(outsettings.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user