如何将字符串放入MFC中的字符串表中?

时间:2022-04-29 07:12:07

I'm trying to localize a large MFC project where all the strings are hard-coded into the source code. (It was the easiest thing to do at the time, back before we had any idea we'd expand into other markets.) I've looked at localization tools, and invariably they say to put all the strings into the .rc file first, or just assume it has been done. Of the ones I've checked, appTranslator is the only one that even hints it may be a problem, and provides a couple of convenience functions to cut down on the wordiness of the resulting source code.

我正在尝试本地化一个大型MFC项目,其中所有字符串都硬编码到源代码中。 (这是当时最容易做到的事情,早在我们知道我们会扩展到其他市场之前。)我看过本地化工具,他们总是说要把所有字符串放到.rc文件中,或者只是假设它已经完成。在我检查的那些中,appTranslator是唯一一个甚至暗示它可能是一个问题的人,并且提供了一些便利功能来减少结果源代码的冗长。

Does anybody have a better idea than going through hundreds of files manually, and making the occasional mistake along the way?

有没有人比手动浏览数百个文件有更好的想法,并在此过程中偶尔出现错误?

Is there some sort of product out there to help?

有什么产品可以提供帮助吗?

Does anybody have experience with doing this?

有没有人有这方面的经验?

2 个解决方案

#1


It is a tedious process to be sure. I participated in an effort like this many years ago. We did it manually. You can probably write some common code that makes the loading, checking, etc all pretty clean with minimal bloat.

确定这是一个繁琐的过程。多年前我参加了这样的努力。我们手动完成了。您可以编写一些通用代码,使加载,检查等都非常干净,最小的膨胀。

I don't know of any products that will do it for you.

我不知道有哪些产品可以帮到你。

CStrings might be your friend - using the LoadString() member.

CStrings可能是你的朋友 - 使用LoadString()成员。

I would either derive from CString or write some other code that encapsulates default values (their current hard-coded values probably) and other error conditions and then use that in place of the hard-coded strings.

我要么从CString派生,要么写一些其他代码来封装默认值(可能是当前的硬编码值)和其他错误条件,然后使用它代替硬编码字符串。

If you prefer not to use CString, then deriving from std::string and using the global LoadString() works fine too.

如果你不想使用CString,那么从std :: string派生并使用全局LoadString()也可以正常工作。

as for tools: not sure they will work for your case: http://www.modelmakertools.com/articles/hard-coded-strings.html

至于工具:不确定它们是否适用于您的情况:http://www.modelmakertools.com/articles/hard-coded-strings.html

apparently this tool can find all the strings in your exe files: http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx Then you can search for them and replace.

显然这个工具可以找到exe文件中的所有字符串:http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx然后你可以搜索它们并替换它们。

I think writing a tool would be fairly straightforward - look for " character and then create an entry in an rc file that corresponds to the .cpp or .h file it came from. You will have a lot of culling to do, but it is a start. You can do a replace of the text, or insert comments, etc. You can use the line number and file name for the resource id/name in a #include.

我认为编写一个工具会相当简单 - 查找“字符然后在rc文件中创建一个条目,该文件对应于它来自的.cpp或.h文件。你需要进行大量的剔除,但它是您可以替换文本或插入注释等。您可以在#include中使用资源ID /名称的行号和文件名。

#2


I know it's too late but just for the search engine.
There is a feature of CString to initialize it from a resource ID.

我知道现在为时已晚,但仅限于搜索引擎。 CString的一个功能是从资源ID初始化它。

CString((LPCTSTR)IDS_RESOURCE_ID)

#1


It is a tedious process to be sure. I participated in an effort like this many years ago. We did it manually. You can probably write some common code that makes the loading, checking, etc all pretty clean with minimal bloat.

确定这是一个繁琐的过程。多年前我参加了这样的努力。我们手动完成了。您可以编写一些通用代码,使加载,检查等都非常干净,最小的膨胀。

I don't know of any products that will do it for you.

我不知道有哪些产品可以帮到你。

CStrings might be your friend - using the LoadString() member.

CStrings可能是你的朋友 - 使用LoadString()成员。

I would either derive from CString or write some other code that encapsulates default values (their current hard-coded values probably) and other error conditions and then use that in place of the hard-coded strings.

我要么从CString派生,要么写一些其他代码来封装默认值(可能是当前的硬编码值)和其他错误条件,然后使用它代替硬编码字符串。

If you prefer not to use CString, then deriving from std::string and using the global LoadString() works fine too.

如果你不想使用CString,那么从std :: string派生并使用全局LoadString()也可以正常工作。

as for tools: not sure they will work for your case: http://www.modelmakertools.com/articles/hard-coded-strings.html

至于工具:不确定它们是否适用于您的情况:http://www.modelmakertools.com/articles/hard-coded-strings.html

apparently this tool can find all the strings in your exe files: http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx Then you can search for them and replace.

显然这个工具可以找到exe文件中的所有字符串:http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx然后你可以搜索它们并替换它们。

I think writing a tool would be fairly straightforward - look for " character and then create an entry in an rc file that corresponds to the .cpp or .h file it came from. You will have a lot of culling to do, but it is a start. You can do a replace of the text, or insert comments, etc. You can use the line number and file name for the resource id/name in a #include.

我认为编写一个工具会相当简单 - 查找“字符然后在rc文件中创建一个条目,该文件对应于它来自的.cpp或.h文件。你需要进行大量的剔除,但它是您可以替换文本或插入注释等。您可以在#include中使用资源ID /名称的行号和文件名。

#2


I know it's too late but just for the search engine.
There is a feature of CString to initialize it from a resource ID.

我知道现在为时已晚,但仅限于搜索引擎。 CString的一个功能是从资源ID初始化它。

CString((LPCTSTR)IDS_RESOURCE_ID)