Menu / Enablemenuitems

After launching my application, I read the preferences, determine the language desired, and changed the Menu names and items accordingly. Unfortunately, the original words from the defined Menu items are displayed first for a half a second, until I do a Enablemenuitems after the processing of the preferences, to show the (changed) Menu items. How can I prevent the application to show the predefined names until I do a first enablemenuitems?

  1. dont change the NAMES of the items - just their text
  2. read the preferences & set all the text of the items in your app open event

Hi Norman,
Sorry, I meant the menu texts and not the names.
And in the App open event, I call a few methods, one of them the ReadPreferences. That’s not good enough?
Cheerio

Well if you want the text of the items to show up as whatever language the person selected you need to do more than read the preferences
you need to actually SET the text in there as well
no need to wait for Enable Menuitems to do it as long as you can get a reference to the menu bar

Okay, so your problem is because you’re doing it yourself. Ideally you should have your translations as Dynamic constants and let the OS deal with localization. It gives you less control, i.e. being able to offer the user the option to have a language that’s different than the computer, but you’ll save yourself a lot of work and maintenance.

Yeah don’t do this; EnableMenuItems gets called A LOT, so you risk wasting time and resources by either replacing the existing text with existing text, or checking to see if the text needs to be replaced.

Do this if you choose to continue using your own localization system.

I also encourage people to use dynamic constants as this makes the experience what a person expects when they set the language at the OS level
But there are reasons people have enumerated as to why they do NOT want things to work that way

But changing them in EnableMenuitems is definitely not the best place to locate such code (esp on OS X)
Why not ?
I would encourage anyone who wonders to create a small app with a text area on the layout and simply put

  system.debuglog currentmethodname

in the textareas EnableMenuitems event, the windows EnableMenuitems event and the apps EnableMenuitems event
Open Console and run this app and start pressing keys
And you’ll see why EnableMenuitems should ONLY “enable” menu items and you should avoid rebuilding menus in there as much as possible

[quote=328116:@Sam Rowlands]
Do this if you choose to continue using your own localization system.[/quote]

Or just define all the required dynamic constants, set the menu items text to # and do nothing and let everything be done for you
Thats my preferred way as well

Ok, my application just needs english and german…
Anyway, the #-methode as above seams good, but there are too many label-fields and texts in windows that needed to be adapted.
Is there no simpler way?

I did this now:

  • my 4 menus, set to: visible OFF
  • in the App open method:
    PrefsRead
    EnableMenuItems (within: if pLang = “G” then MenuFile.Text = “Datei”)
    MenuFile.visible = true
    MenuEdit.visible = true
    MenuWindow.visible = true
    MenuHelp.visible = true

Effect: after launching, for a part of a second, no menus, then the right ones (in the correct language) are displayed. This does it for me.
Still, it seems that in Xojo normally the Menu is being showed before the ‘App open’?
Thanks for all your help and suggestions above.

The menu isn’t shown until after app.Open, but you’re calling EnableMenuItems before the Window is even created. Your EnableMenuItems handler affects the app menu instance, but the window gets created with a menu instance using the default values, until the EnableMenuItems event gets triggered again.

Well, I used to not using Enablemenuitems, and even when the first window was shown, the menu texts changed only when being clicked on with the mouse pointer.
When using it in the App.open method, it changes as described here after a split-second, before the main window is opened.
So is when it the app instance (if this exists) gets created and it displays the original menu text, before I am able to change it in the app.open method?
With hiding them and letting menu.visible = true and enablemenuitems in the window.open method does it nicely.

If you have a default window set, I doubt the app menu is being displayed at all. Calling EnableMenuItems in Window.Open should do the trick, even without menu.visible set to false.

I dont have a default window set, but I tried it: no change.
And again, the initial menu text in the default language changes only when the window opens and using enablemenuitems in the .open method, or without enablemenuitems when later the menu ist clicked onto.
So I’m happy with my solution for the moment, Thanks!
Don’t now why the menu is already shown before the app.open method is done, a Xojo mystery for me.

[quote=328122:@Peter Kronenberg]Ok, my application just needs english and german…
Anyway, the #-methode as above seams good, but there are too many label-fields and texts in windows that needed to be adapted.
Is there no simpler way?
[/quote]
Not really
There is no magic to invoke here that will suddenly replace all your text values with constants

Dont use EnableMenuItems - this will simply cause you issues (as you’ve described)
You really need a method that walks through the MenuBar as it currently exists and sets each items text that does NOT cause it to become visible (enablemenuitems will)

You have just a long long list of if statements with hard coded values in German ?
That is definitely a hard way to do this sort of thing

Without seeing all this code it is hard to make further recommendations BUT every one of them I can think of will involve varying amounts of work on your part