Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Change the UI Culture for my addin

1 REPLY 1
SOLVED
Reply
Message 1 of 2
ServiceRRVWQ
183 Views, 1 Reply

Change the UI Culture for my addin

Hello everyone.

 

I would like to make my add-in bilingual. Is there a way to change the UI culture during execution?

Or after restarting the addin?

 

I have already tried to localize the MainForm, but without success.

I use VB.Net 2019 with Resx Manager and Inventor 2022.

Labels (3)
1 REPLY 1
Message 2 of 2

The short answer is

Resources.Culture = CultureInfo.GetCultureInfo("cs-CZ");

 

The long answer with explanation follows:

How to make add-in localized is a complex task.

At first you need to move all localizable "items" to resources. My best experience is to use single resource file for single assembly (.dll file, project). It is hard to maintain multiple resource files.

At second you need to translate items in resources. It can be strings (the most common) and another resources like icons, images etc. Great tool for maintain resource file is the ResXManager.

 

If you want to use localized resources in code, there is no problem and you can use them directly.

inventor.CommandManager.PromptMessage(Resources.SampleCommand_ResponseMessage, 0);

 

If you want to use localized resources in WinForms controls and dialogs, my best experience is to create and use my own localization method and call them when the dialog loads. It is much safer an more maintainable, than "localized form". It is not easy to pass localization language to it.

private void CommandDialog_Load(object sender, System.EventArgs e)
{
    LocalizeControl();
}

private void LocalizeControl()
{
    Text = Resources.SampleCommand_DisplayName;
    Icon = Resources.Flag;

    lblText.Text = Resources.CommandDialog_lblText_Text;
    btnOk.Text = Resources.CommandDialog_btnOK_Text;
    btnCancel.Text = Resources.CommandDialog_btnCancel_Text;
}

 

How to switch the language of your add-in.

As mentioned above, you can switch the Culture of the Resources class. The best time is in Activate method. You can store the language settings in your config file, and load and apply this settings during add-in activation.

You can change the language settings of the add-in later, but for the best result it is necessary to restart the addin. Because for example ButtonDefinition.DisplayName property is read only, and you need to recreate the button (you can't update them).

 

You can see the sample add-in with localization in attachment. It is in C#, but the concept is the same in VB.NET and I hope you find them useful.

 

WARNING

One warning at the end. NEVER use the approach where you change the CurrentUICulture of the thread. It has many side-effects and can corrupt the underlying application or loaded add-ins.

// !!! NEVER USE THIS !!!
Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(1033);

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Technology Administrators


Autodesk Design & Make Report