Tuesday, September 23, 2014

Run time language change in your C# application (WPF)

For run time language change, like this,





1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Add this three reference 
using System.Reflection;
using System.Resources;
using System.Globalization;

namespace Localization
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void btnEN_Click(object sender, RoutedEventArgs e)
        {
            CultureInfo ci = new CultureInfo("en-US");
            Assembly a = Assembly.Load("Localization"); // Localization is the project name
            ResourceManager rm = new ResourceManager("Localization.LanguageFile.enLang", a); // enLang is resource file

            lblText.Content = rm.GetString("lblText", ci);
            btnEN.Content = rm.GetString("btnEN", ci);
            btnBN.Content = rm.GetString("btnBN", ci);
        }

        private void btnBN_Click(object sender, RoutedEventArgs e)
        {
            CultureInfo ci = new CultureInfo("bn-BD");
            Assembly a = Assembly.Load("Localization"); // Localization is the project name
            ResourceManager rm = new ResourceManager("Localization.LanguageFile.bnLang", a); // bnLang is resource file

            lblText.Content = rm.GetString("lblText", ci);
            btnEN.Content = rm.GetString("btnEN", ci);
            btnBN.Content = rm.GetString("btnBN", ci);
        }
    }
}


Thank you....



No comments:

Post a Comment