mirror of
https://github.com/chylex/TweetDuck.git
synced 2025-01-23 18:46:02 +01:00
Replace app locale option with spell check language & use correct lang list
This commit is contained in:
parent
f0a79add14
commit
301d4fb171
@ -10,7 +10,9 @@
|
||||
|
||||
namespace TweetDuck.Configuration{
|
||||
sealed class UserConfig{
|
||||
private static readonly FileSerializer<UserConfig> Serializer = new FileSerializer<UserConfig>();
|
||||
private static readonly FileSerializer<UserConfig> Serializer = new FileSerializer<UserConfig>{
|
||||
HandleUnknownProperties = FileSerializer<UserConfig>.IgnoreProperties("AppLocale")
|
||||
};
|
||||
|
||||
static UserConfig(){
|
||||
Serializer.RegisterTypeConverter(typeof(WindowState), WindowState.Converter);
|
||||
@ -50,9 +52,9 @@ static UserConfig(){
|
||||
private int _zoomLevel = 100;
|
||||
private bool _muteNotifications;
|
||||
|
||||
public bool EnableSpellCheck { get; set; } = false;
|
||||
public string AppLocale { get; set; } = "en-US";
|
||||
public string TranslationTarget { get; set; } = "en";
|
||||
public bool EnableSpellCheck { get; set; } = false;
|
||||
public string SpellCheckLanguage { get; set; } = "en-US";
|
||||
public string TranslationTarget { get; set; } = "en";
|
||||
|
||||
private TrayIcon.Behavior _trayBehavior = TrayIcon.Behavior.Disabled;
|
||||
public bool EnableTrayHighlight { get; set; } = true;
|
||||
|
@ -11,6 +11,7 @@ public static Task UpdatePrefs(){
|
||||
private static void UpdatePrefsInternal(){
|
||||
using(IRequestContext ctx = Cef.GetGlobalRequestContext()){
|
||||
ctx.SetPreference("browser.enable_spellchecking", Program.UserConfig.EnableSpellCheck, out string _);
|
||||
ctx.SetPreference("spellcheck.dictionary", Program.UserConfig.SpellCheckLanguage, out string _);
|
||||
ctx.SetPreference("settings.a11y.animation_policy", Program.UserConfig.EnableAnimatedImages ? "allowed" : "none", out string _);
|
||||
}
|
||||
}
|
||||
|
44
Core/Other/Settings/TabSettingsLocales.Designer.cs
generated
44
Core/Other/Settings/TabSettingsLocales.Designer.cs
generated
@ -28,8 +28,8 @@ private void InitializeComponent() {
|
||||
this.checkSpellCheck = new System.Windows.Forms.CheckBox();
|
||||
this.labelLocales = new System.Windows.Forms.Label();
|
||||
this.flowPanel = new System.Windows.Forms.FlowLayoutPanel();
|
||||
this.labelAppLanguage = new System.Windows.Forms.Label();
|
||||
this.comboBoxAppLocale = new System.Windows.Forms.ComboBox();
|
||||
this.labelSpellCheckLanguage = new System.Windows.Forms.Label();
|
||||
this.comboBoxSpellCheckLanguage = new System.Windows.Forms.ComboBox();
|
||||
this.labelTranslations = new System.Windows.Forms.Label();
|
||||
this.labelTranslationTarget = new System.Windows.Forms.Label();
|
||||
this.comboBoxTranslationTarget = new System.Windows.Forms.ComboBox();
|
||||
@ -65,8 +65,8 @@ private void InitializeComponent() {
|
||||
| System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.flowPanel.Controls.Add(this.labelLocales);
|
||||
this.flowPanel.Controls.Add(this.checkSpellCheck);
|
||||
this.flowPanel.Controls.Add(this.labelAppLanguage);
|
||||
this.flowPanel.Controls.Add(this.comboBoxAppLocale);
|
||||
this.flowPanel.Controls.Add(this.labelSpellCheckLanguage);
|
||||
this.flowPanel.Controls.Add(this.comboBoxSpellCheckLanguage);
|
||||
this.flowPanel.Controls.Add(this.labelTranslations);
|
||||
this.flowPanel.Controls.Add(this.labelTranslationTarget);
|
||||
this.flowPanel.Controls.Add(this.comboBoxTranslationTarget);
|
||||
@ -77,25 +77,25 @@ private void InitializeComponent() {
|
||||
this.flowPanel.TabIndex = 4;
|
||||
this.flowPanel.WrapContents = false;
|
||||
//
|
||||
// labelAppLanguage
|
||||
// labelSpellCheckLanguage
|
||||
//
|
||||
this.labelAppLanguage.AutoSize = true;
|
||||
this.labelAppLanguage.Location = new System.Drawing.Point(3, 58);
|
||||
this.labelAppLanguage.Margin = new System.Windows.Forms.Padding(3, 12, 3, 0);
|
||||
this.labelAppLanguage.Name = "labelAppLanguage";
|
||||
this.labelAppLanguage.Size = new System.Drawing.Size(77, 13);
|
||||
this.labelAppLanguage.TabIndex = 11;
|
||||
this.labelAppLanguage.Text = "App Language";
|
||||
this.labelSpellCheckLanguage.AutoSize = true;
|
||||
this.labelSpellCheckLanguage.Location = new System.Drawing.Point(3, 58);
|
||||
this.labelSpellCheckLanguage.Margin = new System.Windows.Forms.Padding(3, 12, 3, 0);
|
||||
this.labelSpellCheckLanguage.Name = "labelSpellCheckLanguage";
|
||||
this.labelSpellCheckLanguage.Size = new System.Drawing.Size(115, 13);
|
||||
this.labelSpellCheckLanguage.TabIndex = 11;
|
||||
this.labelSpellCheckLanguage.Text = "Spell Check Language";
|
||||
//
|
||||
// comboBoxAppLocale
|
||||
// comboBoxSpellCheckLanguage
|
||||
//
|
||||
this.comboBoxAppLocale.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
||||
this.comboBoxAppLocale.FormattingEnabled = true;
|
||||
this.comboBoxAppLocale.Location = new System.Drawing.Point(5, 74);
|
||||
this.comboBoxAppLocale.Margin = new System.Windows.Forms.Padding(5, 3, 3, 3);
|
||||
this.comboBoxAppLocale.Name = "comboBoxAppLocale";
|
||||
this.comboBoxAppLocale.Size = new System.Drawing.Size(311, 21);
|
||||
this.comboBoxAppLocale.TabIndex = 9;
|
||||
this.comboBoxSpellCheckLanguage.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
||||
this.comboBoxSpellCheckLanguage.FormattingEnabled = true;
|
||||
this.comboBoxSpellCheckLanguage.Location = new System.Drawing.Point(5, 74);
|
||||
this.comboBoxSpellCheckLanguage.Margin = new System.Windows.Forms.Padding(5, 3, 3, 3);
|
||||
this.comboBoxSpellCheckLanguage.Name = "comboBoxSpellCheckLanguage";
|
||||
this.comboBoxSpellCheckLanguage.Size = new System.Drawing.Size(311, 21);
|
||||
this.comboBoxSpellCheckLanguage.TabIndex = 9;
|
||||
//
|
||||
// labelTranslations
|
||||
//
|
||||
@ -148,8 +148,8 @@ private void InitializeComponent() {
|
||||
private System.Windows.Forms.FlowLayoutPanel flowPanel;
|
||||
private System.Windows.Forms.ComboBox comboBoxTranslationTarget;
|
||||
private System.Windows.Forms.Label labelTranslationTarget;
|
||||
private System.Windows.Forms.ComboBox comboBoxAppLocale;
|
||||
private System.Windows.Forms.ComboBox comboBoxSpellCheckLanguage;
|
||||
private System.Windows.Forms.Label labelTranslations;
|
||||
private System.Windows.Forms.Label labelAppLanguage;
|
||||
private System.Windows.Forms.Label labelSpellCheckLanguage;
|
||||
}
|
||||
}
|
||||
|
@ -8,20 +8,20 @@ public TabSettingsLocales(){
|
||||
InitializeComponent();
|
||||
|
||||
toolTip.SetToolTip(checkSpellCheck, "Underlines words that are spelled incorrectly.");
|
||||
toolTip.SetToolTip(comboBoxAppLocale, "Language used for spell check and context menu items.");
|
||||
toolTip.SetToolTip(comboBoxSpellCheckLanguage, "Language used for spell check.");
|
||||
toolTip.SetToolTip(comboBoxTranslationTarget, "Language tweets are translated into.");
|
||||
|
||||
checkSpellCheck.Checked = Config.EnableSpellCheck;
|
||||
|
||||
try{
|
||||
foreach(LocaleUtils.Item item in LocaleUtils.ChromiumLocales){
|
||||
comboBoxAppLocale.Items.Add(item);
|
||||
foreach(LocaleUtils.Item item in LocaleUtils.SpellCheckLanguages){
|
||||
comboBoxSpellCheckLanguage.Items.Add(item);
|
||||
}
|
||||
}catch{
|
||||
comboBoxAppLocale.Items.Add(new LocaleUtils.Item("en-US"));
|
||||
comboBoxSpellCheckLanguage.Items.Add(new LocaleUtils.Item("en-US"));
|
||||
}
|
||||
|
||||
comboBoxAppLocale.SelectedItem = new LocaleUtils.Item(Config.AppLocale);
|
||||
comboBoxSpellCheckLanguage.SelectedItem = new LocaleUtils.Item(Config.SpellCheckLanguage);
|
||||
|
||||
foreach(LocaleUtils.Item item in LocaleUtils.TweetDeckTranslationLocales){
|
||||
comboBoxTranslationTarget.Items.Add(item);
|
||||
@ -32,7 +32,7 @@ public TabSettingsLocales(){
|
||||
|
||||
public override void OnReady(){
|
||||
checkSpellCheck.CheckedChanged += checkSpellCheck_CheckedChanged;
|
||||
comboBoxAppLocale.SelectedValueChanged += comboBoxAppLocale_SelectedValueChanged;
|
||||
comboBoxSpellCheckLanguage.SelectedValueChanged += comboBoxSpellCheckLanguage_SelectedValueChanged;
|
||||
comboBoxTranslationTarget.SelectedValueChanged += comboBoxTranslationTarget_SelectedValueChanged;
|
||||
}
|
||||
|
||||
@ -41,8 +41,8 @@ private void checkSpellCheck_CheckedChanged(object sender, EventArgs e){
|
||||
BrowserProcessHandler.UpdatePrefs();
|
||||
}
|
||||
|
||||
private void comboBoxAppLocale_SelectedValueChanged(object sender, EventArgs e){
|
||||
Config.AppLocale = (comboBoxAppLocale.SelectedItem as LocaleUtils.Item)?.Code;
|
||||
private void comboBoxSpellCheckLanguage_SelectedValueChanged(object sender, EventArgs e){
|
||||
Config.SpellCheckLanguage = (comboBoxSpellCheckLanguage.SelectedItem as LocaleUtils.Item)?.Code;
|
||||
PromptRestart();
|
||||
}
|
||||
|
||||
|
@ -10,19 +10,7 @@
|
||||
|
||||
namespace TweetDuck.Core.Utils{
|
||||
static class BrowserUtils{
|
||||
public static string HeaderAcceptLanguage{
|
||||
get{
|
||||
string culture = Program.UserConfig.AppLocale;
|
||||
|
||||
if (culture == "en"){
|
||||
return "en-us,en";
|
||||
}
|
||||
else{
|
||||
return culture.ToLower()+",en;q=0.9";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static string HeaderAcceptLanguage => "en-us,en";
|
||||
public static string HeaderUserAgent => Program.BrandName+" "+Application.ProductVersion;
|
||||
|
||||
public static void SetupCefArgs(IDictionary<string, string> args){
|
||||
|
@ -1,17 +1,23 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
namespace TweetDuck.Core.Utils{
|
||||
static class LocaleUtils{
|
||||
public static string LocaleFolder => Path.Combine(Program.ProgramPath, "locales");
|
||||
|
||||
public static IEnumerable<Item> ChromiumLocales => Directory
|
||||
.EnumerateFiles(LocaleFolder, "*.pak", SearchOption.TopDirectoryOnly)
|
||||
.Select(file => new Item(Path.GetFileNameWithoutExtension(file)))
|
||||
.OrderBy(code => code);
|
||||
// https://cs.chromium.org/chromium/src/third_party/hunspell_dictionaries/
|
||||
public static IEnumerable<Item> SpellCheckLanguages { get; } = new List<string>{
|
||||
"af-ZA", "bg-BG", "ca-ES", "cs-CZ", "da-DK", "de-DE",
|
||||
"el-GR", "en-AU", "en-CA", "en-GB", "en-US", "es-ES",
|
||||
"et-EE", "fa-IR", "fo-FO", "fr-FR", "he-IL", "hi-IN",
|
||||
"hr-HR", "hu-HU", "id-ID", "it-IT", "ko" , "lt-LT",
|
||||
"lv-LV", "nb-NO", "nl-NL", "pl-PL", "pt-BR", "pt-PT",
|
||||
"ro-RO", "ru-RU", "sk-SK", "sl-SI", "sq" , "sr",
|
||||
"sv-SE", "ta-IN", "tg-TG", "tr" , "uk-UA", "vi-VN"
|
||||
}.Select(code => {
|
||||
string lang = StringUtils.ExtractBefore(code, '-', 2);
|
||||
return lang == "en" || lang == "pt" ? new Item(code) : new Item(code, lang);
|
||||
}).OrderBy(code => code).ToList();
|
||||
|
||||
// TD.languages.getSupportedTranslationDestinationLanguages() except for "ht", "in", "iw" which are missing/duplicates
|
||||
public static IEnumerable<Item> TweetDeckTranslationLocales { get; } = new List<string>{
|
||||
@ -26,9 +32,9 @@ public sealed class Item : IComparable<Item>{
|
||||
public string Code { get; }
|
||||
public CultureInfo Info { get; }
|
||||
|
||||
public Item(string code){
|
||||
public Item(string code, string alt = null){
|
||||
this.Code = code;
|
||||
this.Info = CultureInfo.GetCultureInfo(code);
|
||||
this.Info = CultureInfo.GetCultureInfo(alt ?? code);
|
||||
}
|
||||
|
||||
public override bool Equals(object obj){
|
||||
|
@ -133,7 +133,6 @@ private static void Main(){
|
||||
CefSettings settings = new CefSettings{
|
||||
AcceptLanguageList = BrowserUtils.HeaderAcceptLanguage,
|
||||
UserAgent = BrowserUtils.HeaderUserAgent,
|
||||
Locale = UserConfig.AppLocale,
|
||||
BrowserSubprocessPath = BrandName+".Browser.exe",
|
||||
CachePath = StoragePath,
|
||||
LogFile = ConsoleLogFilePath,
|
||||
|
Loading…
Reference in New Issue
Block a user