Add i18n support [WIP]

This commit is contained in:
qianlifeng
2015-01-02 23:07:49 +08:00
parent bf87500e35
commit 203965043e
21 changed files with 257 additions and 124 deletions

View File

@@ -17,18 +17,18 @@
<ColumnDefinition Width="200"></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>
<TextBlock Margin="10" FontSize="14" Grid.Row="0" Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Right">Old ActionKeyword:</TextBlock>
<TextBlock Margin="10" FontSize="14" Grid.Row="0" Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Right" Text="{DynamicResource oldActionKeyword}"></TextBlock>
<TextBlock x:Name="tbOldActionKeyword" Margin="10" FontSize="14" Grid.Row="0" Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Left">Old ActionKeyword:</TextBlock>
<TextBlock Margin="10" FontSize="14" Grid.Row="1" Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Right">New ActionKeyword:</TextBlock>
<TextBlock Margin="10" FontSize="14" Grid.Row="1" Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Right" Text="{DynamicResource newActionKeyword}"></TextBlock>
<StackPanel Grid.Row="1" Orientation="Horizontal" Grid.Column="1" >
<TextBox x:Name="tbAction" Margin="10" Width="400" VerticalAlignment="Center" HorizontalAlignment="Left"></TextBox>
</StackPanel>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Grid.Row="2" Grid.Column="1">
<Button x:Name="btnCancel" Click="BtnCancel_OnClick" Margin="10 0 10 0" Width="80" Height="25">Cancel</Button>
<Button x:Name="btnCancel" Click="BtnCancel_OnClick" Margin="10 0 10 0" Width="80" Height="25" Content="{DynamicResource cancel}"></Button>
<Button x:Name="btnDone" Margin="10 0 10 0" Width="80" Height="25" Click="btnDone_OnClick">
<TextBlock x:Name="lblAdd">Done</TextBlock>
<TextBlock x:Name="lblAdd" Text="{DynamicResource done}"></TextBlock>
</Button>
</StackPanel>
</Grid>

View File

@@ -11,6 +11,7 @@ using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Wox.Core.i18n;
using Wox.Core.Plugin;
using Wox.Infrastructure.Storage.UserSettings;
using Wox.Plugin;
@@ -28,7 +29,7 @@ namespace Wox
PluginPair plugin = PluginManager.GetPlugin(pluginId);
if (plugin == null)
{
MessageBox.Show("Can't find specific plugin");
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("cannotFindSpecifiedPlugin"));
Close();
return;
}
@@ -51,14 +52,14 @@ namespace Wox
{
if (string.IsNullOrEmpty(tbAction.Text))
{
MessageBox.Show("New ActionKeyword can't be empty");
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("newActionKeywordCannotBeEmpty"));
return;
}
//check new action keyword didn't used by other plugin
if (PluginManager.AllPlugins.Exists(o => o.Metadata.ActionKeyword == tbAction.Text.Trim()))
{
MessageBox.Show("New ActionKeyword has been assigned to other plugin, please assign another new action keyword");
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("newActionKeywordHasBeenAssigned"));
return;
}
@@ -80,10 +81,8 @@ namespace Wox
customizedPluginConfig.Actionword = tbAction.Text.Trim();
}
UserSettingStorage.Instance.Save();
MessageBox.Show("Sucessfully applied the new action keyword");
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("succeed"));
Close();
}
}
}

View File

@@ -1,4 +1,4 @@
<Window x:Class="Wox.CustomPluginHotkeySetting"
<Window x:Class="Wox.CustomQueryHotkeySetting"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:wox="clr-namespace:Wox"
@@ -16,19 +16,19 @@
<ColumnDefinition Width="150"></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>
<TextBlock Margin="10" FontSize="14" Grid.Row="0" Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Right">Hotkey:</TextBlock>
<TextBlock Margin="10" FontSize="14" Grid.Row="0" Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Right" Text="{DynamicResource hotkey}"></TextBlock>
<wox:HotkeyControl x:Name="ctlHotkey" Margin="10" Grid.Column="1" />
<TextBlock Margin="10" FontSize="14" Grid.Row="1" Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Right">Action Keyword:</TextBlock>
<TextBlock Margin="10" FontSize="14" Grid.Row="1" Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Right" Text="{DynamicResource actionKeyword}"></TextBlock>
<StackPanel Grid.Row="1" Orientation="Horizontal" Grid.Column="1" >
<TextBox x:Name="tbAction" Margin="10" Width="400" VerticalAlignment="Center" HorizontalAlignment="Left"></TextBox>
<Button x:Name="btnTestActionKeyword" Padding="10 5 10 5" Height="30" Click="BtnTestActionKeyword_OnClick">Test</Button>
<Button x:Name="btnTestActionKeyword" Padding="10 5 10 5" Height="30" Click="BtnTestActionKeyword_OnClick" Content="{DynamicResource preview}"></Button>
</StackPanel>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Grid.Row="2" Grid.Column="1">
<Button x:Name="btnCancel" Click="BtnCancel_OnClick" Margin="10 0 10 0" Width="80" Height="25">Cancel</Button>
<Button x:Name="btnCancel" Click="BtnCancel_OnClick" Margin="10 0 10 0" Width="80" Height="25" Content="{DynamicResource cancel}"></Button>
<Button x:Name="btnAdd" Margin="10 0 10 0" Width="80" Height="25" Click="btnAdd_OnClick">
<TextBlock x:Name="lblAdd">Add</TextBlock>
<TextBlock x:Name="lblAdd" Text="{DynamicResource done}"></TextBlock>
</Button>
</StackPanel>
</Grid>

View File

@@ -1,17 +1,18 @@
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using Wox.Core.i18n;
using Wox.Infrastructure.Storage.UserSettings;
namespace Wox
{
public partial class CustomPluginHotkeySetting : Window
public partial class CustomQueryHotkeySetting : Window
{
private SettingWindow settingWidow;
private bool update;
private CustomPluginHotkey updateCustomHotkey;
public CustomPluginHotkeySetting(SettingWindow settingWidow)
public CustomQueryHotkeySetting(SettingWindow settingWidow)
{
this.settingWidow = settingWidow;
InitializeComponent();
@@ -28,7 +29,7 @@ namespace Wox
{
if (!ctlHotkey.CurrentHotkeyAvailable)
{
MessageBox.Show("Hotkey is unavailable, please select a new hotkey");
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("hotkeyIsNotUnavailable"));
return;
}
@@ -48,13 +49,13 @@ namespace Wox
settingWidow.MainWindow.ChangeQuery(pluginHotkey.ActionKeyword);
settingWidow.MainWindow.ShowApp();
});
MessageBox.Show("Add hotkey successfully!");
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("succeed"));
}
else
{
if (updateCustomHotkey.Hotkey != ctlHotkey.CurrentHotkey.ToString() && !ctlHotkey.CurrentHotkeyAvailable)
{
MessageBox.Show("Hotkey is unavailable, please select a new hotkey");
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("hotkeyIsNotUnavailable"));
return;
}
var oldHotkey = updateCustomHotkey.Hotkey;
@@ -67,7 +68,7 @@ namespace Wox
settingWidow.MainWindow.ShowApp();
settingWidow.MainWindow.ChangeQuery(updateCustomHotkey.ActionKeyword);
});
MessageBox.Show("Update successfully!");
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("succeed"));
}
UserSettingStorage.Instance.Save();
@@ -80,7 +81,7 @@ namespace Wox
updateCustomHotkey = UserSettingStorage.Instance.CustomPluginHotkeys.FirstOrDefault(o => o.ActionKeyword == item.ActionKeyword && o.Hotkey == item.Hotkey);
if (updateCustomHotkey == null)
{
MessageBox.Show("Invalid plugin hotkey");
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("invalidPluginHotkey"));
Close();
return;
}
@@ -88,7 +89,7 @@ namespace Wox
tbAction.Text = updateCustomHotkey.ActionKeyword;
ctlHotkey.SetHotkey(updateCustomHotkey.Hotkey, false);
update = true;
lblAdd.Text = "Update";
lblAdd.Text = InternationalizationManager.Instance.GetTranslation("update");
}
private void BtnTestActionKeyword_OnClick(object sender, RoutedEventArgs e)

View File

@@ -1,76 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Media;
using Wox.Helper;
namespace Wox.Helper
{
public static class FontHelper
{
static FontWeightConverter fontWeightConverter = new FontWeightConverter();
public static FontWeight GetFontWeightFromInvariantStringOrNormal(string value)
{
if (value == null) return FontWeights.Normal;
try
{
return (FontWeight) fontWeightConverter.ConvertFromInvariantString(value);
}
catch {
return FontWeights.Normal;
}
}
static FontStyleConverter fontStyleConverter = new FontStyleConverter();
public static FontStyle GetFontStyleFromInvariantStringOrNormal(string value)
{
if (value == null) return FontStyles.Normal;
try
{
return (FontStyle)fontStyleConverter.ConvertFromInvariantString(value);
}
catch
{
return FontStyles.Normal;
}
}
static FontStretchConverter fontStretchConverter = new FontStretchConverter();
public static FontStretch GetFontStretchFromInvariantStringOrNormal(string value)
{
if (value == null) return FontStretches.Normal;
try
{
return (FontStretch)fontStretchConverter.ConvertFromInvariantString(value);
}
catch
{
return FontStretches.Normal;
}
}
public static FamilyTypeface ChooseRegularFamilyTypeface(this FontFamily family)
{
return family.FamilyTypefaces.OrderBy(o =>
{
return Math.Abs(o.Stretch.ToOpenTypeStretch() - FontStretches.Normal.ToOpenTypeStretch()) * 100 +
Math.Abs(o.Weight.ToOpenTypeWeight() - FontWeights.Normal.ToOpenTypeWeight()) +
(o.Style == FontStyles.Normal ? 0 : o.Style == FontStyles.Oblique ? 1 : 2) * 1000;
}).FirstOrDefault() ?? family.FamilyTypefaces.FirstOrDefault();
}
public static FamilyTypeface ConvertFromInvariantStringsOrNormal(this FontFamily family, string style, string weight, string stretch)
{
var styleObj = GetFontStyleFromInvariantStringOrNormal(style);
var weightObj = GetFontWeightFromInvariantStringOrNormal(weight);
var stretchObj = GetFontStretchFromInvariantStringOrNormal(stretch);
return family.FamilyTypefaces.FirstOrDefault(o => o.Style == styleObj && o.Weight == weightObj && o.Stretch == stretchObj)
?? family.ChooseRegularFamilyTypeface();
}
}
}

View File

@@ -1,121 +0,0 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using Wox.Helper;
using Wox.Infrastructure.Logger;
using Wox.Infrastructure.Storage.UserSettings;
namespace Wox
{
public class LanguageManager
{
private static List<string> languageDirectories = new List<string>();
static LanguageManager()
{
languageDirectories.Add(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Languages"));
string userProfilePath = Environment.GetEnvironmentVariable("USERPROFILE");
if (userProfilePath != null)
{
languageDirectories.Add(Path.Combine(Path.Combine(userProfilePath, ".Wox"), "Languages"));
}
MakesureThemeDirectoriesExist();
}
private static void MakesureThemeDirectoriesExist()
{
foreach (string pluginDirectory in languageDirectories)
{
if (!Directory.Exists(pluginDirectory))
{
try
{
Directory.CreateDirectory(pluginDirectory);
}
catch (Exception e)
{
Log.Error(e.Message);
}
}
}
}
public static void ChangeLanguage(string name)
{
string path = GetLanguagePath(name);
if (string.IsNullOrEmpty(path))
{
path = GetLanguagePath("English");
if (string.IsNullOrEmpty(path))
{
throw new Exception("Change Language failed");
}
}
UserSettingStorage.Instance.Language = name;
UserSettingStorage.Instance.Save();
ResourceMerger.ApplyResources();
}
internal static ResourceDictionary GetResourceDictionary()
{
return new ResourceDictionary
{
Source = new Uri(GetLanguagePath(UserSettingStorage.Instance.Language), UriKind.Absolute)
};
}
public static List<string> LoadAvailableLanguages()
{
List<string> themes = new List<string>();
foreach (var directory in languageDirectories)
{
themes.AddRange(
Directory.GetFiles(directory)
.Where(filePath => filePath.EndsWith(".xaml"))
.Select(Path.GetFileNameWithoutExtension)
.ToList());
}
return themes;
}
public static string GetTranslation(string key)
{
try
{
object translation = Application.Current.FindResource(key);
if (translation == null)
{
return "NoTranslation";
}
return translation.ToString();
}
catch
{
return "NoTranslation";
}
}
private static string GetLanguagePath(string name)
{
foreach (string directory in languageDirectories)
{
string path = Path.Combine(directory, name + ".xaml");
if (File.Exists(path))
{
return path;
}
}
return string.Empty;
}
}
}

View File

@@ -1,21 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
namespace Wox.Helper
{
public class ResourceMerger
{
public static void ApplyResources()
{
var languageResource = LanguageManager.GetResourceDictionary();
var themeResource = ThemeManager.GetResourceDictionary();
Application.Current.Resources.MergedDictionaries.Clear();
Application.Current.Resources.MergedDictionaries.Add(languageResource);
Application.Current.Resources.MergedDictionaries.Add(themeResource);
}
}
}

View File

@@ -1,130 +0,0 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using Wox.Helper;
using Wox.Infrastructure.Logger;
using Wox.Infrastructure.Storage.UserSettings;
namespace Wox
{
internal class ThemeManager
{
private static List<string> themeDirectories = new List<string>();
static ThemeManager()
{
themeDirectories.Add(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Themes"));
string userProfilePath = Environment.GetEnvironmentVariable("USERPROFILE");
if (userProfilePath != null)
{
themeDirectories.Add(Path.Combine(Path.Combine(userProfilePath, ".Wox"), "Themes"));
}
MakesureThemeDirectoriesExist();
}
private static void MakesureThemeDirectoriesExist()
{
foreach (string pluginDirectory in themeDirectories)
{
if (!Directory.Exists(pluginDirectory))
{
try
{
Directory.CreateDirectory(pluginDirectory);
}
catch (Exception e)
{
Log.Error(e.Message);
}
}
}
}
public static void ChangeTheme(string themeName)
{
string themePath = GetThemePath(themeName);
if (string.IsNullOrEmpty(themePath))
{
themePath = GetThemePath("Dark");
if (string.IsNullOrEmpty(themePath))
{
throw new Exception("Change theme failed");
}
}
UserSettingStorage.Instance.Theme = themeName;
UserSettingStorage.Instance.Save();
ResourceMerger.ApplyResources();
}
internal static ResourceDictionary GetResourceDictionary()
{
var dict = new ResourceDictionary
{
Source = new Uri(GetThemePath(UserSettingStorage.Instance.Theme), UriKind.Absolute)
};
Style queryBoxStyle = dict["QueryBoxStyle"] as Style;
if (queryBoxStyle != null)
{
queryBoxStyle.Setters.Add(new Setter(TextBox.FontFamilyProperty, new FontFamily(UserSettingStorage.Instance.QueryBoxFont)));
queryBoxStyle.Setters.Add(new Setter(TextBox.FontStyleProperty, FontHelper.GetFontStyleFromInvariantStringOrNormal(UserSettingStorage.Instance.QueryBoxFontStyle)));
queryBoxStyle.Setters.Add(new Setter(TextBox.FontWeightProperty, FontHelper.GetFontWeightFromInvariantStringOrNormal(UserSettingStorage.Instance.QueryBoxFontWeight)));
queryBoxStyle.Setters.Add(new Setter(TextBox.FontStretchProperty, FontHelper.GetFontStretchFromInvariantStringOrNormal(UserSettingStorage.Instance.QueryBoxFontStretch)));
}
Style resultItemStyle = dict["ItemTitleStyle"] as Style;
Style resultSubItemStyle = dict["ItemSubTitleStyle"] as Style;
Style resultItemSelectedStyle = dict["ItemTitleSelectedStyle"] as Style;
Style resultSubItemSelectedStyle = dict["ItemSubTitleSelectedStyle"] as Style;
if (resultItemStyle != null && resultSubItemStyle != null && resultSubItemSelectedStyle != null && resultItemSelectedStyle != null)
{
Setter fontFamily = new Setter(TextBlock.FontFamilyProperty, new FontFamily(UserSettingStorage.Instance.ResultItemFont));
Setter fontStyle = new Setter(TextBlock.FontStyleProperty, FontHelper.GetFontStyleFromInvariantStringOrNormal(UserSettingStorage.Instance.ResultItemFontStyle));
Setter fontWeight = new Setter(TextBlock.FontWeightProperty, FontHelper.GetFontWeightFromInvariantStringOrNormal(UserSettingStorage.Instance.ResultItemFontWeight));
Setter fontStretch = new Setter(TextBlock.FontStretchProperty, FontHelper.GetFontStretchFromInvariantStringOrNormal(UserSettingStorage.Instance.ResultItemFontStretch));
Setter[] setters = new Setter[] { fontFamily, fontStyle, fontWeight, fontStretch };
Array.ForEach(new Style[] { resultItemStyle, resultSubItemStyle, resultItemSelectedStyle, resultSubItemSelectedStyle }, o => Array.ForEach(setters, p => o.Setters.Add(p)));
}
return dict;
}
public static List<string> LoadAvailableThemes()
{
List<string> themes = new List<string>();
foreach (var themeDirectory in themeDirectories)
{
themes.AddRange(
Directory.GetFiles(themeDirectory)
.Where(filePath => filePath.EndsWith(".xaml") && !filePath.EndsWith("Default.xaml"))
.ToList());
}
return themes;
}
private static string GetThemePath(string themeName)
{
foreach (string themeDirectory in themeDirectories)
{
string path = Path.Combine(themeDirectory, themeName + ".xaml");
if (File.Exists(path))
{
return path;
}
}
return string.Empty;
}
}
}

View File

@@ -6,6 +6,7 @@ using System.Windows.Input;
using System.Windows.Media;
using NHotkey;
using NHotkey.Wpf;
using Wox.Core.i18n;
using Wox.Helper;
using Wox.Infrastructure;
using Wox.Infrastructure.Hotkey;
@@ -98,12 +99,12 @@ namespace Wox
if (!CurrentHotkeyAvailable)
{
tbMsg.Foreground = new SolidColorBrush(Colors.Red);
tbMsg.Text = "hotkey unavailable";
tbMsg.Text = InternationalizationManager.Instance.GetTranslation("hotkeyUnavailable");
}
else
{
tbMsg.Foreground = new SolidColorBrush(Colors.Green);
tbMsg.Text = "succeed";
tbMsg.Text = InternationalizationManager.Instance.GetTranslation("succeed");
}
OnOnHotkeyChanged();
}

View File

@@ -1,6 +1,12 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:system="clr-namespace:System;assembly=mscorlib">
<!--MainWindow-->
<system:String x:Key="registerHotkeyFailed">Register hotkey: {0} failed</system:String>
<system:String x:Key="couldnotStartCmd">Could not start {0}</system:String>
<system:String x:Key="invalidWoxPluginFileFormat">Invalid wox plugin file format</system:String>
<!--Setting General-->
<system:String x:Key="general">General</system:String>
<system:String x:Key="startWoxOnSystemStartup">Start Wox on system startup</system:String>
@@ -49,11 +55,30 @@
<system:String x:Key="invalidPortFormat">Invalid port format</system:String>
<system:String x:Key="saveProxySuccessfully">Save proxy successfully</system:String>
<system:String x:Key="proxyIsCorrect">Proxy is correct</system:String>
<system:String x:Key="proxyConnectFailed">Proxy connect failed</system:String>
<!--Setting About-->
<system:String x:Key="about">About</system:String>
<system:String x:Key="website">Website</system:String>
<system:String x:Key="version">Version</system:String>
<!--Action Keyword Setting Dialog-->
<system:String x:Key="oldActionKeyword">Old Action Keyword</system:String>
<system:String x:Key="newActionKeyword">New Action Keyword</system:String>
<system:String x:Key="cancel">Cancel</system:String>
<system:String x:Key="done">Done</system:String>
<system:String x:Key="cannotFindSpecifiedPlugin">Can't find specified plugin</system:String>
<system:String x:Key="newActionKeywordCannotBeEmpty">New Action Keyword can't be empty</system:String>
<system:String x:Key="newActionKeywordHasBeenAssigned">New ActionKeyword has been assigned to other plugin, please assign another new action keyword</system:String>
<system:String x:Key="succeed">Succeed</system:String>
<!--Custom Query Hotkey Dialog-->
<system:String x:Key="preview">Preview</system:String>
<system:String x:Key="hotkeyIsNotUnavailable">Hotkey is unavailable, please select a new hotkey</system:String>
<system:String x:Key="invalidPluginHotkey">Invalid plugin hotkey</system:String>
<system:String x:Key="update">Update</system:String>
<!--Hotkey Control-->
<system:String x:Key="hotkeyUnavailable">Hotkey unavailable</system:String>
</ResourceDictionary>

View File

@@ -1,6 +1,12 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:system="clr-namespace:System;assembly=mscorlib">
<!--主窗体-->
<system:String x:Key="registerHotkeyFailed">注册热键:{0} 失败</system:String>
<system:String x:Key="couldnotStartCmd">启动命令 {0} 失败</system:String>
<system:String x:Key="invalidWoxPluginFileFormat">不是合法的Wox插件格式</system:String>
<!--设置,通用-->
<system:String x:Key="general">通用</system:String>
<system:String x:Key="startWoxOnSystemStartup">开机启动</system:String>
@@ -32,6 +38,8 @@
<system:String x:Key="delete">删除</system:String>
<system:String x:Key="edit">编辑</system:String>
<system:String x:Key="add">增加</system:String>
<system:String x:Key="pleaseSelectAnItem">请选择一项</system:String>
<system:String x:Key="deleteCustomHotkeyWarning">你确定要删除插件 {0} 的热键吗?</system:String>
<!--设置,代理-->
<system:String x:Key="proxy">代理</system:String>
@@ -42,10 +50,36 @@
<system:String x:Key="password">密码</system:String>
<system:String x:Key="testProxy">测试代理</system:String>
<system:String x:Key="save">保存</system:String>
<system:String x:Key="serverCantBeEmpty">服务器不能为空</system:String>
<system:String x:Key="portCantBeEmpty">端口不能为空</system:String>
<system:String x:Key="invalidPortFormat">非法的端口格式</system:String>
<system:String x:Key="saveProxySuccessfully">保存代理设置成功</system:String>
<system:String x:Key="proxyIsCorrect">代理设置正确</system:String>
<system:String x:Key="proxyConnectFailed">代理连接失败</system:String>
<!--设置,版本-->
<system:String x:Key="about">关于</system:String>
<system:String x:Key="website">网站</system:String>
<system:String x:Key="version">版本</system:String>
<!--Action Keyword 设置对话框-->
<system:String x:Key="oldActionKeyword">旧触发关键字</system:String>
<system:String x:Key="newActionKeyword">新触发关键字</system:String>
<system:String x:Key="cancel">取消</system:String>
<system:String x:Key="done">确定</system:String>
<system:String x:Key="cannotFindSpecifiedPlugin">找不到指定的插件</system:String>
<system:String x:Key="newActionKeywordCannotBeEmpty">新触发关键字不能为空</system:String>
<system:String x:Key="newActionKeywordHasBeenAssigned">新触发关键字已经被指派给其他插件了,请重新选择一个关键字</system:String>
<system:String x:Key="succeed">成功</system:String>
<!--Custom Query Hotkey 对话框-->
<system:String x:Key="preview">预览</system:String>
<system:String x:Key="hotkeyIsNotUnavailable">热键不可用,请选择一个新的热键</system:String>
<system:String x:Key="invalidPluginHotkey">插件热键不合法</system:String>
<system:String x:Key="update">更新</system:String>
<!--Hotkey 控件-->
<system:String x:Key="hotkeyUnavailable">热键不可用</system:String>
</ResourceDictionary>

View File

@@ -14,7 +14,9 @@ using WindowsInput;
using WindowsInput.Native;
using NHotkey;
using NHotkey.Wpf;
using Wox.Core.i18n;
using Wox.Core.Plugin;
using Wox.Core.Theme;
using Wox.Helper;
using Wox.Infrastructure;
using Wox.Infrastructure.Hotkey;
@@ -128,7 +130,7 @@ namespace Wox
public void ReloadPlugins()
{
Dispatcher.Invoke(new Action(()=> PluginManager.Init(this)));
Dispatcher.Invoke(new Action(() => PluginManager.Init(this)));
}
public List<PluginPair> GetAllPlugins()
@@ -173,8 +175,8 @@ namespace Wox
pnlResult.RightMouseClickEvent += pnlResult_RightMouseClickEvent;
ThreadPool.SetMaxThreads(30, 10);
ThemeManager.ChangeTheme(UserSettingStorage.Instance.Theme);
LanguageManager.ChangeLanguage(UserSettingStorage.Instance.Language);
ThemeManager.Instance.ChangeTheme(UserSettingStorage.Instance.Theme);
InternationalizationManager.Instance.ChangeLanguage(UserSettingStorage.Instance.Language);
SetHotkey(UserSettingStorage.Instance.Hotkey, OnHotkey);
SetCustomPluginHotkey();
@@ -266,7 +268,8 @@ namespace Wox
}
catch (Exception)
{
MessageBox.Show("Register hotkey: " + hotkeyStr + " failed.");
string errorMsg = string.Format(InternationalizationManager.Instance.GetTranslation("registerHotkeyFailed"), hotkeyStr);
MessageBox.Show(errorMsg);
}
}
@@ -557,7 +560,7 @@ namespace Wox
break;
case Key.F1:
Process.Start("https://github.com/qianlifeng/Wox/wiki/Wox-Function-Guide");
Process.Start("http://doc.getwox.com");
break;
case Key.Enter:
@@ -568,7 +571,7 @@ namespace Wox
}
else
{
SelectResult(activeResult);
SelectResult(activeResult);
}
e.Handled = true;
break;
@@ -590,7 +593,7 @@ namespace Wox
{
return pnlResult.GetActiveResult();
}
}
}
private void SelectPrevItem()
{
@@ -683,7 +686,8 @@ namespace Wox
}
catch (Exception ex)
{
ShowMsg("Could not start " + cmd, ex.Message, null);
string errorMsg = string.Format(InternationalizationManager.Instance.GetTranslation("couldnotStartCmd"), cmd);
ShowMsg(errorMsg, ex.Message, null);
}
return false;
}
@@ -700,7 +704,7 @@ namespace Wox
}
else
{
MessageBox.Show("incorrect wox plugin file.");
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("invalidWoxPluginFileFormat"));
}
}
}

View File

@@ -20,7 +20,7 @@
<converters:ImagePathConverter x:Key="ImageConverter" />
</Window.Resources>
<TabControl Height="auto" >
<TabItem Header="{DynamicResource general}" Height="23" VerticalAlignment="Top">
<TabItem Header="{DynamicResource general}">
<StackPanel Orientation="Vertical" Margin="10">
<CheckBox x:Name="cbStartWithWindows" Unchecked="CbStartWithWindows_OnUnchecked" Checked="CbStartWithWindows_OnChecked" Margin="10">
<TextBlock Text="{DynamicResource startWoxOnSystemStartup}" ></TextBlock>
@@ -33,7 +33,7 @@
</CheckBox>
<StackPanel Margin="10" Orientation="Horizontal">
<TextBlock Text="{DynamicResource language}"></TextBlock>
<ComboBox Margin="10 0 0 0" Width="200" x:Name="cbLanguages" />
<ComboBox Margin="10 0 0 0" Width="100" x:Name="cbLanguages" />
</StackPanel>
</StackPanel>
</TabItem>

View File

@@ -21,6 +21,8 @@ using Application = System.Windows.Forms.Application;
using File = System.IO.File;
using MessageBox = System.Windows.MessageBox;
using System.Windows.Data;
using Wox.Core.i18n;
using Wox.Core.Theme;
namespace Wox
{
@@ -150,7 +152,7 @@ namespace Wox
}
});
foreach (string theme in ThemeManager.LoadAvailableThemes())
foreach (string theme in ThemeManager.Instance.LoadAvailableThemes())
{
string themeName = System.IO.Path.GetFileNameWithoutExtension(theme);
themeComboBox.Items.Add(themeName);
@@ -174,7 +176,7 @@ namespace Wox
}
//PreviewPanel
ThemeManager.ChangeTheme(UserSettingStorage.Instance.Theme);
ThemeManager.Instance.ChangeTheme(UserSettingStorage.Instance.Theme);
#endregion
#region Plugin
@@ -244,7 +246,7 @@ namespace Wox
private void LoadLanguages()
{
cbLanguages.ItemsSource = LanguageManager.LoadAvailableLanguages();
cbLanguages.ItemsSource = InternationalizationManager.Instance.LoadAvailableLanguages();
cbLanguages.SelectedValue = UserSettingStorage.Instance.Language;
cbLanguages.SelectionChanged += cbLanguages_SelectionChanged;
}
@@ -252,7 +254,7 @@ namespace Wox
void cbLanguages_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
string language = cbLanguages.SelectedValue.ToString();
LanguageManager.ChangeLanguage(language);
InternationalizationManager.Instance.ChangeLanguage(language);
}
private void EnableProxy()
@@ -330,12 +332,12 @@ namespace Wox
CustomPluginHotkey item = lvCustomHotkey.SelectedItem as CustomPluginHotkey;
if (item == null)
{
MessageBox.Show(LanguageManager.GetTranslation("pleaseSelectAnItem"));
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("pleaseSelectAnItem"));
return;
}
string deleteWarning = string.Format(LanguageManager.GetTranslation("deleteCustomHotkeyWarning"), item.Hotkey);
if (MessageBox.Show(deleteWarning, LanguageManager.GetTranslation("delete"), MessageBoxButton.YesNo) == MessageBoxResult.Yes)
string deleteWarning = string.Format(InternationalizationManager.Instance.GetTranslation("deleteCustomHotkeyWarning"), item.Hotkey);
if (MessageBox.Show(deleteWarning, InternationalizationManager.Instance.GetTranslation("delete"), MessageBoxButton.YesNo) == MessageBoxResult.Yes)
{
UserSettingStorage.Instance.CustomPluginHotkeys.Remove(item);
lvCustomHotkey.Items.Refresh();
@@ -349,19 +351,19 @@ namespace Wox
CustomPluginHotkey item = lvCustomHotkey.SelectedItem as CustomPluginHotkey;
if (item != null)
{
CustomPluginHotkeySetting window = new CustomPluginHotkeySetting(this);
CustomQueryHotkeySetting window = new CustomQueryHotkeySetting(this);
window.UpdateItem(item);
window.ShowDialog();
}
else
{
MessageBox.Show(LanguageManager.GetTranslation("pleaseSelectAnItem"));
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("pleaseSelectAnItem"));
}
}
private void BtnAddCustomeHotkey_OnClick(object sender, RoutedEventArgs e)
{
new CustomPluginHotkeySetting(this).ShowDialog();
new CustomQueryHotkeySetting(this).ShowDialog();
}
public void ReloadCustomPluginHotkeyView()
@@ -375,7 +377,7 @@ namespace Wox
private void ThemeComboBox_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
{
string themeName = themeComboBox.SelectedItem.ToString();
ThemeManager.ChangeTheme(themeName);
ThemeManager.Instance.ChangeTheme(themeName);
UserSettingStorage.Instance.Theme = themeName;
UserSettingStorage.Instance.Save();
}
@@ -388,7 +390,7 @@ namespace Wox
this.cbQueryBoxFontFaces.SelectedItem = ((FontFamily)cbQueryBoxFont.SelectedItem).ChooseRegularFamilyTypeface();
UserSettingStorage.Instance.Save();
ThemeManager.ChangeTheme(UserSettingStorage.Instance.Theme);
ThemeManager.Instance.ChangeTheme(UserSettingStorage.Instance.Theme);
}
private void CbQueryBoxFontFaces_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
@@ -408,7 +410,7 @@ namespace Wox
UserSettingStorage.Instance.QueryBoxFontWeight = typeface.Weight.ToString();
UserSettingStorage.Instance.QueryBoxFontStyle = typeface.Style.ToString();
UserSettingStorage.Instance.Save();
ThemeManager.ChangeTheme(UserSettingStorage.Instance.Theme);
ThemeManager.Instance.ChangeTheme(UserSettingStorage.Instance.Theme);
}
}
@@ -420,7 +422,7 @@ namespace Wox
this.cbResultItemFontFaces.SelectedItem = ((FontFamily)cbResultItemFont.SelectedItem).ChooseRegularFamilyTypeface();
UserSettingStorage.Instance.Save();
ThemeManager.ChangeTheme(UserSettingStorage.Instance.Theme);
ThemeManager.Instance.ChangeTheme(UserSettingStorage.Instance.Theme);
}
private void CbResultItemFontFaces_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
@@ -438,21 +440,24 @@ namespace Wox
UserSettingStorage.Instance.ResultItemFontWeight = typeface.Weight.ToString();
UserSettingStorage.Instance.ResultItemFontStyle = typeface.Style.ToString();
UserSettingStorage.Instance.Save();
ThemeManager.ChangeTheme(UserSettingStorage.Instance.Theme);
ThemeManager.Instance.ChangeTheme(UserSettingStorage.Instance.Theme);
}
}
private void slOpacity_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
UserSettingStorage.Instance.Opacity = slOpacity.Value;
UserSettingStorage.Instance.Save();
if (UserSettingStorage.Instance.OpacityMode == OpacityMode.LayeredWindow)
PreviewMainPanel.Opacity = UserSettingStorage.Instance.Opacity;
else
PreviewMainPanel.Opacity = 1;
ThemeManager.ChangeTheme(UserSettingStorage.Instance.Theme);
ThemeManager.Instance.ChangeTheme(UserSettingStorage.Instance.Theme);
Dispatcher.DelayInvoke("delaySaveUserSetting", o =>
{
UserSettingStorage.Instance.Save();
}, TimeSpan.FromMilliseconds(1000));
}
#endregion
@@ -650,17 +655,17 @@ namespace Wox
{
if (string.IsNullOrEmpty(tbProxyServer.Text))
{
MessageBox.Show(LanguageManager.GetTranslation("serverCantBeEmpty"));
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("serverCantBeEmpty"));
return;
}
if (string.IsNullOrEmpty(tbProxyPort.Text))
{
MessageBox.Show(LanguageManager.GetTranslation("portCantBeEmpty"));
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("portCantBeEmpty"));
return;
}
if (!int.TryParse(tbProxyPort.Text, out port))
{
MessageBox.Show(LanguageManager.GetTranslation("invalidPortFormat"));
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("invalidPortFormat"));
return;
}
}
@@ -671,25 +676,25 @@ namespace Wox
UserSettingStorage.Instance.ProxyPassword = tbProxyPassword.Password;
UserSettingStorage.Instance.Save();
MessageBox.Show(LanguageManager.GetTranslation("saveProxySuccessfully"));
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("saveProxySuccessfully"));
}
private void btnTestProxy_Click(object sender, RoutedEventArgs e)
{
if (string.IsNullOrEmpty(tbProxyServer.Text))
{
MessageBox.Show(LanguageManager.GetTranslation("serverCantBeEmpty"));
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("serverCantBeEmpty"));
return;
}
if (string.IsNullOrEmpty(tbProxyPort.Text))
{
MessageBox.Show(LanguageManager.GetTranslation("portCantBeEmpty"));
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("portCantBeEmpty"));
return;
}
int port;
if (!int.TryParse(tbProxyPort.Text, out port))
{
MessageBox.Show(LanguageManager.GetTranslation("invalidPortFormat"));
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("invalidPortFormat"));
return;
}
@@ -710,16 +715,16 @@ namespace Wox
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
if (response.StatusCode == HttpStatusCode.OK)
{
MessageBox.Show(LanguageManager.GetTranslation("proxyIsCorrect"));
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("proxyIsCorrect"));
}
else
{
MessageBox.Show("Proxy connect failed.");
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("proxyConnectFailed"));
}
}
catch
{
MessageBox.Show("Proxy connect failed.");
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("proxyConnectFailed"));
}
}

View File

@@ -113,12 +113,9 @@
<Reference Include="WPFToolkit, Version=3.5.40128.1, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
</ItemGroup>
<ItemGroup>
<Compile Include="Helper\ResourceMerger.cs" />
<Compile Include="Helper\WoxLogPathConverter.cs" />
<Compile Include="ImageLoader\ImageCacheStroage.cs" />
<Compile Include="Helper\LanguageManager.cs" />
<Compile Include="Storage\UserSelectedRecordStorage.cs" />
<Compile Include="Helper\ThemeManager.cs" />
<Compile Include="Update\NewVersionWindow.xaml.cs">
<DependentUpon>NewVersionWindow.xaml</DependentUpon>
</Compile>
@@ -144,7 +141,6 @@
<Compile Include="Helper\ErrorReporting\WPFErrorReportingDialog.xaml.cs">
<DependentUpon>WPFErrorReportingDialog.xaml</DependentUpon>
</Compile>
<Compile Include="Helper\FontHelper.cs" />
<Compile Include="ImageLoader\ImageLoader.cs" />
<Compile Include="Helper\SingleInstance.cs" />
<Compile Include="Helper\SyntaxSugars.cs" />
@@ -152,8 +148,8 @@
<Compile Include="Helper\WindowIntelopHelper.cs" />
<Compile Include="Helper\WindowOpener.cs" />
<Compile Include="Converters\OpacityModeConverter.cs" />
<Compile Include="CustomPluginHotkeySetting.xaml.cs">
<DependentUpon>CustomPluginHotkeySetting.xaml</DependentUpon>
<Compile Include="CustomQueryHotkeySetting.xaml.cs">
<DependentUpon>CustomQueryHotkeySetting.xaml</DependentUpon>
</Compile>
<Compile Include="Helper\DispatcherExtensions.cs" />
<Compile Include="Helper\DWMDropShadow.cs" />
@@ -181,7 +177,7 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="CustomPluginHotkeySetting.xaml">
<Page Include="CustomQueryHotkeySetting.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>