2

I am trying to use localization in a winform application and I have several questions. I was going to ask the most complex one but now I have got into a basic problem.

I have build a basic winform with a form, a label and a menustrip.

I have set the form localization to true and set the text of the label in three different languages. As a result I got Form1.es.resx , Form,1.ja.resx and the deafult Form1.resx.

I have checked and the default one is in english. However when I run the application, the label appears in japanese (my OS in windows japanese). Is Form1.resx not the default?

This also happens when I set the Form1 Language property to English.

KansaiRobot
  • 7,564
  • 11
  • 71
  • 150
  • how you change UI culture ? do you want to set localization in configuration or run time , allowing user to choose language ? – Z.R.T. Sep 05 '18 at 02:21
  • Originally I wanted to allow the user to change language on runtime, on multiple forms. But now that even the basics are not working, first I want to know why the form is in japanese even when I set the language to english. When I debug I can clearly see that the forms take from the japanese resource file and not the default one – KansaiRobot Sep 05 '18 at 02:25
  • I can change the language of the label on run time with `ApplyResources` but curiosly this does not work for Menus. But that is for my next question – KansaiRobot Sep 05 '18 at 02:26

2 Answers2

3

first need to add Resources file in the following format: for default leave as it is , for specific language use format Resources.[code-CODE]

enter image description here

if you want to change language in run time , you have to update control text "manually", otherwise you just need to set thread culture info before Application.Run.

class CultureItem
{
    public string Name { get; set; }
    public CultureInfo CultureInfo { get; set; }
}

public partial class MainForm : Form
{
    private CultureItem[] culutures = new CultureItem[]
    {
        new CultureItem() {Name = "Default", CultureInfo = new CultureInfo("en-US")}, 
        new CultureItem() {Name = "Italy", CultureInfo = new CultureInfo("it-IT")}, 
        new CultureItem() {Name = "Japan", CultureInfo = new CultureInfo("ja-JP")}
    };

    public MainForm()
    {
        InitializeComponent();
        comboBox1.DataSource = culutures;
        comboBox1.DisplayMember = "Name";
    }


    private void comboBox1_SelectedValueChanged(object sender, EventArgs e)
    {
        var selected = comboBox1.SelectedItem as CultureItem;
        if (selected != null)
        {
            Thread.CurrentThread.CurrentUICulture = selected.CultureInfo;
            ApplyLocalization();
        }
    }

    public void ApplyLocalization()
    {
        button1.Text = Properties.Resources.button;
    }
}
Z.R.T.
  • 1,543
  • 12
  • 15
1

When I run the application, the label appears in japanese (my OS in windows japanese). Is Form1.resx not the default?

The default resource file is a fallback for cases that you don't have a language resource file for current thread UI culture. Since your default OS language is Japanese (by default, unless you change it through the code) then the current thread UI culture is Japanese and since you have Japanese language file, then the form will be shown in Japanese language.

Reza Aghaei
  • 120,393
  • 18
  • 203
  • 398