Search for text in code Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
ahoyle
Earned a small fee
Earned a small fee
Posts: 19
Joined: Wed Jan 17, 2007 8:38 am
Location: Devon, UK

Search for text in code

Post by ahoyle »

Hi All

I am looking it making an application more international. Having read chapter 16 “writing international applications” in the “wxBook”, and I have one question before I start. Is there any easy way the to add the require _() and _T() macros around the strings in code, that has been written without them. Or more to the point is there a utility that will find and highlight literal strings which have not been wrapped.

I know I could edit the code manual (and probably will do). But it would be nice if there was an automated way to do it, or at least check I haven't missing any strings.

I am using MS Visual studio 2005 standard, wxWidgets 2.8.7 and poEdit 1.4

Thanks in advance

ahoyle
swapd0
I live to help wx-kind
I live to help wx-kind
Posts: 169
Joined: Mon May 14, 2007 11:16 am
Location: Spain

Post by swapd0 »

You don't need to include _() and _T() before any string, you can put them in the output routines.

An example:

Code: Select all

...
void foo::showError(const char *msj)
{
    wxMessageDialog dlg(NULL, _(msj), "Error", wxICON_OK | wxICON_INFORMATION);
    dlg.ShowModal();
}

...


DavidHart
Site Admin
Site Admin
Posts: 4252
Joined: Thu Jan 12, 2006 6:23 pm
Location: IoW, UK

Post by DavidHart »

Hi,
Is there any easy way...
Not afaik; I just searched for ".
Of course if you have 5000 strings, this might be a little time-consuming :( .

But one thing you can do is afterwards to try to compile your app against a unicode wxWidgets build. This will give your an error for every string literal that isn't surrounded by a macro of some sort, so you can be fairly sure you haven't missed any.

Regards,

David
mc2r
wxWorld Domination!
wxWorld Domination!
Posts: 1195
Joined: Thu Feb 22, 2007 4:47 pm
Location: Denver, Co
Contact:

Post by mc2r »

sed

-Max
Utensil
Moderator
Moderator
Posts: 423
Joined: Sun Feb 03, 2008 11:38 am
Location: China

Post by Utensil »

mc2r wrote:sed

-Max

Code: Select all

sed 's/\("\([^"]\|\"\)*"\)/_(\1)/g' your.cpp > yournew.cpp
If you are using Linux or MSYS under Windows, this command will do, I've tested it.

This command made use of the powerful sed(stream editor) and Regular Expression(sed flavor), it might be hard to read/understand, but it's easy to use.

CAUTION:
If you have added _(),wxT() or _T() to some of your strings, you must strip them off first.

So in this case, you better excute the following:

Code: Select all

sed 's/\(wxT\|_T\|_\)(\("\([^"]\|\"\)*"\))/\2/g' Yours.cpp > Temp.cpp
sed 's/\("\([^"]\|\"\)*"\)/_(\1)/g' Temp.cpp > YourNew.cpp
-Utensil
In fascination of creating worlds by words, and in pursuit of words behind the world.

On Github: http://utensil.github.com
Technical Blog in Chinese: http://utensil.iteye.com/
Post Reply