为MVC生成Resx文件 [英] Generating Resx files for MVC

查看:143
本文介绍了为MVC生成Resx文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们使用resx文件进行全球化,同时使用数据库查询来查找CS员工可以配置的事物(例如选项卡名称,根据产品的不同而有所不同),因此在设计时是未知的. /p>

我创建了一个自定义工具,该工具可以读取resx文件,并将键/值对智能地转储到关系数据库中(匹配值,因此我们不会重复).

这对我们的业务有很大帮助-我们不必发送每个resx进行翻译(也不必为共享单词的重复翻译付费),并且我们所有的翻译都有黄金标准"(在数据库中) ).

我创建的工具还读取数据库,获取键/值对和每个值的转换,并为每个resx文件(以及文本的每种语言的转换)创建文本文件,并自动运行resgen.exe是Visual Studio附带的命令行工具,用于从生成的文本文件中编译resx文件.

我没有任何源代码控制集成,因此在使用该工具时,我们必须手动检出resx文件并手动检入生成的文件,但这并不是一个大问题.

我的问题是我们的新MVC项目无法使用这种方法:MVC项目要求resx文件必须是带有公共"访问修饰符的嵌入式资源.

因此,我们一直在手工修复此问题,这引入了人为错误的可能性,并增加了大量的工作量.

有没有办法让resgen.exe创建嵌入和公开的资源文件?如果没有,还有其他方法可以创建resx文件吗?

更新,其他问题: 我们使用此方法生成的resx文件也会发出警告:

A custom tool 'PublicResXFileCodeGenerator' is associated with file '(resxname)',
but the output of the custom tool was not found in the project.
You may try re-running the custom tool by right-clicking on the file in the
Solution Explorer and choosing Run Custom Tool. 

提到的工具是我们最初用于创建resx文件的工具.有什么办法可以防止此警告?

解决方案

我们最终找到了解决此问题的方法.

对于MVC项目,我们将工具更改为使用ResXResourceWriter类来更新resx文件,匹配现有密钥并根据需要添加新密钥.

这将保留嵌入式资源"状态以及所有其他所需的详细信息.

我们仍然必须在首次创建文件时正确设置文件,但这是一个更易于管理的问题.

We use resx files for globalization, along with database lookups for things that can be configured (such as tab names, which can be different by product) by our CS staff, and thus aren't known at design-time.

I created a custom tool that reads resx files and intelligently dumps the key/value pairs into a relational database (matching values so we don't have duplicates).

This has been a big help to our business - we don't have to send each resx for translation (and pay for duplicate translations of shared words) and we have a 'gold standard' with all our translations (in the database).

The tool I created also reads the database, picking up the key/value pairs and the translations of each value, and creates text files for each resx file (and each language's translation of the text file) and automates running resgen.exe, a command-line tool that ships with Visual Studio, to compile the resx files from the generated text files.

I don't have any source-control integration, so we have to manually check out the resx files and manually check-in the generated files when using the tool, but this hasn't been a big problem.

My problem is that this method is failing for our new MVC projects: the MVC projects require the resx files to be embedded resources with the Access Modifier of 'public'.

Thusfar, we have been fixing this by hand, which introduces the possibility of human error and adds a non-trivial amount of work.

Is there a way to get resgen.exe to create resource files that are embedded and public? If not, is there another way I can create resx files that will do so?

Update, additional question: The resx files we generate with this method also raise a warning:

A custom tool 'PublicResXFileCodeGenerator' is associated with file '(resxname)',
but the output of the custom tool was not found in the project.
You may try re-running the custom tool by right-clicking on the file in the
Solution Explorer and choosing Run Custom Tool. 

The tool mentioned is the tool we initially use to create the resx files. Is there a way I can prevent this warning?

解决方案

We did end up finding a solution to this problem.

For MVC projects, we changed the tool to use the ResXResourceWriter class to update the resx files, matching existing keys and adding new ones as needed.

This preserves the 'Embedded Resource' status as well as all of the other details that are needed.

We still have to set the file up correctly the first time it's created, but that is a much more manageable problem.

这篇关于为MVC生成Resx文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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