{"id":627,"date":"2019-09-25T15:07:25","date_gmt":"2019-09-25T06:07:25","guid":{"rendered":"http:\/\/csharp.ihavenomoney.co.kr\/?p=627"},"modified":"2019-09-25T15:20:58","modified_gmt":"2019-09-25T06:20:58","slug":"localization-2","status":"publish","type":"post","link":"https:\/\/csharp.ihavenomoney.co.kr\/?p=627","title":{"rendered":"localization-2"},"content":{"rendered":"\n<pre class=\"lang:c# decode:true \" >using Microsoft.AspNetCore.Hosting; \/\/IWebHostBuilder\r\nusing Microsoft.AspNetCore.Builder; \/\/IApplicationBuilder\r\nusing Microsoft.AspNetCore.Http; \/\/WriteAsync\r\nusing Microsoft.AspNetCore; \/\/webHost\r\nusing Microsoft.Extensions.Logging;\/\/ILoggerFactory\r\nusing Microsoft.Extensions.DependencyInjection; \/\/ IServiceCollection\r\nusing System.Globalization;\r\nusing System.Collections.Generic;\r\nusing Microsoft.AspNetCore.Localization;\r\nusing Microsoft.Extensions.Localization;\r\n\r\nnamespace WebApplication1\r\n{\r\n    public class Startup\r\n    {\r\n        public Startup(IHostingEnvironment env, ILoggerFactory logger)\r\n        {\r\n            \/\/These are two services available at constructor\r\n        }\r\n\r\n        public void ConfigureServices(IServiceCollection services)\r\n        {   \r\n            services.AddLocalization(optipns =&gt; optipns.ResourcesPath = \"resources\"); \/\/ resources path \r\n        }\r\n\r\n        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory logger, IStringLocalizerFactory stringLocalizerFactory)\r\n        {\r\n            var local = stringLocalizerFactory.Create(\"Common\", typeof(Program).Assembly.FullName);\r\n\r\n            var supportedCultures = new List&lt;CultureInfo&gt;\r\n            {\r\n                new CultureInfo(\"fr-FR\"),\r\n                new CultureInfo(\"en-US\")\r\n            };\r\n\r\n            var options = new RequestLocalizationOptions\r\n            {\r\n                DefaultRequestCulture = new RequestCulture(\"fr-FR\"),\r\n                SupportedCultures = supportedCultures,\r\n                SupportedUICultures = supportedCultures\r\n            };\r\n\r\n            app.UseRequestLocalization(options);\r\n            \r\n            app.Run(async context =&gt;\r\n            {\r\n                await context.Response.WriteAsync(\"&lt;h1&gt;QueryStringRequestCultureProvider&lt;\/h1&gt;&lt;p&gt;We are using query string to switch the request culture.&lt;\/p&gt;\");\r\n\r\n                var requestCulture = context.Features.Get&lt;IRequestCultureFeature&gt;().RequestCulture;\r\n                \r\n                \/\/if (requestCulture.Culture.TwoLetterISOLanguageName != \"fr\")\r\n                \/\/    await context.Response.WriteAsync($\"<a href=\\\"\/?culture=fr-FR&#038;ui-culture=fr-FR\\\">Switch to French<\/a><br\/>\");\r\n                \/\/else if (requestCulture.Culture.TwoLetterISOLanguageName != \"en\")\r\n                \/\/    await context.Response.WriteAsync($\"<a href=\\\"\/?culture=en-US&#038;ui-culture=en-US\\\">Switch to English<\/a><br\/>\");\r\n\r\n                \/\/await context.Response.WriteAsync($@\"\r\n                \/\/    Request Culture: {requestCulture.Culture} <br\/> \r\n                \/\/    Localized strings: {local[\"Hello\"]} {local[\"Goodbye\"]} {local[\"Yes\"]} {local[\"No\"]}\r\n                \/\/    \");\r\n\r\n                await context.Response.WriteAsync($@\"\r\n                <a href=\"\"\/?culture=fr-FR&#038;ui-culture=fr-FR\"\">Culture FR - UI Culture GB<\/a><br\/>\r\n                <a href=\"\"\/?culture=en-US&#038;ui-culture=en-US\"\">Culture US - UI Culture US<\/a><br\/>\r\n                <br\/>\r\n                Request Culture: {requestCulture.Culture} <br\/>\r\n                Today's Date (Culture): {DateTime.Now.ToString()}<br\/><br\/>\r\n                Request UI Culture: {requestCulture.UICulture}<br\/> \r\n                Localized strings (UI Culture): {local[\"Hello\"]} {local[\"Goodbye\"]} {local[\"Yes\"]} {local[\"No\"]}\r\n                \");\r\n            });\r\n        }\r\n    }\r\n    public class Program\r\n    {\r\n        public static void Main(string[] args)\r\n        {\r\n            CreateWebHostBuilder(args).Build().Run();\r\n        }\r\n\r\n        public static IWebHostBuilder CreateWebHostBuilder(string[] args) =&gt;\r\n            WebHost.CreateDefaultBuilder(args)\r\n                .UseStartup&lt;Startup&gt;()\r\n                .UseEnvironment(\"Development\");\r\n    }\r\n}<\/pre>\n<p>:: resources :: Common.fr-FR.resx<br \/>\nGoodbye Au Revoir<br \/>\nHello Bonjour<br \/>\nNo Non<br \/>\nYes Oui<\/p>\n<p>:: Goodbye Howdy :: Common.en-US.resx<br \/>\nHello  So long<br \/>\nNo Yah<br \/>\nYes Nope <\/p>\n<p>\uacb0\uacfc :<br \/>\nQueryStringRequestCultureProvider<\/p>\n<p>We are using query string to switch the request culture.<br \/>\nCulture FR &#8211; UI Culture GB<br \/>\nCulture US &#8211; UI Culture US<\/p>\n<p>Request Culture: fr-FR<br \/>\nToday&#8217;s Date (Culture): 25\/09\/2019 15:19:06<\/p>\n<p>Request UI Culture: fr-FR<br \/>\n Localized strings (UI Culture): Bonjour Au Revoir Oui Non <\/p>\n<p>\uc8fc\uc11d \uacb0\uacfc :<br \/>\nQueryStringRequestCultureProvider<\/p>\n<p>We are using query string to switch the request culture.<br \/>\nSwitch to English<br \/>\nRequest Culture: fr-FR<br \/>\n Localized strings: Bonjour Au Revoir Oui Non <\/p>\n<p>QueryStringRequestCultureProvider<\/p>\n<p>We are using query string to switch the request culture.<br \/>\nSwitch to French<br \/>\nRequest Culture: en-US<br \/>\n Localized strings: Howdy So long Yah Nope <\/p>\n","protected":false},"excerpt":{"rendered":"<p>using Microsoft.AspNetCore.Hosting; \/\/IWebHostBuilder using Microsoft.AspNetCore.Builder; \/\/IApplicationBuilder using Microsoft.AspNetCore.Http; \/\/WriteAsync using Microsoft.AspNetCore; \/\/webHost using Microsoft.Extensions.Logging;\/\/ILoggerFactory using Microsoft.Extensions.DependencyInjection; \/\/ IServiceCollection using System.Globalization; using System.Collections.Generic; using Microsoft.AspNetCore.Localization; using Microsoft.Extensions.Localization; namespace WebApplication1 { public class Startup { public Startup(IHostingEnvironment env, ILoggerFactory logger) { \/\/These are two services available at constructor } public void ConfigureServices(IServiceCollection services) { services.AddLocalization(optipns =&gt; optipns.ResourcesPath\u2026 <span class=\"read-more\"><a href=\"https:\/\/csharp.ihavenomoney.co.kr\/?p=627\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[108],"tags":[],"class_list":["post-627","post","type-post","status-publish","format-standard","hentry","category-net-core"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/csharp.ihavenomoney.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/627","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/csharp.ihavenomoney.co.kr\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/csharp.ihavenomoney.co.kr\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/csharp.ihavenomoney.co.kr\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/csharp.ihavenomoney.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=627"}],"version-history":[{"count":5,"href":"https:\/\/csharp.ihavenomoney.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/627\/revisions"}],"predecessor-version":[{"id":633,"href":"https:\/\/csharp.ihavenomoney.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/627\/revisions\/633"}],"wp:attachment":[{"href":"https:\/\/csharp.ihavenomoney.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=627"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/csharp.ihavenomoney.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=627"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/csharp.ihavenomoney.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=627"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}