// This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.Configure <CookiePolicyOptions>(options =>
            {
                // This lambda determines whether user consent for non-essential cookies is needed for a given request.
                options.CheckConsentNeeded    = context => true;
                options.MinimumSameSitePolicy = SameSiteMode.None;
            });
            var supportedCultures   = new[] { "es-ES", "en-US" };
            var localizationOptions = new RequestLocalizationOptions();

            localizationOptions.AddSupportedCultures(supportedCultures)
            .AddSupportedUICultures(supportedCultures)
            .SetDefaultCulture(supportedCultures[0])
            .RequestCultureProviders.Insert(0, new RouteDataRequestCultureProvider()
            {
                Options = localizationOptions
            });
            services.AddSingleton(localizationOptions);
            services.AddLocalization(opt => opt.ResourcesPath = "Resources");
            services.AddMvc(mvcOptions =>
            {
                mvcOptions.Filters.Add(typeof(CultureRedirectFilter));
                mvcOptions.Filters.Add(new MiddlewareFilterAttribute(typeof(LocalizationPipeline)));
            }).SetCompatibilityVersion(CompatibilityVersion.Version_2_1)
            .AddViewLocalization(LanguageViewLocationExpanderFormat.Suffix)
            .AddDataAnnotationsLocalization();
        }
Beispiel #2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
            var supportedCultures = new[]
            {
                "en",
                "es"
            };

            var opt = new RequestLocalizationOptions
            {
                DefaultRequestCulture = new RequestCulture("en"),
            };

            opt.AddSupportedCultures(supportedCultures);
            opt.AddSupportedUICultures(supportedCultures);
            services.AddSingleton(opt);
            services.AddMvc();
            services.AddRazorPages();
            services.AddServerSideBlazor(opt => opt.DetailedErrors = true);
            services.AddLocalization(options =>
            {
                options.ResourcesPath = "Resources";
            });
            services.AddSingleton <IPhotoLabelerService, PhotoLabelerService>();
            services.AddSingleton <IMenuService, MenuService>();
            services.AddSingleton <IDbConnection>((serviceProvider) =>
            {
                var connectionStringBuilder = new SqliteConnectionStringBuilder {
                    DataSource = "./appconfig.db"
                };
                var connection = new SqliteConnection(connectionStringBuilder.ConnectionString);
                return(connection);
            });
            services.AddSingleton <IAppConfigRepository, AppConfigRepository>();
        }
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            //cadena de conexion
            string connecionString = string.Empty;

            connecionString             = Configuration.GetSection("AppeSettings:cn").Value;
            ConnectionString.Connection = connecionString;

            //Inyeccion de depencias para acceder a los metodos creados en la interfaces
            IoC.AddRegistration(services);

            var supportedCultures = new[]
            {
                "en-US"
            };

            var localizationOptions = new RequestLocalizationOptions();

            localizationOptions.AddSupportedCultures(supportedCultures)
            .AddSupportedUICultures(supportedCultures)
            .SetDefaultCulture(supportedCultures[0]);

            services.AddSingleton(localizationOptions);;

            services.AddControllers();
        }
        public void Configuration(IAppBuilder app)
        {
            var options = new RequestLocalizationOptions()
                          .UseUnityInjection(UnityConfig.Container);

            options.AddSupportedCultures("en-US", "de");
            options.AddSupportedUICultures("en-US", "de");
            options.RequestCultureProviders.Clear();
            options.AddInjectedProvider <TestCultureProvider>();

            app.UseRequestLocalization(options);
        }
Beispiel #5
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.Configure <CookiePolicyOptions>(options =>
            {
                // This lambda determines whether user consent for non-essential cookies is needed for a given request.
                options.CheckConsentNeeded    = context => true;
                options.MinimumSameSitePolicy = SameSiteMode.None;
            });

            /* Primero, creamos un array con las culturas soportadas. Si se intenta ajustar una cultura que no esté en este array,
            * la aplicación utilizará la cultura por defecto. En nuestro caso hemos definido solo dos culturas, español de España
            * e inglés de Estados Unidos. Fijaos en la forma de definir las culturas, que será la misma forma en la que más adelante
            * pasaremos la cultura a la aplicación: es-ES y en-US. El formato es {ISO 639-1 código de idioma (dos caracteres)}
            * -{ISO 3166-1 código de país (dos caracteres)}. Así, en-GB es inglés de Gran Bretaña, es-AR español de Argentina...*/
            var supportedCultures = new[] { "es-ES", "en-US" };

            /* Cumplimentamos el objeto RequestLocalizationOptions. Le decimos que las culturas soportadas, tanto para UI como para
             * métodos son las definidas en el array anterior. Así mismo, le decimos que la cultura por defecto tanto para la
             * interfaz como para los métodos dependientes de cultura será es-ES (español de España).*/
            var localizationOptions = new RequestLocalizationOptions();

            localizationOptions.AddSupportedCultures(supportedCultures)
            .AddSupportedUICultures(supportedCultures)
            .SetDefaultCulture(supportedCultures[0])
            .RequestCultureProviders.Insert(0, new RouteDataRequestCultureProvider()
            {
                Options = localizationOptions
            });

            /*Guardamos estas opciones en el contenedor de dependencias, pues luego las necesitaremos para satisfacer un parámetro del
             * siguiente método y para pedirlo en uno de nuestros controladores, y así extraer la liD:\ASPNetCore\TrainingNETCore\MvcMovie\Startup.cssta de idiomas soportados:*/
            services.AddSingleton(localizationOptions);

            /*Añadimos todos los servicios necesarios para localizar nuestra aplicación al contenedor de inyección de dependencias,
             * y le decimos que nuestros archivos de recursos estarán en la carpeta Resources*/
            services.AddLocalization(opt => opt.ResourcesPath = "Resources");

            // Añadimos los servicios de MVC, los servicios para localizar las vistas y las Data Anotations.
            services.AddMvc(mvcOptions =>
            {
                //mvcOptions.Filters.Add(typeof(CultureRedirectFilter));
                //Añadimos el filtro cuando configuramos el middleware de MVC
                mvcOptions.Filters.Add(new MiddlewareFilterAttribute(typeof(LocalizationPipeline)));
            }).SetCompatibilityVersion(CompatibilityVersion.Version_2_2)
            .AddViewLocalization(LanguageViewLocationExpanderFormat.Suffix)
            .AddDataAnnotationsLocalization();


            services.AddDbContext <MvcMovieContext>(options =>
                                                    options.UseSqlServer(Configuration.GetConnectionString("MvcMovieContext")));
        }
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            var supportedCultures   = new[] { "es-ES", "en-US" };
            var localizationOptions = new RequestLocalizationOptions();

            localizationOptions.AddSupportedCultures(supportedCultures)
            .AddSupportedUICultures(supportedCultures)
            .SetDefaultCulture(supportedCultures[0]);
            services.AddSingleton(localizationOptions);
            services.AddLocalization(opt => opt.ResourcesPath = "Resources");
            services.AddControllersWithViews().SetCompatibilityVersion(CompatibilityVersion.Version_2_1)
            .AddViewLocalization(LanguageViewLocationExpanderFormat.Suffix)
            .AddDataAnnotationsLocalization();
        }
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.Configure <CookiePolicyOptions>(options =>
            {
                // This lambda determines whether user consent for non-essential cookies is needed for a given request.
                options.CheckConsentNeeded    = context => true;
                options.MinimumSameSitePolicy = SameSiteMode.None;
            });
            var supportedCultures   = new[] { "es-ES", "en-US" };
            var localizationOptions = new RequestLocalizationOptions();

            localizationOptions.AddSupportedCultures(supportedCultures)
            .AddSupportedUICultures(supportedCultures)
            .SetDefaultCulture(supportedCultures[0]);
            services.AddSingleton(localizationOptions);
            services.AddLocalization(opt => opt.ResourcesPath = "Resources");
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1)
            .AddViewLocalization(LanguageViewLocationExpanderFormat.Suffix)
            .AddDataAnnotationsLocalization();
        }
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            var supportedCultures   = new[] { "es-ES", "en-US" };
            var localizationOptions = new RequestLocalizationOptions();

            localizationOptions.AddSupportedCultures(supportedCultures)
            .AddSupportedUICultures(supportedCultures)
            .SetDefaultCulture(supportedCultures[0])
            .RequestCultureProviders.Insert(0, new RouteDataRequestCultureProvider()
            {
                Options = localizationOptions
            });
            services.AddSingleton(localizationOptions);
            services.AddLocalization(opt => opt.ResourcesPath = "Resources");
            services.AddControllersWithViews(mvcOptions =>
            {
                mvcOptions.Filters.Add(typeof(CultureRedirectFilter));
            }).SetCompatibilityVersion(CompatibilityVersion.Version_2_1)
            .AddViewLocalization(LanguageViewLocationExpanderFormat.Suffix)
            .AddDataAnnotationsLocalization();
        }
Beispiel #9
0
        public void Configuration(IAppBuilder app)
        {
            var builder = new ContainerBuilder();

            builder.RegisterType <TestCultureProvider>().InstancePerLifetimeScope();

            var container = builder.Build();

            app.UseAutofacMiddleware(container);

            var options = new RequestLocalizationOptions()
                          .UseAutofacInjection();

            options.AddSupportedCultures("en-US", "de");
            options.AddSupportedUICultures("en-US", "de");
            options.RequestCultureProviders.Clear();
            options.AddInjectedProvider <TestCultureProvider>();



            app.UseRequestLocalization(options);
        }