Add translations for Program plugin.

This commit is contained in:
qianlifeng 2015-01-06 23:24:11 +08:00
parent ce9c832e00
commit 492e33aeda
14 changed files with 223 additions and 172 deletions

View File

@ -2,6 +2,22 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:system="clr-namespace:System;assembly=mscorlib"> xmlns:system="clr-namespace:System;assembly=mscorlib">
<system:String x:Key="wox_plugin_porgram_delete">Delete</system:String> <!--Program setting-->
<system:String x:Key="wox_plugin_program_delete">Delete</system:String>
<system:String x:Key="wox_plugin_program_edit">Edit</system:String>
<system:String x:Key="wox_plugin_program_add">Add</system:String>
<system:String x:Key="wox_plugin_program_location">Location</system:String>
<system:String x:Key="wox_plugin_program_suffixes">Index file suffixes</system:String>
<system:String x:Key="wox_plugin_program_reindex">Reindex</system:String>
<system:String x:Key="wox_plugin_program_indexing">Indexing</system:String>
<system:String x:Key="wox_plugin_program_pls_select_program_source">Please select a program source</system:String>
<system:String x:Key="wox_plugin_program_delete_program_source">Are your sure to delete {0}?</system:String>
<system:String x:Key="wox_plugin_program_update">Update</system:String>
<system:String x:Key="wox_plugin_program_only_index_tip">Wox will only index files that end with following suffixes:</system:String>
<system:String x:Key="wox_plugin_program_split_by_tip">(Each suffix should split by ;)</system:String>
<system:String x:Key="wox_plugin_program_update_file_suffixes">Sucessfully update file suffixes</system:String>
<system:String x:Key="wox_plugin_program_suffixes_cannot_empty">File suffixes can't be empty</system:String>
</ResourceDictionary> </ResourceDictionary>

View File

@ -0,0 +1,24 @@
<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">
<!--Program setting-->
<system:String x:Key="wox_plugin_program_delete">删除</system:String>
<system:String x:Key="wox_plugin_program_edit">编辑</system:String>
<system:String x:Key="wox_plugin_program_add">增加</system:String>
<system:String x:Key="wox_plugin_program_location">位置</system:String>
<system:String x:Key="wox_plugin_program_suffixes">索引文件后缀</system:String>
<system:String x:Key="wox_plugin_program_reindex">重新索引</system:String>
<system:String x:Key="wox_plugin_program_indexing">索引中</system:String>
<system:String x:Key="wox_plugin_program_pls_select_program_source">请先选择一项</system:String>
<system:String x:Key="wox_plugin_program_delete_program_source">你确定要删除{0}吗?</system:String>
<system:String x:Key="wox_plugin_program_update">更新</system:String>
<system:String x:Key="wox_plugin_program_only_index_tip">Wox仅索引下列后缀的文件</system:String>
<system:String x:Key="wox_plugin_program_split_by_tip">(每个后缀以英文状态下的分号分隔)</system:String>
<system:String x:Key="wox_plugin_program_update_file_suffixes">成功更新索引文件后缀</system:String>
<system:String x:Key="wox_plugin_program_suffixes_cannot_empty">文件后缀不能为空</system:String>
</ResourceDictionary>

View File

@ -3,14 +3,9 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:infrastructure="clr-namespace:Wox.Infrastructure;assembly=Wox.Infrastructure"
xmlns:program="clr-namespace:Wox.Plugin.Program" xmlns:program="clr-namespace:Wox.Plugin.Program"
mc:Ignorable="d" mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="600"> d:DesignHeight="300" d:DesignWidth="600">
<UserControl.Resources>
<BooleanToVisibilityConverter x:Key="BoolToVis" />
</UserControl.Resources>
<Grid Margin="10"> <Grid Margin="10">
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="50"/> <RowDefinition Height="50"/>
@ -18,13 +13,13 @@
<RowDefinition Height="50"/> <RowDefinition Height="50"/>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<StackPanel Grid.Row="0" Orientation="Horizontal" HorizontalAlignment="Right"> <StackPanel Grid.Row="0" Orientation="Horizontal" HorizontalAlignment="Right">
<Button Height="30" HorizontalAlignment="Right" x:Name="btnProgramSuffixes" Width="130" Click="BtnProgramSuffixes_OnClick">Index file suffixes</Button> <Button Height="30" HorizontalAlignment="Right" x:Name="btnProgramSuffixes" Width="130" Click="BtnProgramSuffixes_OnClick" Content="{DynamicResource wox_plugin_program_suffixes}"></Button>
<Button Height="30" HorizontalAlignment="Right" Margin="10 0 0 0" x:Name="btnReindex" Width="100" Click="btnReindex_Click">Re-Index</Button> <Button Height="30" HorizontalAlignment="Right" Margin="10 0 0 0" x:Name="btnReindex" Width="100" Click="btnReindex_Click" Content="{DynamicResource wox_plugin_program_reindex}"></Button>
</StackPanel> </StackPanel>
<ListView x:Name="programSourceView" Grid.Row="1"> <ListView x:Name="programSourceView" Grid.Row="1">
<ListView.View> <ListView.View>
<GridView> <GridView>
<GridViewColumn Header="Location" Width="400"> <GridViewColumn Header="{DynamicResource wox_plugin_program_location}" Width="400">
<GridViewColumn.CellTemplate> <GridViewColumn.CellTemplate>
<DataTemplate> <DataTemplate>
<TextBlock Text="{Binding Location, ConverterParameter=(null), Converter={program:StringEmptyConverter}}"/> <TextBlock Text="{Binding Location, ConverterParameter=(null), Converter={program:StringEmptyConverter}}"/>
@ -37,12 +32,12 @@
<DockPanel Grid.Row="2"> <DockPanel Grid.Row="2">
<StackPanel x:Name="indexingPanel" Visibility="Hidden" HorizontalAlignment="Left" Orientation="Horizontal"> <StackPanel x:Name="indexingPanel" Visibility="Hidden" HorizontalAlignment="Left" Orientation="Horizontal">
<ProgressBar x:Name="progressBarIndexing" Height="20" Width="80" Minimum="0" Maximum="100" IsIndeterminate="True"></ProgressBar> <ProgressBar x:Name="progressBarIndexing" Height="20" Width="80" Minimum="0" Maximum="100" IsIndeterminate="True"></ProgressBar>
<TextBlock Margin="10 0 0 0" Height="20" HorizontalAlignment="Center">Indexing</TextBlock> <TextBlock Margin="10 0 0 0" Height="20" HorizontalAlignment="Center" Text="{DynamicResource wox_plugin_program_indexing}"></TextBlock>
</StackPanel> </StackPanel>
<StackPanel HorizontalAlignment="Right" Orientation="Horizontal"> <StackPanel HorizontalAlignment="Right" Orientation="Horizontal">
<Button x:Name="btnDeleteProgramSource" Click="btnDeleteProgramSource_OnClick" Width="100" Margin="10" Content="{DynamicResource wox_plugin_porgram_delete}"/> <Button x:Name="btnDeleteProgramSource" Click="btnDeleteProgramSource_OnClick" Width="100" Margin="10" Content="{DynamicResource wox_plugin_program_delete}"/>
<Button x:Name="btnEditProgramSource" Click="btnEditProgramSource_OnClick" Width="100" Margin="10" Content="Edit"/> <Button x:Name="btnEditProgramSource" Click="btnEditProgramSource_OnClick" Width="100" Margin="10" Content="{DynamicResource wox_plugin_program_edit}"/>
<Button x:Name="btnAddProgramSource" Click="btnAddProgramSource_OnClick" Width="100" Margin="10" Content="Add"/> <Button x:Name="btnAddProgramSource" Click="btnAddProgramSource_OnClick" Width="100" Margin="10" Content="{DynamicResource wox_plugin_program_add}"/>
</StackPanel> </StackPanel>
</DockPanel> </DockPanel>
</Grid> </Grid>

View File

@ -10,8 +10,11 @@ namespace Wox.Plugin.Program
/// </summary> /// </summary>
public partial class ProgramSetting : UserControl public partial class ProgramSetting : UserControl
{ {
public ProgramSetting() private PluginInitContext context;
public ProgramSetting(PluginInitContext context)
{ {
this.context = context;
InitializeComponent(); InitializeComponent();
Loaded += Setting_Loaded; Loaded += Setting_Loaded;
} }
@ -55,8 +58,9 @@ namespace Wox.Plugin.Program
ProgramSource selectedProgramSource = programSourceView.SelectedItem as ProgramSource; ProgramSource selectedProgramSource = programSourceView.SelectedItem as ProgramSource;
if (selectedProgramSource != null) if (selectedProgramSource != null)
{ {
if (MessageBox.Show("Are your sure to delete " + selectedProgramSource.Location, "Delete ProgramSource", string msg = string.Format(context.API.GetTranslation("wox_plugin_program_delete_program_source"), selectedProgramSource.Location);
MessageBoxButton.YesNo) == MessageBoxResult.Yes)
if (MessageBox.Show(msg, string.Empty, MessageBoxButton.YesNo) == MessageBoxResult.Yes)
{ {
ProgramStorage.Instance.ProgramSources.Remove(selectedProgramSource); ProgramStorage.Instance.ProgramSources.Remove(selectedProgramSource);
ProgramStorage.Instance.Save(); ProgramStorage.Instance.Save();
@ -65,7 +69,8 @@ namespace Wox.Plugin.Program
} }
else else
{ {
MessageBox.Show("Please select a program source"); string msg = context.API.GetTranslation("wox_plugin_program_pls_select_program_source");
MessageBox.Show(msg);
} }
} }
@ -86,7 +91,8 @@ namespace Wox.Plugin.Program
} }
else else
{ {
MessageBox.Show("Please select a program source"); string msg = context.API.GetTranslation("wox_plugin_program_pls_select_program_source");
MessageBox.Show(msg);
} }
} }
@ -97,8 +103,7 @@ namespace Wox.Plugin.Program
private void BtnProgramSuffixes_OnClick(object sender, RoutedEventArgs e) private void BtnProgramSuffixes_OnClick(object sender, RoutedEventArgs e)
{ {
ProgramSuffixes p = new ProgramSuffixes(context);
ProgramSuffixes p = new ProgramSuffixes();
p.ShowDialog(); p.ShowDialog();
} }
} }

View File

@ -5,13 +5,13 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d" mc:Ignorable="d"
Width="400" Width="400"
Height="170" Height="180"
WindowStartupLocation="CenterScreen" WindowStartupLocation="CenterScreen"
d:DesignHeight="400" d:DesignWidth="300"> d:DesignHeight="400" d:DesignWidth="300">
<StackPanel> <StackPanel>
<TextBlock Margin="10 10 0 0" Foreground="Gray">Wox will only index files that end with following suffixes.</TextBlock> <TextBlock Margin="10 10 0 0" Foreground="Gray" Text="{DynamicResource wox_plugin_program_only_index_tip}"></TextBlock>
<TextBlock Margin="10 0 0 0" Foreground="Gray">Each suffix should split by ;</TextBlock> <TextBlock Margin="10 10 0 0" Foreground="Gray" Text="{DynamicResource wox_plugin_program_split_by_tip}"></TextBlock>
<TextBox x:Name="tbSuffixes" Margin="10"/> <TextBox x:Name="tbSuffixes" Margin="10"/>
<Button HorizontalAlignment="Right" Height="30" Width="80" Click="ButtonBase_OnClick" Margin="10">Update</Button> <Button HorizontalAlignment="Right" Height="30" Width="80" Click="ButtonBase_OnClick" Margin="10" Content="{DynamicResource wox_plugin_program_update}"></Button>
</StackPanel> </StackPanel>
</Window> </Window>

View File

@ -7,8 +7,11 @@ namespace Wox.Plugin.Program
/// </summary> /// </summary>
public partial class ProgramSuffixes public partial class ProgramSuffixes
{ {
public ProgramSuffixes() private PluginInitContext context;
public ProgramSuffixes(PluginInitContext context)
{ {
this.context = context;
InitializeComponent(); InitializeComponent();
tbSuffixes.Text = ProgramStorage.Instance.ProgramSuffixes; tbSuffixes.Text = ProgramStorage.Instance.ProgramSuffixes;
@ -18,12 +21,14 @@ namespace Wox.Plugin.Program
{ {
if (string.IsNullOrEmpty(tbSuffixes.Text)) if (string.IsNullOrEmpty(tbSuffixes.Text))
{ {
MessageBox.Show("File suffixes can't be empty"); string warning = context.API.GetTranslation("wox_plugin_program_suffixes_cannot_empty");
MessageBox.Show(warning);
return; return;
} }
ProgramStorage.Instance.ProgramSuffixes = tbSuffixes.Text; ProgramStorage.Instance.ProgramSuffixes = tbSuffixes.Text;
MessageBox.Show("Sucessfully update file suffixes"); string msg = context.API.GetTranslation("wox_plugin_program_update_file_suffixes");
MessageBox.Show(msg);
} }
} }
} }

View File

@ -178,7 +178,7 @@ namespace Wox.Plugin.Program
public System.Windows.Controls.Control CreateSettingPanel() public System.Windows.Controls.Control CreateSettingPanel()
{ {
return new ProgramSetting(); return new ProgramSetting(context);
} }
#endregion #endregion

View File

@ -88,6 +88,11 @@
</Content> </Content>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="Languages\zh-cn.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<Page Include="ProgramSetting.xaml"> <Page Include="ProgramSetting.xaml">
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType> <SubType>Designer</SubType>

View File

@ -12,8 +12,8 @@ namespace Wox.Core.UI
public static void ApplyResources() public static void ApplyResources()
{ {
Application.Current.Resources.MergedDictionaries.Clear(); Application.Current.Resources.MergedDictionaries.Clear();
ApplyUIResources();
ApplyPluginLanguages(); ApplyPluginLanguages();
ApplyUIResources();
} }
private static void ApplyUIResources() private static void ApplyUIResources()
@ -37,13 +37,17 @@ namespace Wox.Core.UI
.SelectMany(s => s.GetTypes()) .SelectMany(s => s.GetTypes())
.Where(p => p.IsClass && !p.IsAbstract && pluginI18nType.IsAssignableFrom(p)); .Where(p => p.IsClass && !p.IsAbstract && pluginI18nType.IsAssignableFrom(p));
foreach (IPluginI18n pluginI18n in pluginI18ns) foreach (var pluginI18n in pluginI18ns)
{ {
string languageFile = InternationalizationManager.Internationalization.GetLanguageFile(pluginI18n.GetLanguagesFolder()); string languageFile = InternationalizationManager.Internationalization.GetLanguageFile(
Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary ((IPluginI18n)Activator.CreateInstance(pluginI18n)).GetLanguagesFolder());
if (!string.IsNullOrEmpty(languageFile))
{ {
Source = new Uri(languageFile, UriKind.Absolute) Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary
}); {
Source = new Uri(languageFile, UriKind.Absolute)
});
}
} }
} }
} }

View File

@ -14,7 +14,7 @@ namespace Wox.Core.i18n
/// <summary> /// <summary>
/// Get language file for current user selected language /// Get language file for current user selected language
/// if couldn't find the current selected language file, it will first try to load en.xaml /// if couldn't find the current selected language file, it will first try to load en.xaml
/// if en.xaml couldn't find, it will pick up first *.xaml file /// if en.xaml couldn't find, return empty string
/// </summary> /// </summary>
/// <param name="folder"></param> /// <param name="folder"></param>
/// <returns></returns> /// <returns></returns>

View File

@ -137,16 +137,8 @@ namespace Wox.Core.i18n
{ {
return english; return english;
} }
else
{
string file = Directory.GetFiles(folder).FirstOrDefault(o => o.EndsWith("xaml"));
if (string.IsNullOrEmpty(file))
{
throw new WoxI18nException(string.Format("Couldn't find language file from:{0}, current selected language:{1}"));
}
return Path.Combine(folder, file); return string.Empty;
}
} }
} }

View File

@ -36,6 +36,8 @@ namespace Wox.Plugin
void ReloadPlugins(); void ReloadPlugins();
string GetTranslation(string key);
List<PluginPair> GetAllPlugins(); List<PluginPair> GetAllPlugins();
event WoxKeyDownEventHandler BackKeyDownEvent; event WoxKeyDownEventHandler BackKeyDownEvent;

View File

@ -132,6 +132,11 @@ namespace Wox
Dispatcher.Invoke(new Action(() => PluginManager.Init(this))); Dispatcher.Invoke(new Action(() => PluginManager.Init(this)));
} }
public string GetTranslation(string key)
{
return InternationalizationManager.Internationalization.GetTranslation(key);
}
public List<PluginPair> GetAllPlugins() public List<PluginPair> GetAllPlugins()
{ {
return PluginManager.AllPlugins; return PluginManager.AllPlugins;

View File

@ -482,7 +482,7 @@ namespace Wox
pluginTitle.Text = pair.Metadata.Name; pluginTitle.Text = pair.Metadata.Name;
pluginTitle.Cursor = Cursors.Hand; pluginTitle.Cursor = Cursors.Hand;
pluginActionKeyword.Text = pair.Metadata.ActionKeyword; pluginActionKeyword.Text = pair.Metadata.ActionKeyword;
pluginAuthor.Text = "By: " + pair.Metadata.Author; pluginAuthor.Text = InternationalizationManager.Internationalization.GetTranslation("author") + ": " + pair.Metadata.Author;
pluginSubTitle.Text = pair.Metadata.Description; pluginSubTitle.Text = pair.Metadata.Description;
pluginId = pair.Metadata.ID; pluginId = pair.Metadata.ID;
pluginIcon.Source = ImageLoader.ImageLoader.Load(pair.Metadata.FullIcoPath); pluginIcon.Source = ImageLoader.ImageLoader.Load(pair.Metadata.FullIcoPath);
@ -509,8 +509,6 @@ namespace Wox
control.Width = Double.NaN; control.Width = Double.NaN;
control.Height = Double.NaN; control.Height = Double.NaN;
} }
// featureControls
// throw new NotImplementedException();
} }
private void CbDisablePlugin_OnClick(object sender, RoutedEventArgs e) private void CbDisablePlugin_OnClick(object sender, RoutedEventArgs e)