Home > Mobile >  Localization with C# Windows Forms, cannot access my .resx File
Localization with C# Windows Forms, cannot access my .resx File

Time:09-17

Hi I created this WinForm Program. It has several Forms.

I looked for a tutorial or someting to help and found this on StackoverFlow. Properties Folder

Then i wanted to access the Properties Folder to Use the ResourceString.de-De.resx File.

setLanguage

But it doesn't get suggested.

The Code has to look like this in the end :

private void setLanguage()
{
   btnSwitchLanguage.Text = Properties.ResourceString.de-DE.btnSwitchLanguage;
}

Am I missing something ?

Any Help is appreciated. :) Thanks

CodePudding user response:

You need to create a default 'ResourceString.resx' file along with al your language specific resx files. Make sure to add the same resources in all resx files. (btnSwitchLanguage, ...).

CodePudding user response:

You don't need to add the Strings.resx file, Your project already has the resource file Resources.resx. Therefore, you should add a new resource file with Resources.de.resx name, if required localization for the "de-DE". So, you can put into this resource file not only strings, but images, icons etc.

There is no need to change the Access Modifier to Public unless you are not going to access this resources from another assembly.

NOTE: When you are working in the Visual Studio the Visual Assist suggestion will be the same for all languages, starting from Properties.Resources.

CodePudding user response:

Well i found my mistake, after reading the Thread again, that i linked in my Post.

There should be a File called Strings.resx (or whatever Name you Choose), which contains the original strings. And the File which contains another language. (German in my Example). Should have the same name, except the language comes at the end. Like this :

Strings.de-DE.resx

After that i just had to change my Code to :

 private void btnSwitchLanguage_Click(object sender, EventArgs e)
    {
      
        if (Thread.CurrentThread.CurrentUICulture.ToString().Equals("de-DE"))
        {
            Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("en-GB");
        }
        else
        {
            Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("de-DE");
            
            setLanguage();
        }
    }

private void setLanguage()
{
    btnSwitchLanguage.Text = Properties.Strings.btnSwitchLanguage;
}
  • Related