Skip to content

Commit

Permalink
Find out a better way for localization
Browse files Browse the repository at this point in the history
  • Loading branch information
heku committed Mar 30, 2018
1 parent 5aba78b commit 78ab9c1
Show file tree
Hide file tree
Showing 12 changed files with 132 additions and 79 deletions.
2 changes: 1 addition & 1 deletion Kool.EditProject/Commands/EditProjectCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ protected override void OnBeforeQueryStatus()
_projectFile = project.FullName;
var fileName = Path.GetFileName(_projectFile);
Visible = true;
Text = string.Format(Resources.EditMenuPattern, fileName);
Text = string.Format(VSPackage.EditMenuPattern, fileName);
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<CommandTable xmlns="http://schemas.microsoft.com/VisualStudio/2005-10-18/CommandTable" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<CommandTable xmlns="http://schemas.microsoft.com/VisualStudio/2005-10-18/CommandTable" xmlns:xs="http://www.w3.org/2001/XMLSchema" language="en">

<Extern href="stdidcmd.h" />
<Extern href="vsshlids.h" />

<!--https://docs.microsoft.com/en-us/visualstudio/extensibility/image-service-and-catalog#how-do-i-use-image-monikers-in-a-vsct-file-->
<Include href="KnownImageIds.vsct" />
<Include href="EditProjectPackage.vsct" />

<Commands package="guidPackage">
<Groups>
<Group guid="guidCmdSet" id="EDIT_PROJECT_GROUP_ID" priority="0x017F">
<Parent guid="guidSHLMainMenu" id="IDM_VS_CTXT_PROJNODE" />
</Group>
<Group guid="guidCmdSet" id="EDIT_PROJECTS_GROUP_ID" priority="0x017F">
<Parent guid="guidSHLMainMenu" id="IDM_VS_CTXT_XPROJ_MULTIPROJ" />
</Group>
</Groups>

<Buttons>
<Button guid="guidCmdSet" id="EDIT_PROJECT_CMD_ID" priority="0x0100" type="Button">
<!--Visual Studio 2015 doesn't have such menu, we have to define a new Group-->
Expand All @@ -43,17 +30,4 @@
</Button>
</Buttons>
</Commands>

<Symbols>
<!-- This is the package guid. -->
<GuidSymbol name="guidPackage" value="{08a2610d-b354-402c-99a8-9c2113e89ad8}" />

<!-- This is the guid used to group the menu commands together -->
<GuidSymbol name="guidCmdSet" value="{6c7e3ed8-7da3-456d-802f-e11c4f8f8438}">
<IDSymbol name="EDIT_PROJECT_CMD_ID" value="0x0100" />
<IDSymbol name="EDIT_PROJECTS_CMD_ID" value="0x0110" />
<IDSymbol name="EDIT_PROJECT_GROUP_ID" value="0x1000" />
<IDSymbol name="EDIT_PROJECTS_GROUP_ID" value="0x1100" />
</GuidSymbol>
</Symbols>
</CommandTable>
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,6 @@
<Parent guid="guidSHLMainMenu" id="IDM_VS_CTXT_XPROJ_MULTIPROJ" />
</Group>
</Groups>

<Buttons>
<Button guid="guidCmdSet" id="EDIT_PROJECT_CMD_ID" priority="0x0100" type="Button">
<!--Visual Studio 2015 doesn't have such menu, we have to define a new Group-->
<!--<Parent guid="guidSHLMainMenu" id="IDG_VS_CTXT_PROJECT_EDITFILE" />-->
<Parent guid="guidCmdSet" id="EDIT_PROJECT_GROUP_ID" />
<Icon guid="ImageCatalogGuid" id="Open" />
<CommandFlag>DynamicVisibility</CommandFlag>
<CommandFlag>DefaultInvisible</CommandFlag>
<CommandFlag>TextChanges</CommandFlag>
<CommandFlag>IconAndText</CommandFlag>
<CommandFlag>IconIsMoniker</CommandFlag>
<Strings>
<ButtonText>编辑...</ButtonText>
</Strings>
</Button>
<Button guid="guidCmdSet" id="EDIT_PROJECTS_CMD_ID" priority="0x0100" type="Button">
<Parent guid="guidCmdSet" id="EDIT_PROJECTS_GROUP_ID" />
<Icon guid="ImageCatalogGuid" id="Open" />
<CommandFlag>IconAndText</CommandFlag>
<CommandFlag>IconIsMoniker</CommandFlag>
<Strings>
<ButtonText>编辑项目文件</ButtonText>
</Strings>
</Button>
</Buttons>
</Commands>

<Symbols>
Expand Down
33 changes: 33 additions & 0 deletions Kool.EditProject/EditProjectPackage.zh-Hans.vsct
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<CommandTable xmlns="http://schemas.microsoft.com/VisualStudio/2005-10-18/CommandTable" xmlns:xs="http://www.w3.org/2001/XMLSchema" language="zh-hans">

<Include href="EditProjectPackage.vsct" />

<Commands package="guidPackage">
<Buttons>
<Button guid="guidCmdSet" id="EDIT_PROJECT_CMD_ID" priority="0x0100" type="Button">
<!--Visual Studio 2015 doesn't have such menu, we have to define a new Group-->
<!--<Parent guid="guidSHLMainMenu" id="IDG_VS_CTXT_PROJECT_EDITFILE" />-->
<Parent guid="guidCmdSet" id="EDIT_PROJECT_GROUP_ID" />
<Icon guid="ImageCatalogGuid" id="Open" />
<CommandFlag>DynamicVisibility</CommandFlag>
<CommandFlag>DefaultInvisible</CommandFlag>
<CommandFlag>TextChanges</CommandFlag>
<CommandFlag>IconAndText</CommandFlag>
<CommandFlag>IconIsMoniker</CommandFlag>
<Strings>
<ButtonText>编辑...</ButtonText>
</Strings>
</Button>
<Button guid="guidCmdSet" id="EDIT_PROJECTS_CMD_ID" priority="0x0100" type="Button">
<Parent guid="guidCmdSet" id="EDIT_PROJECTS_GROUP_ID" />
<Icon guid="ImageCatalogGuid" id="Open" />
<CommandFlag>IconAndText</CommandFlag>
<CommandFlag>IconIsMoniker</CommandFlag>
<Strings>
<ButtonText>编辑项目文件</ButtonText>
</Strings>
</Button>
</Buttons>
</Commands>
</CommandTable>
28 changes: 18 additions & 10 deletions Kool.EditProject/Kool.EditProject.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,20 @@
<Compile Include="EditProjectPackage.cs" />
<Compile Include="Ids.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Resources.cs" />
<Compile Include="Vsix.cs" />
<Compile Include="VSPackage.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>VSPackage.tt</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<None Include="Key.snk" />
<None Include="packages.config" />
<None Include="source.extension.vsixmanifest">
<SubType>Designer</SubType>
<None Include="source.extension.vsixmanifest" />
<None Include="VSPackage.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>VSPackage.Designer.cs</LastGenOutput>
</None>
</ItemGroup>
<ItemGroup>
Expand Down Expand Up @@ -173,30 +179,32 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<VSCTCompile Include="EditProjectPackage.en-US.vsct">
<VSCTCompile Include="EditProjectPackage.en.vsct">
<ResourceName>Menus.ctmenu</ResourceName>
</VSCTCompile>
<VSCTCompile Include="EditProjectPackage.zh-CN.vsct">
<VSCTCompile Include="EditProjectPackage.zh-Hans.vsct">
<ResourceName>Menus.ctmenu</ResourceName>
</VSCTCompile>
<VSCTCompile Include="EditProjectPackage.vsct" />
<Content Include="Resources\Logo.ico">
<IncludeInVSIX>true</IncludeInVSIX>
</Content>
<Content Include="zh-CN\extension.vsixlangpack">
<Content Include="zh-Hans\extension.vsixlangpack">
<IncludeInVSIX>true</IncludeInVSIX>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="VSPackage.en-US.resx">
<EmbeddedResource Include="VSPackage.en.resx">
<MergeWithCTO>true</MergeWithCTO>
<LogicalName>VSPackage.en-US.Resources</LogicalName>
</EmbeddedResource>
<EmbeddedResource Include="VSPackage.zh-CN.resx">
<EmbeddedResource Include="VSPackage.zh-Hans.resx">
<MergeWithCTO>true</MergeWithCTO>
<LogicalName>VSPackage.zh-CN.Resources</LogicalName>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<Service Include="{508349B6-6B84-4DF5-91F0-309BEEBAD82D}" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(VSToolsPath)\VSSDK\Microsoft.VsSDK.targets" Condition="'$(VSToolsPath)' != ''" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
Expand Down
2 changes: 1 addition & 1 deletion Kool.EditProject/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@
[assembly: AssemblyVersion(Vsix.VERSION)]

// https://docs.microsoft.com/en-us/visualstudio/extensibility/localizing-menu-commands
[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
[assembly: NeutralResourcesLanguage("en", UltimateResourceFallbackLocation.Satellite)]
13 changes: 0 additions & 13 deletions Kool.EditProject/Resources.cs

This file was deleted.

24 changes: 24 additions & 0 deletions Kool.EditProject/VSPackage.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
53 changes: 53 additions & 0 deletions Kool.EditProject/VSPackage.tt
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<#@ template debug="false" hostspecific="true" language="C#" #>
<#@ assembly name="System.Core" #>
<#@ assembly name="System.Windows.Forms" #>
<#@ import namespace="System.IO" #>
<#@ import namespace="System.Resources" #>
<#@ import namespace="System.Text.RegularExpressions" #>
<#@ output extension=".Designer.cs" #>

<#
const string NameSpace = "Kool.EditProject";
const string BenchmarkLanguage = "en";

var resourceNameWithoutCulture = Path.GetFileNameWithoutExtension(Host.TemplateFile);
var resourceFullNameWithoutCulture = NameSpace + "." + resourceNameWithoutCulture;
#>

// ------------------------------------------------------------------------------
// <auto-generated>
// This file was generated by T4 Template.
// </auto-generated>
// ------------------------------------------------------------------------------

using System.Resources;

namespace <#= NameSpace#>
{
/// <summary>
/// A strongly-typed resource class, for looking up localized strings.
/// </summary>
static class <#= resourceNameWithoutCulture#>
{
static readonly ResourceManager Resx = new ResourceManager("<#= resourceFullNameWithoutCulture#>", typeof(<#= resourceNameWithoutCulture#>).Assembly);

<#
var resx = Path.ChangeExtension(Host.TemplateFile , BenchmarkLanguage + ".resx");
using(var reader = new ResXResourceReader(resx) { UseResXDataNodes = true })
{
foreach (System.Collections.DictionaryEntry kv in reader)
{
var node = (ResXDataNode)kv.Value;
if (node.FileRef == null)
{
var keyName = kv.Key.ToString();
var propName = Regex.IsMatch(keyName , @"^\d+") ? "_" + keyName : keyName;
#>
public static string <#= propName#> { get; } = Resx.GetString("<#= keyName#>");
<#
}
}
}
#>
}
}
File renamed without changes.

0 comments on commit 78ab9c1

Please sign in to comment.