Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Multilangual WindowsForms plugin

2 REPLIES 2
Reply
Message 1 of 3
Extraneous
207 Views, 2 Replies

Multilangual WindowsForms plugin

Hi! How do you create multilangual UI for Revit plugins?

I've always been using WindowsForms and setting "Localizable - True" in form's properties. Then I can change "Language" in form's properties and set texts in labels, checkboxes for the each language. It stores in .resx files and it's convenient because you shouldn't do anything else, and the most important you can check the displaying of texts for every language at the same time with developing.

Of course you also need to display some text in messageboxes, etc. You can manually create resource files, for example MyString.resx and MyStrings.fr.resx and add values for the each language. Then you can write:

 

MessageBox.Show(MyStrings.GoodbyeMessage);

 

Application will be able to get actual values automatically in depending of the current language. Great!

But how the application knows what the current language is?

It uses a property called Culture. When a process starts it get Culture from current Windows settings, but you can change Culture for you application in the beginning of your code:

 

System.Globalization.CultureInfo culture = 
         System.Globalization.CultureInfo.GetCultureInfo("en-US");
System.Threading.Thread.CurrentThread.CurrentUICulture = culture;
System.Threading.Thread.CurrentThread.CurrentCulture = culture;

 

And then your application will get the relevant resource files automatically.

 

But it works perfectly only for independent applications. In case of Revit you know the language of Revit's interface doesn't depend on the thread's Culture: https://forums.autodesk.com/t5/revit-api-forum/how-to-get-the-language-of-revit-user-interface/td-p/...

Revit can be in French but culture can be "en-US".

And if you will try to change the Culture it will be changed for the entire thread with Revit, because it works in the same thread. I'm afraid that outcomes of this can be unpredictable. For example I've met a plugin that changes Culture for the entire Revit thread and language of other plugins changes too after it was installed.

 

UPD: the continuation of my research:

It's possible to set the desired language for the resx-file manually:

 

MyStrings.Culture = new CultureInfo("en");

 

And it works! But it's impossible for resx-files that VisualStudio creates automatically for the form's content. It's because resx-file that you create manually has "Access modifier - Internal" and it means that VS creates a "wrapper"-class with the same name as your resx-file and you can call resx as like as a static class in your program. But Form1.resx has "Modifier - No code"; you can set "Internal" and the you can set "Form1.Culture = new CultureInfo("en");". I've found a solution! Or not? Then VS shows a warning about ambiguous names because the "wrapper"-class and Form have the same names. If I'm trying to change the class's name VS set its back automatically. What a shame...

Extraneous_0-1658934192364.png

 

I know many developers advice not to rely on resx-files but I still trying to use it because it's very convenient for simple apps. Maybe it's not dangerous to set the Culture for the entire Revit process?

Thanks in advance!

 

 

Alexander Zuev
In BIM we trust
Facebook | Linkedin | Telegram

2 REPLIES 2
Message 2 of 3
ricaun
in reply to: Extraneous

I never set the Culture/Language in my applications, usually, I configure the resource language with the right keyword related to the language, and works fine.

 

Here is an example that I created using WPF and Resource Files.

 

 

This example uses the default language as English and if you open Revit with Brazilian Portuguese or '"C:\Program Files\Autodesk\Revit 2021\Revit.exe" /language PTB' the plugin gonna show a different image and text.

 

Here is the video about RevitAddin.ResourcesExample (The audio is in Portuguese)

 

 

I hope this helps, see yaa.

 

 

 

 

 

 

 

 

Luiz Henrique Cassettari

ricaun.com - Revit API Developer

AppLoader EasyConduit WireInConduit ConduitMaterial CircuitName ElectricalUtils

Aprenda a criar um janela WPF e carregar Recursos no Revit em Português e Inglês automaticamente. Github: https://github.com/ricaun/RevitAddin.ResourcesExample Plugin Console: https://ricaun.com/console/ Subscribe for more! Please Like this Tutorial! Follow me on social media: Instagram: ...
Message 3 of 3
Extraneous
in reply to: ricaun

Thank you @ricaun !

I've realised where my mistake was.

I should use "Language - French(France)" instead of "Language - French". Because in this case resx-file will get incorrect name's key and it will not match the Revit's interface.

Extraneous_1-1659038121485.png

 

Of cource as I noticed Thread.CurrentCulture may not match with the Revit's interface. But this mechanism uses the property ThreadCurrentUICulture and as I see it matches the language in Revit.

Extraneous_0-1659037912622.png

 

Eventually the solution becomes very simple. I've created the sample with instructions in my github: https://github.com/Tereami/TestMultilangual

Maybe it will be useful for someone else. Thank yu again!

Alexander Zuev
In BIM we trust
Facebook | Linkedin | Telegram

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

Post to forums  

Rail Community


Autodesk Design & Make Report