How to make a multilingual application in winforms

I have an application and I need to use two languages โ€‹โ€‹(for example, English and Arabic) in this application, but I do not know how to do it. Can anybody help me? I need some examples in C # Windows Forms.

+10
source share
3 answers

Using Properties Localizableand LanguageForms

The class Formhas the property Localizableand Language. If the property is Localizableset to true, you can add controls to the default language form and set the properties for the default language. Then you can select other languages โ€‹โ€‹and change the properties for these languages. Thus, values โ€‹โ€‹or localized properties will be stored in separate resource files for different cultures.

Note. A property is considered localizable if it is decorated with an attribute [Localizable(true)]. For example, a property is BackColornot localizable, but a property Textis localizable.

Localization of messages and images using Resx resource files

Rseources.Resx Properties, . .resx . , Strings.resx , strings.en.resx strings.fa.resx . , :

MessageBox.Show(Properties.Resources.AreYouSure);

AreYouSure Resources.Resx .

, Resx.

Persian, :

System.Threading.Thread.CurrentThread.CurrentCulture =
    System.Globalization.CultureInfo.GetCultureInfo("fa");

System.Threading.Thread.CurrentThread.CurrentUICulture =
    System.Globalization.CultureInfo.GetCultureInfo("fa");

.

:

+20

.

  1. Visual Studio. . en.resx fr.resx .

  2. , , . : next station next station en.resx - next station fr.resx Prochaine station. : en_local.resx fr_local.resx

  3. public static ResourceManager rm = new ResourceManager("WindowsFormsApp1.en_local", Assembly.GetExecutingAssembly()); .

  4. , GetString(), label1.Text = rm.GetString("welcome");

+9

wwjih123 .

VS2017

1- ( ). lang_en, lang_tr, lang_fr ..

2 - then the object properties window leaves the assembly action as an embedded resource

3-inside the lang_tr.resx file add a new line lbl_error and the value "Hata" in Turkish (whatever)

4- inside the class, the variables are defined as:

    ResourceManager res_man;    // declare Resource manager to access to specific cultureinfo

5-in class initialization after InitializeComponent ();

Console.WriteLine("You are speaking {0}", 
System.Globalization.CultureInfo.CurrentUICulture.TwoLetterISOLanguageName);
res_man = new ResourceManager("MyApp.lang_"+ System.Globalization.CultureInfo.CurrentUICulture.TwoLetterISOLanguageName, Assembly.GetExecutingAssembly());

lblError.Text = res_man.GetString("lbl_error");

If your ui language is Turkish, it will automatically download lang_tr.resx, if the English lang_en.resx file is downloaded, etc ...

luck

+5
source

Source: https://habr.com/ru/post/1610556/


All Articles