wxAUI: pane titles not translated if perspective loaded

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
Vexator
I live to help wx-kind
I live to help wx-kind
Posts: 187
Joined: Sun Jan 30, 2005 2:50 pm
Location: Heidelberg, Germany

wxAUI: pane titles not translated if perspective loaded

Post by Vexator » Mon Jan 03, 2011 6:21 pm

in my app, i use wxLocale etc. to translate strings to different languages. that works fine except for labels of wxAUI managed panes, when those are being restored from a saved perspective.

i set the locale in my wxApp instance, then create an instance of wxFrame, in which i create several pnaes like this:

Code: Select all

wxTreeCtrl *ItemsPanel = new wxTreeCtrl( this, wxID_ANY );
m_auiManager.AddPane( ItemsPanel, wxAuiPaneInfo().Name("Items panel").Caption(_("Items")).Left().Layer(1).Position(1).Hide() );
m_auiManager.Update();
when i start the application now, the caption ("Items") is being translated as it should. if, however, I load a perspective after all panes have been created, they are no longer being translated:

Code: Select all

m_auiManager.LoadPerspective( Layout );
is there a workaround for this? thank you!
Windows 7 Pro
Visual Studio 2010
wxWidgets 2.9.3

catalin
Moderator
Moderator
Posts: 1534
Joined: Wed Nov 12, 2008 7:23 am
Location: Romania

Post by catalin » Mon Jan 03, 2011 9:20 pm


PB
Part Of The Furniture
Part Of The Furniture
Posts: 2242
Joined: Sun Jan 03, 2010 5:45 pm

Post by PB » Mon Jan 03, 2011 9:21 pm

The simplest workaround seems to be:
1. Load the perspective
2. Obtain all panes array by calling wxAuiPaneInfoArray& wxAuiManager::GetAllPanes()
3. Iterate through that array and set the caption (by wxAuiPaneInfo::Caption(const wxString &c) to be _() of the untranslated, ie. current caption.

Something like that didn't work?

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

Post by DavidHart » Mon Jan 03, 2011 10:49 pm

Hi,
3. Iterate through that array and set the caption (by wxAuiPaneInfo::Caption(const wxString &c) to be _() of the untranslated, ie. current caption.
I was bitten by a similar issue, and tried this. It works, of course.

However, wxAui uses the caption as part of the way it 'registers' and identifies each dockable pane. So I found that, once the caption was changed, wxAui would lose track of the pane if it were moved or floated: it looked at the caption and decided it wasn't the one it was expecting.

In the end I gave up and stopped translating captions :( .

Regards,

David

PB
Part Of The Furniture
Part Of The Furniture
Posts: 2242
Joined: Sun Jan 03, 2010 5:45 pm

Post by PB » Tue Jan 04, 2011 6:38 am

DavidHart wrote:However, wxAui uses the caption as part of the way it 'registers' and identifies each dockable pane. So I found that, once the caption was changed, wxAui would lose track of the pane if it were moved or floated: it looked at the caption and decided it wasn't the one it was expecting.
I don't have much experience with wxAUI, but if it does that, it seems like a bug to me. Panels are supposed to be identified by their names and not their captions, right?

Anyway, speaking generally this is a problem that doesn't seem to have a simple solution. Imagine this scenario:
1. Application default language is English
2. User language is switched to French and the perspective saved
3. Application language is switched to Spanish
4. The perspective is loaded

Even if you store the user language somewhere along with the perspective, I don't think there's an easy automatic way how to translate captions that are stored in French into Spanish. Such a scenario is not very likely, but still possible.

If I had to solve this problem, I would probably do something like:
1. Create a name-->caption look up table for all panels in the default language (English), except those that are set by a user
2. After a perspective is loaded set the panel captions to the current user language based on the panel names.
Of course, this can work only if the issue David Hart mentioned has been fixed.

Post Reply