Ejemplo n.º 1
0
        public IActionResult Index()
        {
            var Test = MyStaticLocalizer.localizer("Product");

            ViewBag.Product = _localizer.GetLocalizedHtmlString("Product");

            return(View());
        }
Ejemplo n.º 2
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }

            app.UseHttpsRedirection();
            app.UseStaticFiles();
            app.UseRouting();
            app.UseAuthorization();

            //
            HttpHelper.Configure(app.ApplicationServices.GetRequiredService <IHttpContextAccessor>());               //MyStaticHelper yerine bunu kullanabilirsiniz.
            MyStaticLocalizer.Configure(app.ApplicationServices.GetRequiredService <IdentityLocalizationService>()); //Localizer static.

            //
            var options = app.ApplicationServices.GetService <IOptions <RequestLocalizationOptions> >();

            app.UseRequestLocalization(options.Value);
            var DefaultBrowserLanguage = options.Value.DefaultRequestCulture.Culture.TwoLetterISOLanguageName;

            //
            app.UseEndpoints(endpoints =>
            {
                //Language TranslationRoute
                endpoints.MapDynamicControllerRoute <TranslationTransformer>("{lang:lang}/{controller=Home}/{action=Index}/{id?}");
                endpoints.MapDynamicControllerRoute <TranslationTransformer>("{**slug}");

                // Test Route
                endpoints.MapControllerRoute(name: "blog",
                                             pattern: "{lang:lang}/blog/{*article}",
                                             defaults: new { controller = "Blog", action = "Article" });

                // General Route
                endpoints.MapControllerRoute(
                    name: "LocalizedDefault",
                    pattern: "{lang:lang}/{controller=Home}/{action=Index}/{id?}");

                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{*catchall}",
                    defaults: new { controller = "Home", action = "RedirectToDefaultLanguage", lang = DefaultBrowserLanguage });
            });
        }