How to check localized winforms application?

Background:

I created a window sample application to teach localization implementation. Each of my forms has two .resx files. One for Bulgaria and one for French (Belgium). It has a default culture English (XX)

For testing locally, I am currently changing the UICulture programmatically, i.e. Thread.CurrentThread.CurrentUICulture = new CultureInfo ("fr-BE"); And it works great.

Problem:

How can I check without forcing UI Culture programmatically? I tried changing the Control Panel> Regional Settings> Standard and Formats to French (Belgium). This has made changes to DatePickerControl and now displays French dates. However, I still see the Button text in English, where, as if I tested by entering the CultureInfo programmatically, it changes to French.

If I can change the standard and formats to French, do I still need to install the multilingual user interface (MUI) package?

Another question arises: How to check the localization in a winforms application? However, he does not answer my question.

+4
source share
2 answers

You can use a virtual machine installed with various localized OSs, i.e. French XP, Japanese XP, etc. We used this method to check the localization, since, as you say, simply changing the language / time zone settings is not enough.

+2
source

Why don't you put the localization parameter in the configuration file? Your application can read the configuration file at boot time and apply the correct settings to it. Then you need to handle the localization of each line manually.

I did something similar for a tool that I did 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
source

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


All Articles