将转换后的resx文件放在Visual Studio中的其他文件夹中? [英] Put translated resx files in a different folder in Visual Studio?

查看:160
本文介绍了将转换后的resx文件放在Visual Studio中的其他文件夹中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含14个翻译和12个文件的解决方案,并且资源"文件夹有点不合时宜.有没有一种方法可以将翻译后的文件放到另一个文件夹中,以便我可以更轻松地访问英文主文件?

I've got a solution with 14 translations and 12 files and the "Resources" folder is getting a bit out of hand. Is there a way to put the translated files into a different folder so I can access the master English ones more easily?

我注意到您可以通过设置定制工具命名空间"来更改生成设计器文件的命名空间,但是我还没有弄清楚如何从其他文件夹中获取翻译.我玩弄了使用链接创建快捷方式"文件夹和真实"文件夹的想法,但是您无法链接到项目结构内的文件,也无法两次在项目结构外链接至同一文件.我考虑过根据语言更改ResourceManager使用的命名空间,但这会破坏回退行为.

I've noticed that you can change the namespace the designer file is generated in by setting the Custom Tool Namespace, but I haven't figured out how to pick up translations from a different folder. I toyed with the idea of using links to make a "shortcuts" folder and a "real" folder but you can't link to a file within the project structure and you can't link to the same file twice outside of the project structure. I thought about changing the namespace that the ResourceManager used based on the language but that would break the fallback behavior.

有什么办法可以管理它,因此在解决方案资源管理器中不是很大的文件列表吗?

Is there any way to manage this so it isn't a giant list of files in Solution Explorer?

推荐答案

假设您要将所有已翻译的.resx文件放置在Translations文件夹中,就像这样(请注意,我保留了默认值 en 版本):

Let's say you want to place all the translated .resx files in a Translations folder, like this (note I have left the default and en versions in the root folder):

然后,您所需要做的就是编辑MSBuild项目文件(从Visual Studio中,右键单击项目节点,单击卸载项目",然后单击编辑xxx.csproj"),然后重新配置此文件夹中的每个Resx文件像这样:

Then all you need to do is edit the MSBuild project file (from Visual Studio, right-click on the project node, 'Unload project', then 'Edit xxx.csproj'), and reconfigure each Resx file in this folder like this:

之前:

  <ItemGroup>
    ...
    <EmbeddedResource Include="Resource1.en.resx" />
    <EmbeddedResource Include="Translations\Resource1.fr.resx" />
    <EmbeddedResource Include="Resource1.resx">
      <Generator>ResXFileCodeGenerator</Generator>
      <LastGenOutput>Resource1.Designer.cs</LastGenOutput>
    </EmbeddedResource>
    ...
  </ItemGroup>

之后:

  <ItemGroup>
    ...
    <EmbeddedResource Include="Resource1.en.resx" />
    <EmbeddedResource Include="Translations\Resource1.fr.resx">
      <ManifestResourceName>$(TargetName).%(Filename)</ManifestResourceName> <!-- add this for all .resx files in a custom folder -->
    </EmbeddedResource>
    <EmbeddedResource Include="Resource1.resx">
      <Generator>ResXFileCodeGenerator</Generator>
      <LastGenOutput>Resource1.Designer.cs</LastGenOutput>
    </EmbeddedResource>
    ...
  </ItemGroup>

它的作用是指示基础的MSBuild任务使用您指定的清单名称,而不是自动生成清单名称.自动生成的文件夹始终使用RESX所在的文件夹布局,这不是我们想要的.

What it does is instruct underlying MSBuild tasks to use the manifest name you specificy instead of generating one automatically. The automatically generated one always uses the folder layout where the RESX resides in which is not what we want.

编译后,最终的卫星ConsoleApplication1.resources.dll文件将照常放置在fr文件夹中,但是其内容将与resx文件放置在根文件夹中的内容相同.

After compilation, the final satellite ConsoleApplication1.resources.dll file will be placed in the fr folder as usual, but its content will be the same as if the resx file was placed in the root folder.

这篇关于将转换后的resx文件放在Visual Studio中的其他文件夹中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆