Change language interface on the fly 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
User avatar
dejudicibus
Knows some wx things
Knows some wx things
Posts: 32
Joined: Mon Dec 20, 2004 10:28 am
Location: Rome, Italy (EU)
Contact:

Change language interface on the fly

Post by dejudicibus » Fri Jan 26, 2007 12:24 pm

My application support multiple language interfaces and locales. However, when the user select a new language, I have to store it in an INI file so that at the next launch it can be used. If I change the locale on the fly, the interface continue to use the current catalog, even if I use this code to swich it:

Code: Select all

wxLocale * wbxDictApp::SetLocale(wxLanguage lang)
{
  if (locale) delete locale ;
	locale = new wxLocale() ;

	// --- Enter block (~wxLogNull called at the end) ---
	{
		wxLogNull noLog ; // --- Prevent message "Cannot load locale" 
		locale->Init(lang) ;
	}

	// --- Load catalog ---
	locale->AddCatalogLookupPathPrefix(wbxSTR_LOCALE_PATH) ;
	bool loaded = locale->AddCatalog(wbxSTR_LOCALE_CAT) ;
	if (!loaded)
	{
		wxString msg = wxString::Format(wbxMSG_NOLOCALE, locale->GetLocale()) ;
		wbxWarningMessage(NULL, msg) ;

  	if (locale) delete locale ;
		locale = new wxLocale() ;

		// --- Load REAL English catalog ---
		// --- Enter block (~wxLogNull called at the end) ---
		{
			wxLogNull noLog ; // --- Prevent message "Cannot load locale" 
			locale->Init(wxLANGUAGE_ENGLISH) ;
		}

		// --- Load catalog ---
		locale->AddCatalogLookupPathPrefix(wbxSTR_LOCALE_PATH) ;
		loaded = locale->AddCatalog(wbxSTR_LOCALE_CAT) ;
	}

	return locale ;
}
Any way to switch interface language on the fly in 2.8.0?

User avatar
T-Rex
Moderator
Moderator
Posts: 1198
Joined: Sat Oct 23, 2004 9:58 am
Location: Zaporizhzhya, Ukraine
Contact:

Post by T-Rex » Fri Jan 26, 2007 2:38 pm


User avatar
dejudicibus
Knows some wx things
Knows some wx things
Posts: 32
Joined: Mon Dec 20, 2004 10:28 am
Location: Rome, Italy (EU)
Contact:

Post by dejudicibus » Mon Jan 29, 2007 11:12 am

Thank you. I have seen that the author uses wxDELETE rather than delete to destruct an istance. What's the advantage?

User avatar
T-Rex
Moderator
Moderator
Posts: 1198
Joined: Sat Oct 23, 2004 9:58 am
Location: Zaporizhzhya, Ukraine
Contact:

Post by T-Rex » Mon Jan 29, 2007 12:01 pm

wxDELETE macro just checks if the pointer is equal to NULL and if it is not NULL-pointer then deletes allocated memory.

User avatar
esselo
Earned a small fee
Earned a small fee
Posts: 11
Joined: Thu Sep 13, 2007 6:52 am
Location: Finland

Post by esselo » Mon Sep 17, 2007 6:59 pm

OK, so this is an old thread and this link is pointing to something about HTML Helps, so I'm guessing the page at this URL seems to have changed. Any idea where the original page is located now, or did I just miss your point?

I'm also interested in this matter as I'm trying to become an expert in L10N / I18N things :wink:

User avatar
T-Rex
Moderator
Moderator
Posts: 1198
Joined: Sat Oct 23, 2004 9:58 am
Location: Zaporizhzhya, Ukraine
Contact:

Post by T-Rex » Mon Sep 17, 2007 7:49 pm


User avatar
esselo
Earned a small fee
Earned a small fee
Posts: 11
Joined: Thu Sep 13, 2007 6:52 am
Location: Finland

Post by esselo » Tue Sep 18, 2007 5:26 am

Brilliant, thanks a lot for the updated link.

Post Reply