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/06/23 09:37]
smayr [Deployment]
swdev:dotnet:localization_using_resx_files [2013/12/16 15:26] (current)
smayr
Line 1: Line 1:
-WPF Localization =+= Localization Using RESX Files =
  
-== 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: <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 =
   * Create WPF Application (eg ''MyApp.exe'').   * 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.   * 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.   * Create Resource file in local application or resource-only assembly.
-    *  Add new ''Resource.resx'' file to the project under ''Properties'' folder.+    * Add new ''Resource.resx'' file to the project under ''Properties'' folder.
     * 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''
Line 144: Line 218:
   * Copy application executable, and localization resource-only assembly, if using one. Eg: ''MyApp.exe'', ''Acme.App.Localization.dll''   * Copy application executable, and localization resource-only assembly, if using one. Eg: ''MyApp.exe'', ''Acme.App.Localization.dll''
   * Copy language subfolders with localized resources or resource-only assemblies. Eg:    * Copy language subfolders with localized resources or resource-only assemblies. Eg: 
-    * ''..\de\Acme.App.Localization.resources.dll'' +    * ''..\de\MyApp.resources.dll'', or ''..\de\Acme.App.Localization.resources.dll'' 
-    * ''..\es\Acme.App.Localization.resources.dll'' +    * ''..\es\MyApp.resources.dll'', or ''..\es\Acme.App.Localization.resources.dll'' 
-    * ''..\fr\Acme.App.Localization.resources.dll'' +    * ''..\fr\MyApp.resources.dll'', or ''..\fr\Acme.App.Localization.resources.dll'' 
-    * ''..\pt\Acme.App.Localization.resources.dll''+    * ''..\pt\MyApp.resources.dll'', or ''..\pt\Acme.App.Localization.resources.dll''
   * Create an application settings file with default language setting. Eg: File ''//MyApp//.exe.config'': <code xml>. . .   * Create an application settings file with default language setting. Eg: File ''//MyApp//.exe.config'': <code xml>. . .
 <userSettings> <userSettings>
Line 676: Line 750:
 } }
 </code> </code>
 +
  
 = Reference Material = = Reference Material =
Line 683: 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]]