开发者

How to test localized winforms application?

Background:

I have created sample windows application for learning to implement localization. My each form has two RESX file. One for Bulgaria and one for French(Belgium). It has default culture English(XX)

To test locally currently I am programmatically changing UICulture i.e. Thread.CurrentThread.CurrentUICulture = new CultureInfo("fr-BE"); And it works fine.

Problem:

How can I test without forcing the UI Culture programatically? I have tried changing Control Panel > Regional Options > Standard and Formats to French(Belgium). That made changes to DatePickerControl and now it display the dates French. However I can still see the Button text in English, where as if I test by injecting CultureInfo programmatically it changes to french.

开发者_JAVA百科

If I am able to change the standard and formats to French do I still need to Install Multilingual User Interface Pack (MUI)?

There is another question: How do I test localization in a winforms application? However it does not answer my question.


You could use VM's installed with different localized OS', i.e. French XP, Japanese XP etc. We used this method to test localization as, like you say, just changing your language / timezone settings isn't enough.


Why don't you put the localization setting in a config file? Your application can read the config file at load time and apply the correct setting based on that. Then you need to handle the localization of each string manually.

I did something like that for a tool I made once (in C#):

Localization.cs

    using System.Globalization;
    using System;

    namespace DummyProject
    {
        public class Localization
        {
            private string _language = "en";

            public Localization()
            {
                if (CultureInfo.CurrentCulture.Name.StartsWith("de") == true)
                {
                    CurrentLanguage = "de";
                }
                else if (CultureInfo.CurrentCulture.Name.StartsWith("fr") == true)
                {
                    CurrentLanguage = "fr";
                }
                else if (CultureInfo.CurrentCulture.Name.StartsWith("es") == true)
                {
                    CurrentLanguage = "es";
                }
                else
                {
                    // Default english
                    CurrentLanguage = "en";
                }
            }

            //-------------------------

            public string CurrentLanguage
            {
                get
                {
                    return _language;
                }
                set
                {
                    _language = value;
                }
            }

            private string GetLocalizedString(
                string pDefault,
                string pDe = "",
                string pFr = "",
                string pEs = "")
            {
                string returnValue = pDefault;

                switch (_language)
                {
                    case "de":
                    returnValue = pDe;
                    break;
                case "fr":
                    returnValue = pFr;
                    break;
                case "es":
                    returnValue = pEs;
                    break;
                default:
                    returnValue = pDefault;
                    break;
                }
                if (String.IsNullOrEmpty(returnValue) == true)
                {
                    returnValue = pDefault;
                }
                return returnValue;
            }

            public string AboutToolStripMenuItem { get { return GetLocalizedString("A&bout", "Ü&ber", "&A Propos", "&Acerca"); } }

            public string AutocheckForUpdateToolStripMenuItem { get { return GetLocalizedString("&Autocheck for update", "&Automatisch nach Updates suchen", "&Vérifier automatiquement les mises à jour", "&Comprobar actualizaciones automáticamente"); } }

            public string TimeUpdater { get { return GetLocalizedString("Timer Updater", "Zum Timer-Upater", "Mettre a jour", "Actualización de temporizador"); } }

            public string CloseToolStripMenuItem { get { return GetLocalizedString("&Close", "&Beenden", "F&ermer", "&Cerrar"); } }
        }
    }

Then in your main class:

    private Localization _localization;

    public Form1()
    {
        InitializeComponent();

        _localization = new Localization();

        //----

        // Load localization setting here
        _localization.CurrentLanguage = "en";

        //----

        SetLocalization();
    }

    private void SetLocalization()
    {
        aboutToolStripMenuItem.Text = _localization.AboutToolStripMenuItem;
        autocheckForUpdateToolStripMenuItem.Text = _localization.AutocheckForUpdateToolStripMenuItem;
        bttn_TimerUpdater.Text = _localization.TimeUpdater;
        closeToolStripMenuItem.Text = _localization.CloseToolStripMenuItem;
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜