Question Translate a WinForm type application into multilingual

sn_race

Member
Joined
Feb 27, 2022
Messages
11
Programming Experience
5-10
Hello,

I have developed a project in WinForm and I would like to implement multilingual translation as in commercial software.

I tried using the resource file (.resx).
Is it really the best approach to translate all user interfaces and messages?

Wouldn't it be better something like using the Application Database by adding the Languages table, where each column is the object to translate and each record is a language?

Are there more just methods?
 
I tried using the resource file (.resx).
Is it really the best approach to translate all user interfaces and messages?
It's the way that is built into .NET and WinForms so you just have to supply the data and the rest is done for you. It's the best from the perspective that a lot of the work and testing has already been done for you. It will just work based on the user's current culture settings without you adding any code.
Wouldn't it be better something like using the Application Database by adding the Languages table, where each column is the object to translate and each record is a language?
Better in what way exactly?
Are there more just methods?
You can do it any way you want. It's all just data. It's just a matter of how much work you need to do and how robust the end result will be.
 
If I use a database I could transfer the result of the query in a static class and recall any item on the whole project, with the resource file I have to write twice item by item all the translations to be done in the entire software, I'll give you a little example:

This is the Class that changes the language:
    public static class Language
    {
        //Form1 "Container"
        public static string Form1 = "";
        public static string tsbScheduling = "";
        public static string tsbGrups = "";
        public static string tsbPosts = "";
        public static string tsbLogin = "";
        public static string tsbInfo = "";
        public static string tsmLanguage = "";
        public static string tsmi_IT = "";
        public static string tsmi_EN = "";
        public static string tsmi_RO = "";


        public static void Translate(string _ln = "")
        {
            string LinguaSistema = CultureInfo.CurrentUICulture.ToString();

            if (_ln == "")
            {
                Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(LinguaSistema);
            }
            else
            {
                Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(_ln);
            }

            //Form1 "Container"
            Form1 = Properties.languages.lang.Form1;
            tsbScheduling = Properties.languages.lang.tsbScheduling;
            tsbGrups = Properties.languages.lang.tsbGrups;
            tsbPosts = Properties.languages.lang.tsbPosts;
            tsbLogin = Properties.languages.lang.tsbLogin;
            tsbInfo = Properties.languages.lang.tsbInfo;
            tsmLanguage = Properties.languages.lang.tsmLanguage;
            tsmi_IT = Properties.languages.lang.tsmi_IT;
            tsmi_EN = Properties.languages.lang.tsmi_EN;
            tsmi_RO = Properties.languages.lang.tsmi_RO;
        }
    }

On Form1 there will be::
        private void SwitchLanguage(string _ln = "")
        {
            Language.Translate(_ln);

            this.Text = Language.Form1;
            tsbScheduling.Text = Language.tsbScheduling;
            tsbGrups.Text = Language.tsbGrups;
            tsbPosts.Text = Language.tsbPosts;
            tsbLogin.Text = Language.tsbLogin;
            tsbInfo.Text = Language.tsbInfo;
            tsmLanguage.Text = Language.tsmLanguage;
            tsmi_IT.Text = Language.tsmi_IT;
            tsmi_EN.Text = Language.tsmi_EN;
            tsmi_RO.Text = Language.tsmi_RO;
        }

What is on the class will become very long, the software is not small, it has a lot of things to translate.
 
.NET already has a mechanism for supporting localization using satellite assemblies. Instead of storing the strings and other assets in a database, they are stored in assemblies. These assemblies are created by having multiple language or culture specific .resx files. At runtime the system loads the appropriate assembly (or you can override). In your code you simple referr to the same resources names. You do not have to do anything special to say that you want a specific language or culture version of that resource. You can read more about this here:


(I know there is a much better document about WinForms localization, but I can't find it right now. I'll post that when I find it again.)
 
What is on the class will become very long, the software is not small, it has a lot of things to translate.
That is because you are not using the .resx files the way they were mean to be used.
 
That is because you are not using the .resx files the way they were mean to be used.
I misunderstood that post. I thought that all that code was to go with the database. It never occurred to me that someone would write all that code to do what .NET already does for them. The key words here are "globalization" and "localization". The first is preparing your app to support multiple languages and the second is implementing support for a specific language. That's what you should research.
 
That is because you are not using the .resx files the way they were mean to be used.

Do you have links where I can see an example of how to use it?

I made 3 rows:
lang.resx
lang.en.resx
lang.ro.resx

lang.resx is the default language, for me "Italian"

Where within them there are all String fields and their respective value.

In the class that I have shown I change the language and pass the values of the strings to the public properties in order to be able to recall them throughout the software.
 
You obviously did not bother to read the the link I posted above. It has sample code.
 
You obviously did not bother to read the the link I posted above. It has sample code.
Yes, I looked at it but for those who don't know how to do it, they seem like a list of examples for various occasions, an example link I meant an example of a blog where it says how to do it on one occasion.

But then who are you to tell me that I did not "deign", I'm not a kid, you have to learn to respect people and to talk.
 
There was a step-by-step example in that link above, if you had bothered to read it.

Here is a direct link to that part in that same page:
 
But then who are you to tell me that I did not "deign", I'm not a kid, you have to learn to respect people and to talk.
I did not say you were a kid. Where in post #9 did I say you were a kid?

Please educate me. What is the appropriate phrasing to state that someone missed about 25% of a web page? (The web page was about 16 screen pages long on a 1080px tall monitor with zoom set to 100%. The sample code section took up 4 of those 16 pages.) Drop the editorializing "obviously" and write it as:

"You must have missed the sample code in the link provided."

or

"Re-read the link provided again."
 
You didn't tell me I'm a kid but you treated me like a kid, it's possible it's the google translation that works badly, it doesn't matter, forget it, I don't like to argue if I'm not face to face with the person, it was a misunderstanding.
 
Last edited by a moderator:
You didn't tell me I'm a kid but you treated me like a kid, it's possible it's the google translation that works badly, it doesn't matter, forget it, I don't like to argue if I'm not face to face with the person, it was a misunderstanding.
Translated, please post in English in these forums.
 
In the original post, the OP was asking about getting the localization resources from a database, this question and answer in StackOverflow asks for the same thing, and more importantly has a response from a reputable source:

 
Back
Top Bottom