Run-time modification of menus and toolbar texts?


#1

John McClenahan and I have been working on an extension in which we want to let a user choose a language other than the one from the installed version of SketchUp. We envisioned this as a way to deal with situations in which we haven’t worked up a translation for a language yet (because we don’t know anything about, e.g., Chinese) and have a user who knows, say, French but not English. By letting them specify French, our extension would become more usable. We have a working version that lets a user specify and save a supported choice as default. That choice takes over in all of our text content the next time SketchUp is restarted.

We were looking for a way to cause changes to take effect immediately instead of having to restart SketchUp, but are coming to believe that is not possible for menu text and toolbar tooltips. I can access the UI::Commands that were originally used when items were added to the menus and toolbar, and can modify the properties of these Command objects. But doing so has no effect on the menu or toolbar, as if the properties were duplicated across to the menu and toolbar and detached from the Command object.

So, I’m looking for either confirmation that this is impossible or insight about how to make it happen.


#2

I believe you can only do it for the install of the rbz file…

if you have in the extension file

loader = File.join(EXTPATH, 'drawAngleDim_prefs.rb')

it can check and set prefs, before requiring your

loader = File.join(EXTPATH, 'drawAngleDim_menu.rb')

if people want to change ‘lang’ prefs after first run, you could do an auto restart to make it easier…

john


#3

Thanks for your reply John! We have a (unpublished) working system that reads defaults as the extension loads and sets all text to the saved translation language. We also have a dialog that lets a user choose a different translation. The new choice immediately alters all of our prompts, messages, input boxes, and web dialogs, without restarting SU. But I can’t find a way to change menu and tooltips without restarting SU.

Forcing a restart would work, but seems somewhat brutal…


#4

True. But this is not platform standard. It is just that the SketchUp API has not gone beyond the initial command registration. The Windows C API has functions that can be called to change the text in UI window objects. (Everything is a window or a window sub-class.)


We used to be able to change tooltip text dynamically in the v8 (and prior days) on Windows. This was when the tooltips were a single popup text flag.

Then with the v2013 release, tooltips changed to a definition-like box with an icon, a caption, and a description:

Since then (v2013,) they have been static, and loaded only at startup.


Another thing that loads only at startup, is the names, text and descriptions that appear in the old Preferences > Extensions panel.

Y’all need to keep in mind that the extension settings keys are partly the localized extension name, (with the version string concatenated onto the end,) so each time the user FIRST changes language, it’s like they just installed the extension afresh. Each language will be keeping it’s own startup settings.

Also, If the toolbar names are also localized, each language will have it’s own toolbar location and docking settings. So the toolbar could “seem” to move around weirdly, after the user changes language.


Bottom line, changing language causes registry bloat !

(Now you know why I never released my “LangPicker” utility.
It ends up begging the need for a SketchUp registry cleaner.)


#5

What you say worries me, so let’s discuss it a bit more.

First of all, I should clarify that all I am doing to change the presentation language for the extension is to set a variable to a language code such as “en-US”, “fr”, “de”, etc. This variable is used by the extension to decide which of a suite of translations is presented. I chose to use the same codes as Sketchup.get_locale so that our initial translation will match the user’s actual locale, but the action is otherwise independent of the locale in SketchUp. I do not monkey with any part of SketchUp or change the user’s actual locale.

To save and recall the user’s choice, I use Sketchup.write_default and Sketchup.read_default. The section and key values are hard-coded. Since they are not visible to the user, there is no reason to translate them. So all I am doing is to write and read back the language code string in a fixed registry location. Are you saying that SketchUp will somehow pick up the name of the extension doing the write/read_default and secretly append it to the registry keys?

I have been translating the extension.name and extension.description passed during registration of the extension. I can see how that makes SketchUp believe it is a new extension, which would need a new set of registration information. Do you know how much info is associated with a bare-bones extension?

I had noticed this effect. It seems the location of a toolbar is registered against its name, so if you translate the name the toolbar will get an independent position on the screen for each translated name. Maybe I shouldn’t translate the toolbar name…


#6

When you call Sketchup.register_extension( extension_instance ), the SketchupExtension class concatenates extension_instance.name + extension_instance.version and uses this as a plist/registry attribute name (under the “Extensions” key,) to store the load_on_startup boolean value. (This is the checkbox state in the extensions list.)

Basically the (REG_DWORD) value is 0 or 1 (don’t load / load at startup.)

So you might conclude this facet has minimal impact.

Yes I think this might have more of an impact on regisrty size, although it might not be as bad as I made it sound. The Bar key has a numeracal ID and a string name. And then the ID key has at least 3 numerical attributes.

Likely that Reset Workspace would clear these out ?

For me, I am comfy with manually editing the registry to clean things out (which must be done when SketchUp is closed. The Summary count must be corrected manually also.)

Up to you. Most times it may not matter, as if it’s docked you cannot see the name anyway.


#7

I do this exact same thing in a few of my extensions.
Changing each extension is separate from all other extensions.

This is not the problem you are looking for. … move along.