Script para cambiar idioma (cultura) en toda la aplicación en C# WPF

Script que se aplica en arranque de aplicación, para cambio de idioma

    public partial class App : Application
    {
        protected override void OnStartup(StartupEventArgs e)
        {
            Options options = Options.Create();
            string alternativeAdminCoreServiceUri = options.AdminCoreServiceUri;
            // Parte particular: inicio
            Admin.Clients.Core.AdminClient adminEntityClient = new Admin.Clients.Core.AdminClient(options.AdminCoreServiceUri, 
                                                                    alternativeAdminCoreServiceUri);
            bool changedFromLocal;
            adminEntityClient.GetGlobalParameterValues("C:", out changedFromLocal);
            string cultureStr = adminEntityClient.AdminSet.GetGlobalParameterStr(Common.SharedEntities.Admin.GlobalParameterValueId.CultureName);
            // Parte particular: final
            System.Globalization.CultureInfo culture = System.Globalization.CultureInfo.GetCultureInfo(cultureStr);
            System.Threading.Thread.CurrentThread.CurrentCulture = culture;
            System.Threading.Thread.CurrentThread.CurrentUICulture = culture;

            WpfSingleInstance.Make(System.Reflection.Assembly.GetExecutingAssembly().GetName().Name, this);
            base.OnStartup(e);
        }
    }

Leave a Reply

Your email address will not be published. Required fields are marked *