Poedit problem 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
zhouhao
Earned some good credits
Earned some good credits
Posts: 144
Joined: Tue Dec 06, 2005 7:02 am

Poedit problem

Post by zhouhao » Sat Jul 26, 2008 4:56 am

Some texts are not correctly shown although I translated them by poedit. Here is my code:

Code: Select all


    const static wxString ITEM1	= _("Item 1");
    const static wxString ITEM2	= _("Item 2");

    wxArrayString CMyClass::Population()
    {
        wxArrayString array;
        array.Add(ITEM1);
        array.Add(ITEM2);
        return array;
    }

The problem is "Item 1" and "Item 2" are shown when I use the string array somewhere in my program. The corresponding translation is never shown. What could be the problem? ( Other texts are correctly translated and shown in my application)

utelle
Moderator
Moderator
Posts: 1008
Joined: Tue Jul 05, 2005 10:00 pm
Location: Cologne, Germany
Contact:

Re: Poedit problem

Post by utelle » Sat Jul 26, 2008 8:51 am

zhouhao wrote:The problem is "Item 1" and "Item 2" are shown when I use the string array somewhere in my program. The corresponding translation is never shown. What could be the problem? ( Other texts are correctly translated and shown in my application)
Since you use static wxString constants the compiler generates initialization code that is executed before your program gets the chance to load the po message catalogs. Therefore no translation is available and the strings remain untranslated.

You have to mark such strings using wxTRANSLATE() instead of _(), so that poEdit collects them, and use the function ::wxGetTranslation() to translate the strings at the places in your program where you use them.

See the wxWidgets documentation for further explanations:
http://docs.wxwidgets.org/2.8/wx_string ... xtranslate and
http://docs.wxwidgets.org/2.8/wx_string ... ranslation.

Regards,

Ulrich

zhouhao
Earned some good credits
Earned some good credits
Posts: 144
Joined: Tue Dec 06, 2005 7:02 am

Re: Poedit problem

Post by zhouhao » Sun Jul 27, 2008 1:01 pm

utelle wrote:
zhouhao wrote:The problem is "Item 1" and "Item 2" are shown when I use the string array somewhere in my program. The corresponding translation is never shown. What could be the problem? ( Other texts are correctly translated and shown in my application)
Since you use static wxString constants the compiler generates initialization code that is executed before your program gets the chance to load the po message catalogs. Therefore no translation is available and the strings remain untranslated.

You have to mark such strings using wxTRANSLATE() instead of _(), so that poEdit collects them, and use the function ::wxGetTranslation() to translate the strings at the places in your program where you use them.

See the wxWidgets documentation for further explanations:
http://docs.wxwidgets.org/2.8/wx_string ... xtranslate and
http://docs.wxwidgets.org/2.8/wx_string ... ranslation.

Regards,

Ulrich
Thank you so much, it works.

Zhou Hao

Post Reply