Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
swdev:dotnet:localization_using_resx_files [2011/07/14 15:52]
smayr
swdev:dotnet:localization_using_resx_files [2013/12/16 15:26] (current)
smayr
Line 8: Line 8:
     * Set Access Modifier to ''Public'' (top toolbar in resource document).     * Set Access Modifier to ''Public'' (top toolbar in resource document).
     * Add strings to the Resource file. Eg: ''rsClose'' = ''Close''     * Add strings to the Resource file. Eg: ''rsClose'' = ''Close''
-  * Create other resources files for other languages. For example: +  * 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.es.resx'' for Spanish (es-ES)
     * ''Resources.fr.resx'' for French Canadian (fr-CA), or potentially ''Resources.fr-CA.resx'' as well.     * ''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: <code csharp>
 +using System;
 +using System.Collections.Generic;
 +using System.Linq;
 +using System.Windows.Forms;
  
 +namespace LocalizedAppWinForms
 +{
 +    static class Program
 +    {
 +        public static System.Resources.ResourceManager resmgr;
 +
 +        /// <summary>
 +        /// The main entry point for the application.
 +        /// </summary>
 +        [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());
 +        }
 +    }
 +}
 +</code>
 +
 +  * Localize controls. For example, using form ''frmMain'', modify file ''frmMain.cs'' to include: <code csharp>
 +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");
 +}
 +</code>
 = WPF Localization = = WPF Localization =
   * Create WPF Application (eg ''MyApp.exe'').   * Create WPF Application (eg ''MyApp.exe'').
Line 687: Line 750:
 } }
 </code> </code>
 +
  
 = Reference Material = = Reference Material =
Line 694: Line 758:
   * [[http://www.codeproject.com/KB/WPF/WPF_Resx_Localization.aspx?display=Mobile&fid=1538725&df=90&mpp=25&noise=3&sort=Position&view=Quick&fr=101|WPF Localization Using ResX Files]]   * [[http://www.codeproject.com/KB/WPF/WPF_Resx_Localization.aspx?display=Mobile&fid=1538725&df=90&mpp=25&noise=3&sort=Position&view=Quick&fr=101|WPF Localization Using ResX Files]]
   * [[http://www.codeproject.com/KB/WPF/WPF_Localization.aspx|Simple WPF Localization]]   * [[http://www.codeproject.com/KB/WPF/WPF_Localization.aspx|Simple WPF Localization]]
 +  * [[swdev:dotnet:localization:Editing RESX Files with SimpleResxEditor]]