mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-07 11:46:30 +02:00
Implement plugin i18n [WIP]
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
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>
|
||||||
|
|
||||||
</ResourceDictionary>
|
</ResourceDictionary>
|
||||||
@@ -40,7 +40,7 @@
|
|||||||
<TextBlock Margin="10 0 0 0" Height="20" HorizontalAlignment="Center">Indexing</TextBlock>
|
<TextBlock Margin="10 0 0 0" Height="20" HorizontalAlignment="Center">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="Delete"/>
|
<Button x:Name="btnDeleteProgramSource" Click="btnDeleteProgramSource_OnClick" Width="100" Margin="10" Content="{DynamicResource wox_plugin_porgram_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="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="Add"/>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
|
|||||||
@@ -1,14 +1,16 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
using System.Windows;
|
||||||
using Wox.Infrastructure;
|
using Wox.Infrastructure;
|
||||||
using Wox.Plugin.Program.ProgramSources;
|
using Wox.Plugin.Program.ProgramSources;
|
||||||
|
|
||||||
namespace Wox.Plugin.Program
|
namespace Wox.Plugin.Program
|
||||||
{
|
{
|
||||||
public class Programs : ISettingProvider,IPlugin
|
public class Programs : ISettingProvider, IPlugin, IPluginI18n
|
||||||
{
|
{
|
||||||
private static object lockObject = new object();
|
private static object lockObject = new object();
|
||||||
private static List<Program> programs = new List<Program>();
|
private static List<Program> programs = new List<Program>();
|
||||||
@@ -76,7 +78,7 @@ namespace Wox.Plugin.Program
|
|||||||
{
|
{
|
||||||
programs = ProgramCacheStorage.Instance.Programs;
|
programs = ProgramCacheStorage.Instance.Programs;
|
||||||
}
|
}
|
||||||
Debug.WriteLine(string.Format("Preload {0} programs from cache",programs.Count),"Wox");
|
Debug.WriteLine(string.Format("Preload {0} programs from cache", programs.Count), "Wox");
|
||||||
using (new Timeit("Program Index"))
|
using (new Timeit("Program Index"))
|
||||||
{
|
{
|
||||||
IndexPrograms();
|
IndexPrograms();
|
||||||
@@ -180,5 +182,10 @@ namespace Wox.Plugin.Program
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
public string GetLanguagesFolder()
|
||||||
|
{
|
||||||
|
return Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Languages");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,126 +1,126 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||||
<ProjectGuid>{FDB3555B-58EF-4AE6-B5F1-904719637AB4}</ProjectGuid>
|
<ProjectGuid>{FDB3555B-58EF-4AE6-B5F1-904719637AB4}</ProjectGuid>
|
||||||
<OutputType>Library</OutputType>
|
<OutputType>Library</OutputType>
|
||||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||||
<RootNamespace>Wox.Plugin.Program</RootNamespace>
|
<RootNamespace>Wox.Plugin.Program</RootNamespace>
|
||||||
<AssemblyName>Wox.Plugin.Program</AssemblyName>
|
<AssemblyName>Wox.Plugin.Program</AssemblyName>
|
||||||
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
|
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
|
||||||
<FileAlignment>512</FileAlignment>
|
<FileAlignment>512</FileAlignment>
|
||||||
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
|
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
|
||||||
<RestorePackages>true</RestorePackages>
|
<RestorePackages>true</RestorePackages>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||||
<DebugSymbols>true</DebugSymbols>
|
<DebugSymbols>true</DebugSymbols>
|
||||||
<DebugType>full</DebugType>
|
<DebugType>full</DebugType>
|
||||||
<Optimize>false</Optimize>
|
<Optimize>false</Optimize>
|
||||||
<OutputPath>..\..\Output\Debug\Plugins\Wox.Plugin.Program\</OutputPath>
|
<OutputPath>..\..\Output\Debug\Plugins\Wox.Plugin.Program\</OutputPath>
|
||||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||||
<ErrorReport>prompt</ErrorReport>
|
<ErrorReport>prompt</ErrorReport>
|
||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||||
<DebugType>pdbonly</DebugType>
|
<DebugType>pdbonly</DebugType>
|
||||||
<Optimize>true</Optimize>
|
<Optimize>true</Optimize>
|
||||||
<OutputPath>bin\Release\</OutputPath>
|
<OutputPath>bin\Release\</OutputPath>
|
||||||
<DefineConstants>TRACE</DefineConstants>
|
<DefineConstants>TRACE</DefineConstants>
|
||||||
<ErrorReport>prompt</ErrorReport>
|
<ErrorReport>prompt</ErrorReport>
|
||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="log4net">
|
<Reference Include="log4net">
|
||||||
<HintPath>..\..\packages\log4net.2.0.3\lib\net35-full\log4net.dll</HintPath>
|
<HintPath>..\..\packages\log4net.2.0.3\lib\net35-full\log4net.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||||
<SpecificVersion>False</SpecificVersion>
|
<SpecificVersion>False</SpecificVersion>
|
||||||
<HintPath>..\..\packages\Newtonsoft.Json.6.0.7\lib\net35\Newtonsoft.Json.dll</HintPath>
|
<HintPath>..\..\packages\Newtonsoft.Json.6.0.7\lib\net35\Newtonsoft.Json.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="PresentationCore" />
|
<Reference Include="PresentationCore" />
|
||||||
<Reference Include="PresentationFramework" />
|
<Reference Include="PresentationFramework" />
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
<Reference Include="System.Core" />
|
<Reference Include="System.Core" />
|
||||||
<Reference Include="System.Windows.Forms" />
|
<Reference Include="System.Windows.Forms" />
|
||||||
<Reference Include="System.Xml.Linq" />
|
<Reference Include="System.Xml.Linq" />
|
||||||
<Reference Include="System.Data.DataSetExtensions" />
|
<Reference Include="System.Data.DataSetExtensions" />
|
||||||
<Reference Include="System.Data" />
|
<Reference Include="System.Data" />
|
||||||
<Reference Include="System.Xml" />
|
<Reference Include="System.Xml" />
|
||||||
<Reference Include="WindowsBase" />
|
<Reference Include="WindowsBase" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="FileChangeWatcher.cs" />
|
<Compile Include="FileChangeWatcher.cs" />
|
||||||
<Compile Include="IProgramSource.cs" />
|
<Compile Include="IProgramSource.cs" />
|
||||||
<Compile Include="Program.cs" />
|
<Compile Include="Program.cs" />
|
||||||
<Compile Include="ProgramCacheStorage.cs" />
|
<Compile Include="ProgramCacheStorage.cs" />
|
||||||
<Compile Include="Programs.cs" />
|
<Compile Include="Programs.cs" />
|
||||||
<Compile Include="ProgramSetting.xaml.cs">
|
<Compile Include="ProgramSetting.xaml.cs">
|
||||||
<DependentUpon>ProgramSetting.xaml</DependentUpon>
|
<DependentUpon>ProgramSetting.xaml</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="ProgramSource.cs" />
|
<Compile Include="ProgramSource.cs" />
|
||||||
<Compile Include="ProgramSources\AppPathsProgramSource.cs" />
|
<Compile Include="ProgramSources\AppPathsProgramSource.cs" />
|
||||||
<Compile Include="ProgramSources\CommonStartMenuProgramSource.cs" />
|
<Compile Include="ProgramSources\CommonStartMenuProgramSource.cs" />
|
||||||
<Compile Include="ProgramSources\FileSystemProgramSource.cs" />
|
<Compile Include="ProgramSources\FileSystemProgramSource.cs" />
|
||||||
<Compile Include="ProgramSources\UserStartMenuProgramSource.cs" />
|
<Compile Include="ProgramSources\UserStartMenuProgramSource.cs" />
|
||||||
<Compile Include="ProgramStorage.cs" />
|
<Compile Include="ProgramStorage.cs" />
|
||||||
<Compile Include="ProgramSuffixes.xaml.cs">
|
<Compile Include="ProgramSuffixes.xaml.cs">
|
||||||
<DependentUpon>ProgramSuffixes.xaml</DependentUpon>
|
<DependentUpon>ProgramSuffixes.xaml</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="StringEmptyConverter.cs" />
|
<Compile Include="StringEmptyConverter.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="packages.config" />
|
<None Include="packages.config" />
|
||||||
<None Include="plugin.json">
|
<None Include="plugin.json">
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
</None>
|
</None>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="Images\program.png">
|
<None Include="Images\program.png">
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
</None>
|
</None>
|
||||||
<Content Include="Languages\en.xaml">
|
<Content Include="Languages\en.xaml">
|
||||||
<Generator>MSBuild:Compile</Generator>
|
<Generator>MSBuild:Compile</Generator>
|
||||||
<SubType>Designer</SubType>
|
<SubType>Designer</SubType>
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
</Content>
|
</Content>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Page Include="ProgramSetting.xaml">
|
<Page Include="ProgramSetting.xaml">
|
||||||
<Generator>MSBuild:Compile</Generator>
|
<Generator>MSBuild:Compile</Generator>
|
||||||
<SubType>Designer</SubType>
|
<SubType>Designer</SubType>
|
||||||
</Page>
|
</Page>
|
||||||
<Page Include="ProgramSuffixes.xaml">
|
<Page Include="ProgramSuffixes.xaml">
|
||||||
<Generator>MSBuild:Compile</Generator>
|
<Generator>MSBuild:Compile</Generator>
|
||||||
<SubType>Designer</SubType>
|
<SubType>Designer</SubType>
|
||||||
</Page>
|
</Page>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\..\Wox.Infrastructure\Wox.Infrastructure.csproj">
|
<ProjectReference Include="..\..\Wox.Infrastructure\Wox.Infrastructure.csproj">
|
||||||
<Project>{4fd29318-a8ab-4d8f-aa47-60bc241b8da3}</Project>
|
<Project>{4fd29318-a8ab-4d8f-aa47-60bc241b8da3}</Project>
|
||||||
<Name>Wox.Infrastructure</Name>
|
<Name>Wox.Infrastructure</Name>
|
||||||
</ProjectReference>
|
</ProjectReference>
|
||||||
<ProjectReference Include="..\..\Wox.Plugin\Wox.Plugin.csproj">
|
<ProjectReference Include="..\..\Wox.Plugin\Wox.Plugin.csproj">
|
||||||
<Project>{8451ecdd-2ea4-4966-bb0a-7bbc40138e80}</Project>
|
<Project>{8451ecdd-2ea4-4966-bb0a-7bbc40138e80}</Project>
|
||||||
<Name>Wox.Plugin</Name>
|
<Name>Wox.Plugin</Name>
|
||||||
</ProjectReference>
|
</ProjectReference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup />
|
<ItemGroup />
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
|
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
|
||||||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<ErrorText>这台计算机上缺少此项目引用的 NuGet 程序包。启用“NuGet 程序包还原”可下载这些程序包。有关详细信息,请参阅 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。</ErrorText>
|
<ErrorText>这台计算机上缺少此项目引用的 NuGet 程序包。启用“NuGet 程序包还原”可下载这些程序包。有关详细信息,请参阅 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。</ErrorText>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
|
<Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
|
||||||
</Target>
|
</Target>
|
||||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||||
Other similar extension points exist, see Microsoft.Common.targets.
|
Other similar extension points exist, see Microsoft.Common.targets.
|
||||||
<Target Name="BeforeBuild">
|
<Target Name="BeforeBuild">
|
||||||
</Target>
|
</Target>
|
||||||
<Target Name="AfterBuild">
|
<Target Name="AfterBuild">
|
||||||
</Target>
|
</Target>
|
||||||
-->
|
-->
|
||||||
</Project>
|
</Project>
|
||||||
@@ -3,13 +3,14 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
|
using Wox.Core.i18n;
|
||||||
|
|
||||||
namespace Wox.Core.UI
|
namespace Wox.Core.UI
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Object implement this interface will have the ability to has its own UI styles
|
/// Object implement this interface will have the ability to has its own UI styles
|
||||||
/// </summary>
|
/// </summary>
|
||||||
interface IUIResource
|
public interface IUIResource
|
||||||
{
|
{
|
||||||
ResourceDictionary GetResourceDictionary();
|
ResourceDictionary GetResourceDictionary();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,25 +3,48 @@ using System.Linq;
|
|||||||
using System.Windows;
|
using System.Windows;
|
||||||
using Wox.Core.i18n;
|
using Wox.Core.i18n;
|
||||||
using Wox.Core.Theme;
|
using Wox.Core.Theme;
|
||||||
|
using Wox.Plugin;
|
||||||
|
|
||||||
namespace Wox.Core.UI
|
namespace Wox.Core.UI
|
||||||
{
|
{
|
||||||
public class ResourceMerger
|
public class ResourceMerger
|
||||||
{
|
{
|
||||||
public static void ApplyResources()
|
public static void ApplyResources()
|
||||||
|
{
|
||||||
|
Application.Current.Resources.MergedDictionaries.Clear();
|
||||||
|
ApplyUIResources();
|
||||||
|
ApplyPluginLanguages();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void ApplyUIResources()
|
||||||
{
|
{
|
||||||
var UIResourceType = typeof(IUIResource);
|
var UIResourceType = typeof(IUIResource);
|
||||||
var UIResources = AppDomain.CurrentDomain.GetAssemblies()
|
var UIResources = AppDomain.CurrentDomain.GetAssemblies()
|
||||||
.SelectMany(s => s.GetTypes())
|
.SelectMany(s => s.GetTypes())
|
||||||
.Where(p => p.IsClass && !p.IsAbstract && UIResourceType.IsAssignableFrom(p));
|
.Where(p => p.IsClass && !p.IsAbstract && UIResourceType.IsAssignableFrom(p));
|
||||||
|
|
||||||
Application.Current.Resources.MergedDictionaries.Clear();
|
|
||||||
|
|
||||||
foreach (var uiResource in UIResources)
|
foreach (var uiResource in UIResources)
|
||||||
{
|
{
|
||||||
Application.Current.Resources.MergedDictionaries.Add(
|
Application.Current.Resources.MergedDictionaries.Add(
|
||||||
((IUIResource)Activator.CreateInstance(uiResource)).GetResourceDictionary());
|
((IUIResource)Activator.CreateInstance(uiResource)).GetResourceDictionary());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void ApplyPluginLanguages()
|
||||||
|
{
|
||||||
|
var pluginI18nType = typeof(IPluginI18n);
|
||||||
|
var pluginI18ns = AppDomain.CurrentDomain.GetAssemblies()
|
||||||
|
.SelectMany(s => s.GetTypes())
|
||||||
|
.Where(p => p.IsClass && !p.IsAbstract && pluginI18nType.IsAssignableFrom(p));
|
||||||
|
|
||||||
|
foreach (IPluginI18n pluginI18n in pluginI18ns)
|
||||||
|
{
|
||||||
|
string languageFile = InternationalizationManager.Internationalization.GetLanguageFile(pluginI18n.GetLanguagesFolder());
|
||||||
|
Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary
|
||||||
|
{
|
||||||
|
Source = new Uri(languageFile, UriKind.Absolute)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -11,6 +11,15 @@ namespace Wox.Core.i18n
|
|||||||
|
|
||||||
string GetTranslation(string key);
|
string GetTranslation(string key);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 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 en.xaml couldn't find, it will pick up first *.xaml file
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="folder"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
string GetLanguageFile(string folder);
|
||||||
|
|
||||||
void ChangeLanguage(Language language);
|
void ChangeLanguage(Language language);
|
||||||
|
|
||||||
void ChangeLanguage(string languageCode);
|
void ChangeLanguage(string languageCode);
|
||||||
|
|||||||
@@ -14,28 +14,24 @@ namespace Wox.Core.i18n
|
|||||||
{
|
{
|
||||||
public class Internationalization : IInternationalization, IUIResource
|
public class Internationalization : IInternationalization, IUIResource
|
||||||
{
|
{
|
||||||
private static List<string> languageDirectories = new List<string>();
|
private static string DefaultLanguageDirectory = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Languages");
|
||||||
|
|
||||||
static Internationalization()
|
static Internationalization()
|
||||||
{
|
{
|
||||||
languageDirectories.Add(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Languages"));
|
|
||||||
MakesureThemeDirectoriesExist();
|
MakesureThemeDirectoriesExist();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void MakesureThemeDirectoriesExist()
|
private static void MakesureThemeDirectoriesExist()
|
||||||
{
|
{
|
||||||
foreach (string pluginDirectory in languageDirectories)
|
if (!Directory.Exists(DefaultLanguageDirectory))
|
||||||
{
|
{
|
||||||
if (!Directory.Exists(pluginDirectory))
|
try
|
||||||
{
|
{
|
||||||
try
|
Directory.CreateDirectory(DefaultLanguageDirectory);
|
||||||
{
|
}
|
||||||
Directory.CreateDirectory(pluginDirectory);
|
catch (System.Exception e)
|
||||||
}
|
{
|
||||||
catch (System.Exception e)
|
Log.Error(e.Message);
|
||||||
{
|
|
||||||
Log.Error(e.Message);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -59,7 +55,7 @@ namespace Wox.Core.i18n
|
|||||||
|
|
||||||
public void ChangeLanguage(Language language)
|
public void ChangeLanguage(Language language)
|
||||||
{
|
{
|
||||||
if(language == null) throw new WoxI18nException("language can't be null");
|
if (language == null) throw new WoxI18nException("language can't be null");
|
||||||
|
|
||||||
string path = GetLanguagePath(language);
|
string path = GetLanguagePath(language);
|
||||||
if (string.IsNullOrEmpty(path))
|
if (string.IsNullOrEmpty(path))
|
||||||
@@ -80,7 +76,7 @@ namespace Wox.Core.i18n
|
|||||||
{
|
{
|
||||||
return new ResourceDictionary
|
return new ResourceDictionary
|
||||||
{
|
{
|
||||||
Source = new Uri(GetLanguagePath(UserSettingStorage.Instance.Language), UriKind.Absolute)
|
Source = new Uri(GetLanguageFile(DefaultLanguageDirectory), UriKind.Absolute)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -115,16 +111,44 @@ namespace Wox.Core.i18n
|
|||||||
|
|
||||||
private string GetLanguagePath(Language language)
|
private string GetLanguagePath(Language language)
|
||||||
{
|
{
|
||||||
foreach (string directory in languageDirectories)
|
string path = Path.Combine(DefaultLanguageDirectory, language.LanguageCode + ".xaml");
|
||||||
|
if (File.Exists(path))
|
||||||
{
|
{
|
||||||
string path = Path.Combine(directory, language.LanguageCode + ".xaml");
|
return path;
|
||||||
if (File.Exists(path))
|
|
||||||
{
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return string.Empty;
|
return string.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public string GetLanguageFile(string folder)
|
||||||
|
{
|
||||||
|
if (!Directory.Exists(folder)) return string.Empty;
|
||||||
|
|
||||||
|
string path = Path.Combine(folder, UserSettingStorage.Instance.Language + ".xaml");
|
||||||
|
if (File.Exists(path))
|
||||||
|
{
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
string english = Path.Combine(folder, "en.xaml");
|
||||||
|
if (File.Exists(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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,19 +31,26 @@ namespace Wox.Infrastructure.Storage
|
|||||||
{
|
{
|
||||||
using (FileStream fileStream = new FileStream(ConfigPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
|
using (FileStream fileStream = new FileStream(ConfigPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
|
||||||
{
|
{
|
||||||
BinaryFormatter binaryFormatter = new BinaryFormatter
|
if (fileStream.Length > 0)
|
||||||
{
|
{
|
||||||
AssemblyFormat = FormatterAssemblyStyle.Simple
|
BinaryFormatter binaryFormatter = new BinaryFormatter
|
||||||
};
|
{
|
||||||
serializedObject = binaryFormatter.Deserialize(fileStream) as T;
|
AssemblyFormat = FormatterAssemblyStyle.Simple
|
||||||
if (serializedObject == null)
|
};
|
||||||
|
serializedObject = binaryFormatter.Deserialize(fileStream) as T;
|
||||||
|
if (serializedObject == null)
|
||||||
|
{
|
||||||
|
serializedObject = LoadDefault();
|
||||||
|
#if (DEBUG)
|
||||||
|
{
|
||||||
|
throw new Exception("deserialize failed");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
serializedObject = LoadDefault();
|
serializedObject = LoadDefault();
|
||||||
#if (DEBUG)
|
|
||||||
{
|
|
||||||
throw new Exception("deserialize failed");
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
16
Wox.Plugin/IPluginI18n.cs
Normal file
16
Wox.Plugin/IPluginI18n.cs
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace Wox.Plugin
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Represent plugins that support internationalization
|
||||||
|
/// </summary>
|
||||||
|
public interface IPluginI18n
|
||||||
|
{
|
||||||
|
string GetLanguagesFolder();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -47,6 +47,7 @@
|
|||||||
<Compile Include="AllowedLanguage.cs" />
|
<Compile Include="AllowedLanguage.cs" />
|
||||||
<Compile Include="EventHandler.cs" />
|
<Compile Include="EventHandler.cs" />
|
||||||
<Compile Include="IHttpProxy.cs" />
|
<Compile Include="IHttpProxy.cs" />
|
||||||
|
<Compile Include="IPluginI18n.cs" />
|
||||||
<Compile Include="IPlugin.cs" />
|
<Compile Include="IPlugin.cs" />
|
||||||
<Compile Include="IPublicAPI.cs" />
|
<Compile Include="IPublicAPI.cs" />
|
||||||
<Compile Include="ISettingProvider.cs" />
|
<Compile Include="ISettingProvider.cs" />
|
||||||
|
|||||||
Reference in New Issue
Block a user