I need to translate some menuitem texts, I’m using menuitem.text = “…”, it works fine except in Windows if the menuitem has submenus. I have tried to place the translation at several events including enablemenuitems but it only works after restarting the app.
Also tried to remove the menuitem and create a different one as I had noticed strange behaviour with menuitems in the past but it doesn’t helps. As soon as I append any menuitem to it, the parent text doesn’t changes.
Mac is fine, only Windows. Xojo 2018 4
Do you try to change the MenuItem.Text property
in the Property pane (IDEs rightmost part)
Below the Appearance area, you will find the Text property.
If you don’t see a need for beeing able to switch the language from within the app or to be able to use a language different from the platform language, use Dynamic Constants instead.
A few days ago I have hit exactly the same issue, which is not new in r4, since r3 (both windows) has the same.
So I tried to reproduce in a small project, but couldn’t since it works fine as you can see when you get it.
I left it for the time being by putting it on my buglist for that project, but would be fine if we could solve it now.
Thanks Emile and Sascha but I need to be able to change languages at runtime.
Joost, thanks, I will check your project asap. I had several issues with menuitems in the past, just if they was a cache of properties somewhere and regardless what I did at runtime it had any effect, most of the times I had to remove the menuitems and create new ones to get it working.
Joost, your sample works as expected. This would mean something in our larger projects is interfering with the menuitem ¿?
While debugging, the text value of the menuitem changes correctly but it still displays the wrong one. I can change the text to several different values at runtime but only the first one set after starting the application is displayed, the text value is being changed correctly (as shown in debug window).
I tried to force refreshing by changing visibility but it doesn’t helps.
@Alejandro Fresno Meyer I am coding elsewhere in the project now, but I would remove the menu and rebuild it again. Then have a look in the file and compare the content with the version we’re having now.
As you see in my sample, we WILL get it working.
BTW: I have made sure nothing in my project interferes with the text-value in the menu, else than what we want to achieve business-wise.
I believe there is a workaround:
- Create a dummy menu item at the desired position
- Create a variable for a new menuitem
To change the text remove the menuitem (dummy or new) using parentmenu.remove(index), create a new menuitem with new text and use parentmenu.insert(index,newmenuitem) to insert it at the dummy position.
Remember to append any submenus to the new menuitem as they have been lost after removing.
This seems fine for Mac and Windows
By force you f**k an elephant.
Sorry Alejandro, I am happy that this workaround works for you, but it looks terrible to me. And the test-project shows it can work in a normal way, so I don’t give up and keep you informed.
I agree with you but prefer to have it working this way that spending more time on this
Please keep me informed about any progress.
@Alejandro Fresno Meyer - I’ve seen that if you remove the entire menu with the menu-editor and rebuild it, there is a chance that also translating menuitems afterwards will work as expected. Don’t see the difference, with the situation where it did not work and so don’t trust it will keep working after making changes in later versions.
So, what I did is skipping the menu-editor-tool, and build my menu’s dynamically by coding at startup of my app.
Example: (ViewMenuItem is just a class with it’s super is MenuItem) .
[code]Dim fMenu As ViewMenuItem
Dim sMenu As ViewMenuItem
For x As Integer = 1 To 10
fMenu = New ViewMenuItem("Test " + CStr(x),x) // tag = x
For y As Integer = 1 To 13
sMenu = New ViewMenuItem("Sub " + CStr(y),y)
If x = 5 Then ViewMenu.Append(New MenuItem(MenuItem.TextSeparator))
In the action event of ViewMenuItem you can easily handle the clicking
[code]Dim a As Integer = Self.tag
Your solution works, no doubt, but regarding that I only have issues with a single menuitem I prefer to just remove and reinsert it, it’s less work and probably faster to revert once this is solved in next versions.