Best approach to support several UI languages

Best approach to support several UI languages

Maxim-CADman77
Advisor Advisor
355 Views
3 Replies
Message 1 of 4

Best approach to support several UI languages

Maxim-CADman77
Advisor
Advisor

this is another (not directly related to Inventor) beginner-coder question:

I wonder which is the best approach to provide software product with several UI localizations?

I used to support two languages (my native and English).

I'm doing it in I believe not very smart way. In iLogic it looks somewhat like:

Sub Main
Dim sMsgTitle, sMsgBody, sLC As String

sLC = ThisApplication.LanguageCode
If sLC = "it-IT"
sMsgTitle = "Il mio saluto"
sMsgBody = "Ciao mondo"
Else
sMsgTitle = "My Greeting"
sMsgBody = "Hello World"
End If

MessageBox.Show(sMsgBody, sMsgTitle)
End sub


The worst thing about the way mentioned - I don't see easy way to split sentences with values of variables when necessary. I then use several separate strings (one for Sentence begin, ... , ..., and one for sentence ending.

I believe I need to use at least some variable value placeholders, right?
Or should I hard-code every sentence in English and connect some external resource file(s) from which those string values would be substituted (if applicable)?

 

How you, professionals , do all this stuff?

Please vote for Inventor-Idea Text Search within Option Names

0 Likes
Accepted solutions (1)
356 Views
3 Replies
Replies (3)
Message 2 of 4

Michael.Navara
Advisor
Advisor

This is very complex task, how to use localization in your code.

I recommend you to avoid to use localization in iLogic.

But in Add-Ins it is a different. You can use very robust tools from .NET System.Resources Namespace

How to use this is too complicated for this forum post. See some references on the internet. There are many useful links and samples.

 

Here is few screenshots from sample project

Resources can be found at Project settings page in VS

MichaelNavara_0-1678439131961.png

Usage looks like this

MichaelNavara_1-1678439214196.png

 

 

Message 3 of 4

Maxim-CADman77
Advisor
Advisor

@Michael.Navara 
Sorry for re-asking but what about using variable value in the middle of the string.
Let say I have string variable sAAA and it has value "10th"
How should I organize things so that my sMsgBody values be "Ciao, 10th mondo" and "Hello, 10th World!" accordingly?

Please vote for Inventor-Idea Text Search within Option Names

0 Likes
Message 4 of 4

Michael.Navara
Advisor
Advisor
Accepted solution

This is easy. You can have placeholders in localized strings.

 

'it: "Ciao, 10th mondo" => "Ciao, {0} mondo"
'en: "Hello, 10th World!" => "Hello, {0} World!"

dim msgFormat = "Ciao, {0} mondo" ' Can be obtained from My.Resources
MsgBox(String.Format(msgFormat, "10th"))
0 Likes