Does anyone have any suggestions on what is the best way to translate a C# application in VS .net?

Currently I am translating a GUI in multiple languages and editing the Form.languagecode.resx file but when I make edits to the GUI, even a litte thing like moving a button, all the changes are lost. Perhaps the way I am doing the localization is not the best way.

Personnaly, what I'd do, is create a static class containing only string properties for all the text written in the application. And then for each properties you would return the value depending on the language set in the user settings or last used settings (Settings.settings)

This way each text area wont directly have text but they would refer to the property in the static class

The form resx file is used by the form to store things like background image and form size, etc. Any change to the form will rebuild the form.resx file.

To localize the form you need to create a separate set of resx files and when ever the form is loaded call a function to read the text from the resx file. Just reading the resx file should do as the os will select the correct resx based on the current language.

Can you please give an example on how you would do that? Perhaps with some sample code in the Settings.settings as well as in the Form code. Thanks.

Personnaly, what I'd do, is create a static class containing only string properties for all the text written in the application. And then for each properties you would return the value depending on the language set in the user settings or last used settings (Settings.settings)

This way each text area wont directly have text but they would refer to the property in the static class

public partial class Form1 : Form
        {
                public Form1()
                {
                        InitializeComponent();
                        Settings1.Default.Language = Language.French;
                        btn.Text = Translater.btn;
                }
        }


        public enum Language { English , French }

        public static class Translater
        {

                public static string btn
                {
                        get
                        {
                                switch( Settings1.Default.Language )
                                {
                                        case Language.English:
                                                return "Hello World!";
                                        case Language.French:
                                                return "Bonjour Monde!";
                                        default:
                                                return null;
                                }
                        }
                }
        }

and this is what you'd have in your settings.cs

[global::System.Configuration.UserScopedSettingAttribute()]
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
        [global::System.Configuration.DefaultSettingValueAttribute("Language.English")]
        public Language Language
        {
            get {
                return ((Language)(this["Language"]));
            }
            set {
                this["Language"] = value;
            }
        }

Lil tip, add it as string, and then go replace the string by Language in the code.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.