= Localization Using RESX Files = = WinForms Localization = * Create WinForms Application (eg ''MyApp.exe''). * Optionally, create an Resource-only Assembly (eg ''Acme.App.Localization.dll'') where all localized resources will be placed, so that other assemblies or applications can share it. * Create Resource file in local application or resource-only assembly. * Add new ''Resource.resx'' file to the project under ''Properties'' folder. * Set Access Modifier to ''Public'' (top toolbar in resource document). * Add strings to the Resource file. Eg: ''rsClose'' = ''Close'' * Autotranslate original English RESX strings using Google Translate and [[http://resxtranslatorbot.codeplex.com|Resx Translator Bot]]. * Create other resources files for other languages not supported in autotranslation. For example: * ''Resources.es.resx'' for Spanish (es-ES) * ''Resources.fr.resx'' for French Canadian (fr-CA), or potentially ''Resources.fr-CA.resx'' as well. * Set Culture before calling anything else in the application. Modify ''Program.cs'' to include: using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms; namespace LocalizedAppWinForms { static class Program { public static System.Resources.ResourceManager resmgr; /// /// The main entry point for the application. /// [STAThread] static void Main() { // Sets the UI culture //System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("es"); // Spanish (Spain) //System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en"); // English (US) System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("fr"); // French (France) //System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("de"); // German (Germany) // Load localized resources resmgr = new System.Resources.ResourceManager( "LocalizedAppWinForms.Properties.Resources", System.Reflection.Assembly.GetExecutingAssembly() ); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new frmMain()); } } } * Localize controls. For example, using form ''frmMain'', modify file ''frmMain.cs'' to include: private void frmMain_Load(object sender, EventArgs e) { LoadResources(); } private void LoadResources() { // Optional method to load resources local to this form //System.Resources.ResourceManager resmgrlocal = new System.Resources.ResourceManager( // "LocalizedAppWinForms.Properties.Resources", // System.Reflection.Assembly.GetExecutingAssembly() //); //lblFirstName.Text = resmgrlocal.GetString("rsFirstName"); //lblLastName.Text = resmgrlocal.GetString("rsLastName"); //lblPatient.Text = resmgrlocal.GetString("rsPatient"); //btnClose.Text = resmgrlocal.GetString("rsClose"); // Method to load global resources (defined in Program.cs file) lblFirstName.Text = Program.resmgr.GetString("rsFirstName"); lblLastName.Text = Program.resmgr.GetString("rsLastName"); lblPatient.Text = Program.resmgr.GetString("rsPatient"); btnClose.Text = Program.resmgr.GetString("rsClose"); } = WPF Localization = * Create WPF Application (eg ''MyApp.exe''). * Optionally, create an Resource-only Assembly (eg ''Acme.App.Localization.dll'') where all localized resources will be placed, so that other assemblies or applications can share it. * Create Resource file in local application or resource-only assembly. * Add new ''Resource.resx'' file to the project under ''Properties'' folder. * Set Access Modifier to ''Public'' (top toolbar in resource document). * Add strings to the Resource file. Eg: ''rsClose'' = ''Close'' * Create other resources files for other languages. For example: * ''Resources.es.resx'' for Spanish (es-ES) * ''Resources.fr.resx'' for French Canadian (fr-CA), or potentially ''Resources.fr-CA.resx'' as well. * Localize controls. * Add reference to ''Window'''s or ''UserControl'''s namespace in XAML. For example, if using resources within the application: . . . Or, if using a resource-only assembly instead: . . . * Add resource to a control. For example, assuming a resource string ''rsClose'' exists: