Translate my Text

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.
ruud85
In need of some credit
In need of some credit
Posts: 3
Joined: Wed Mar 16, 2011 9:54 am

Translate my Text

Postby ruud85 » Wed Mar 16, 2011 10:07 am

Hallo
I have wrote a Progream.The program will be bilingual. I have used wxwidgets. But the language change comes only after I have closed my window and started again.
Is there a feature of wxwidgets that the language changes presented without reloading the window or relaod automatic he windows?

Thank you for your Help


here my code to take the my porgramm bilanguage that works

Code: Select all

void CSettingsExpertFrame::SelectLanguage(int lang)
{
   wxLocale* pLocal = NULL;
   pLocal = g_pApp->GetLocale();

   if( pLocal != 0 )
      delete pLocal;
   
   pLocal = new wxLocale( lang );
   pLocal->AddCatalogLookupPathPrefix(wxGetCwd());
   pLocal->AddCatalog( wxT("maindlg") );    
 }

void CSettingsExpertFrame::EVT_BTN_LANG_OK( wxCommandEvent& event )
{
   SelectLanguage( wxLANGUAGE_DEFAULT );

   int i_ChoiceSelect;
   wxArrayInt ai_languageCodes;
   wxArrayString aS_languageNames;
   i_ChoiceSelect=m_choiceLang->GetCurrentSelection();

   ai_languageCodes.Add(wxLANGUAGE_GERMAN);
   aS_languageNames.Add(_("Deutsch"));

   ai_languageCodes.Add(wxLANGUAGE_ENGLISH);
   aS_languageNames.Add(_("English"));

   if (i_ChoiceSelect==0)
   {
      SelectLanguage(0);
      
   }
   else
   {
      SelectLanguage(ai_languageCodes[i_ChoiceSelect]);
   }

   GetParent()->Refresh();
   GetParent()->Layout();
   Refresh();
   Layout();
}

briceandre
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 670
Joined: Tue Aug 31, 2010 6:22 am
Location: Belgium

Postby briceandre » Wed Mar 16, 2011 10:41 am

There is a dedicated mechanism provided with wxWidgets to support multi-language application.

Take a look at the internat sample provided with wxWidgets, it will probably be helpful.

The general idea is that you write all your program in a language, let's say english, but you encapsulate all strings that shall be translated in a macro -> wxString(_T("Hello World")).

Then, with a dedicated tool (for example poedit), you will extract a complete catalog of all strings that shall be translated. You can thus provide all translated catalogs to your application and, by configuring the default language (by default, this will be the one of your OS, but your application can dynamically change it during execution), all strings that are encapsulated in the macro and that are translated in the provided catalog will be translated in your application.

EDITED PS : you are not in the proper forum for this subject. You should envisage moving it to a more appropriate one...
Moderator: Done, and code-tags applied

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

Postby DavidHart » Wed Mar 16, 2011 10:54 am

Hi,

Just for the record, that's _("Hello World"), not _T("Hello World").

Regards,

David

ruud85
In need of some credit
In need of some credit
Posts: 3
Joined: Wed Mar 16, 2011 9:54 am

Postby ruud85 » Wed Mar 16, 2011 11:36 am

Hi use _("Text");

The problem is not the language is not changed but the language is not changed immediately

briceandre
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 670
Joined: Tue Aug 31, 2010 6:22 am
Location: Belgium

Postby briceandre » Wed Mar 16, 2011 12:23 pm

The problem is not the language is not changed but the language is not changed immediately


What do you mean by immediately ?

After having changed the language, the modification should be immediate. But, what is important to notice is that, it only means that after having changed the language, all new call to _("Hello World") will return the string in the proper language, but that does not mean that it will affect calls performed previously.

Imagine that, in your aplication, you initialise a frame like this :

Code: Select all

new wxFrame(parent, wxID_ANY, _("Hello World"));

after having changed the language, the instruction _("Hello World") will return, let say "Bonjour tout le monde". But the frame has already been initialised with "Hello World" so, the change will only take effect for next call to this instruction.

If you want to change everything, you should either configure the language before creating frames or dialog, or you should change by hand everything that was already initialised before you changed the language. In your example, you should, somewhere in the code, invoke the method SetTitle(_("Hello World")) after having changed ther language setting for the change being taken into account in your frame title.

ruud85
In need of some credit
In need of some credit
Posts: 3
Joined: Wed Mar 16, 2011 9:54 am

Postby ruud85 » Wed Mar 16, 2011 2:51 pm

I hvae a settingsdialog in this you can choice the language. Die übersetzung beginnt wenn ein ok button gedrückt wurde. Aber Das Hauptfenster von mir wird dann nicht sofort aktualisiert. Ich muss erst das Hauptfenster schleißen und wieder öffen dann ist die übersetzung auch in dem Fenster
I hpoe you can understand nee

briceandre
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 670
Joined: Tue Aug 31, 2010 6:22 am
Location: Belgium

Postby briceandre » Wed Mar 16, 2011 3:17 pm

Sorry, I do not speak German..

User avatar
doublemax
Moderator
Moderator
Posts: 12813
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Postby doublemax » Wed Mar 16, 2011 3:18 pm

There is no mechanism that automatically updates all windows/controls to the new language. You'd have to recreate the windows/controls.

The option to switch the language without restarting the application may be a nice feature, but users don't need it very often. I personally don't think it's worth the extra effort, in my applications i just display a message box saying "The application needs to be restarted for the changes to take effect."
Use the source, Luke!


Return to “C++ Development”

Who is online

Users browsing this forum: No registered users and 23 guests