{"id":623,"date":"2019-09-25T14:51:54","date_gmt":"2019-09-25T05:51:54","guid":{"rendered":"http:\/\/csharp.ihavenomoney.co.kr\/?p=623"},"modified":"2019-09-25T14:58:36","modified_gmt":"2019-09-25T05:58:36","slug":"localization","status":"publish","type":"post","link":"https:\/\/csharp.ihavenomoney.co.kr\/?p=623","title":{"rendered":"localization"},"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            };\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                var requestCulture = context.Features.Get&lt;IRequestCultureFeature&gt;();\r\n                await context.Response.WriteAsync($\"{requestCulture.RequestCulture.Culture} - {local[\"Hello\"]} {local[\"Goodbye\"]} {local[\"Yes\"]} {local[\"No\"]}\");\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 ::<br \/>\nGoodbye  Au Revoir<br \/>\nHello    Bonjour<br \/>\nNo       Non<br \/>\nYes      Oui<\/p>\n<p>\uacb0\uacfc :  fr-FR &#8211; Bonjour Au Revoir Oui Non<\/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=623\">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-623","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\/623","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=623"}],"version-history":[{"count":3,"href":"https:\/\/csharp.ihavenomoney.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/623\/revisions"}],"predecessor-version":[{"id":626,"href":"https:\/\/csharp.ihavenomoney.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/623\/revisions\/626"}],"wp:attachment":[{"href":"https:\/\/csharp.ihavenomoney.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=623"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/csharp.ihavenomoney.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=623"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/csharp.ihavenomoney.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=623"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}