{"id":394,"date":"2009-02-22T14:39:07","date_gmt":"2009-02-22T19:39:07","guid":{"rendered":"http:\/\/williamsportwebdeveloper.com\/cgi\/wp\/?p=394"},"modified":"2019-12-02T13:44:23","modified_gmt":"2019-12-02T18:44:23","slug":"aspnet-20-culture-%e2%80%93-web-site-internationalization","status":"publish","type":"post","link":"http:\/\/williamsportwebdeveloper.com\/cgi\/wp\/?p=394","title":{"rendered":"ASP.NET 2.0 Culture &#8211; Web Site Internationalization"},"content":{"rendered":"<p>Last night I watched the movie <strong>Paris, Je T&#8217;Aime<\/strong>, a collection of short films set in various arrondissements. This is undoubtedly one of the best recent films to see before you travel to Paris. I especially liked the short film <em>14e arrondissement (XIVe arrondissement)<\/em> &#8211; written and directed by Alexander Payne. It is a brutally honest and mundane vignette about a middle-aged American mail carrier from Denver on vacation in Paris who is sad that she has to experience it alone. It is narrated in her atrocious attempt at French. This will probably be embarrassingly similar to my experience!<\/p>\n<div id=\"scid:7dc1bd33-94bd-46fd-a20b-0131235bcd47:6704d37d-049d-428f-9f99-4f3cfb3b4f3f\" class=\"wlWriterEditableSmartContent\" style=\"margin: 0px; display: inline; float: none; padding: 0px;\">\n<table border=\"0\" width=\"400\" cellspacing=\"0\" cellpadding=\"2\">\n<tbody>\n<tr>\n<td valign=\"top\" width=\"400\"><a title=\"Paris, Je T'Aime (Two Disc Limited Collector's Edition): Fanny Ardant, Juliette Binoche, Steve Buscemi, Willem Dafoe, Marianne Faithfull, Ben Gazzara, Maggie Gyllenhaal, Bob Hoskins, Margo Martindale, Yolande Moreau, Nick Nolte, Miranda Richardson, Gena Rowlands, Ludivine Sagnier, Rufus Sewell, Elijah Wood, Sergio Castellitto, G\u00e9rard Depardieu, Barbet Schroeder, Natalie Portman, Pierre Adenot, Olivier Assayas: Movies &amp; TV\" href=\"http:\/\/www.amazon.com\/exec\/obidos\/ASIN\/B000V6FVN4\/robertrobbins-20\"><img decoding=\"async\" style=\"float: left;\" src=\"http:\/\/images.amazon.com\/images\/P\/B000V6FVN4.01.MZZZZZZZ.jpg\" align=\"left\" border=\"0\" \/>Paris, Je T&#8217;Aime (Two Disc Limited Collector&#8217;s Edition): Fanny Ardant, Juliette Binoche, Steve Buscemi, Willem Dafoe, Marianne Faithfull, Ben Gazzara, Maggie Gyllenhaal, Bob Hoskins, Margo Martindale, Yolande Moreau, Nick Nolte, Miranda Richardson, Gena Rowlands, Ludivine Sagnier, Rufus Sewell, Elijah Wood, Sergio Castellitto, G\u00e9rard Depardieu, Barbet Schroeder, Natalie Portman, Pierre Adenot, Olivier Assayas: Movies &amp; TV<\/a><\/p>\n<p><b>ASIN<\/b>: B000V6FVN4<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>However, this blog post is about the technical issues of web development for international sites. I&#8217;ve never been asked to give any consideration to foreign languages or cultures in my work because I haven&#8217;t worked on any major web sites that are intended to serve the world market. I&#8217;ve mostly done back end administration sites which certainly don&#8217;t need to be bilingual. Web developers have enough headaches just making sure web sites appear the same in every browser without worrying about a number of foreign languages in addition to that.<\/p>\n<p>Fortunately ASP.NET is slightly more advanced than other web development frameworks in this regard. If you want your web page to format dates, times, and currency for France you just need to set the culture in the page directive:<\/p>\n<div style=\"line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; font-family: consolas, 'Courier New', courier, monospace; height: 36px; max-height: 200px; font-size: 8pt; overflow: auto; cursor: text; border: gray 1px solid; padding: 4px;\">\n<div style=\"line-height: 12pt; background-color: #f4f4f4; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">\n<pre style=\"line-height: 12pt; background-color: white; margin: 0em; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\"><span style=\"color: #606060;\">   1:<\/span> <span style=\"color: #0000ff;\">&lt;% <\/span><span style=\"color: #800000;\">Page<\/span> <span style=\"color: #ff0000;\">Language<\/span><span style=\"color: #0000ff;\">=\"VB\"<\/span> <span style=\"color: #ff0000;\">MasterPageFile<\/span><span style=\"color: #0000ff;\">=\"~\/Default.master\"<\/span> <span style=\"color: #ff0000;\">Culture<\/span><span style=\"color: #0000ff;\">=\"fr-FR\"<\/span> <span style=\"color: #ff0000;\">UICulture<\/span><span style=\"color: #0000ff;\">=\"fr-FR\"<\/span> <span style=\"color: #ff0000;\">AutoEventWireup<\/span><span style=\"color: #0000ff;\">=\"false\"<\/span> <span style=\"color: #ff0000;\">CodeFile<\/span><span style=\"color: #0000ff;\">=\"Langue.aspx.vb\"<\/span> <span style=\"color: #ff0000;\">Inherits<\/span><span style=\"color: #0000ff;\">=\"Langue\"<\/span> <span style=\"color: #ff0000;\">title<\/span><span style=\"color: #0000ff;\">=\"French Culture Test Page\"<\/span> <span style=\"color: #0000ff;\"> %&gt;<\/span><\/pre>\n<\/div>\n<\/div>\n<p>The Internet-standard string that identifies the French language is <strong>fr-FR<\/strong> (French in France). <strong>fr-CA<\/strong> would be French in Canada. This changes the display of full dates to something like <em>mercredi 18 f\u00e9vrier 2009<\/em>, short dates to <em>18\/02\/2009<\/em>, short times to something like 15:21, and currency amounts to 56,95. Notice how the full date automatically uses the French words for the weekday and the month without any effort on your part. The short date places the day before the month in the European fashion. The time is in military time because the French do not use AM and PM. And the currency uses a comma instead of a period and automatically added the Euro symbol.<\/p>\n<p>You could also set the <strong>Culture<\/strong> and\u00a0 <strong>UICulture<\/strong> attributes to &#8220;auto&#8221; and get the same effect if your browser language is set to fr-FR. However changing your browser language can have unintended consequences as every web site you visit may redirect you to a French version of the site or display some things in the French format. It does give you a good way to test sites for internationalization. It is surprising how many sites use country flags to direct visitors to translated pages when they should just use the browser&#8217;s language settings to determine this.<\/p>\n<p>If you want to dynamically replace strings with foreign words or phrases then you&#8217;ll have to do a lot more work. ASP.NET 2.0 provides a standard way of accomplishing this using local resource files. First you have to create an ASP.NET Folder for this. Right click your project in Solution Explorer and select Add ASP.NET Folder, select <em>App_LocalResources<\/em>. Then with an ASP.NET page in design view, select Tools &gt; Generate Local Resource. This command automates the creation of a local resource file for the default culture. It also adds <strong>meta:resourcekey<\/strong> attributes throughout the page and creates corresponding string values in the local resource file to act as targets for <strong>meta:resourcekey<\/strong> attribute entries. That should give you the English version of your page.<\/p>\n<p>To create a French version of the page you&#8217;ll have to create a local resource file containing French resources. You need a resource file named <strong>Default.aspx.fr.resx<\/strong> for Firefox and a resource file named <strong>Default.aspx.fr-FR.resx<\/strong> for Internet Explorer. When you open the resx resource files in Visual Studio you&#8217;ll see a lot of name \/ value pairs where the name will be the name of a web control and the value will be the foreign words you want to appear there.\u00a0 If you want to localize static content you can use the special ASP.NET tag <strong>asp:Localize<\/strong> for anything which does not get referenced in the code behind page.<\/p>\n<div style=\"line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; font-family: consolas, 'Courier New', courier, monospace; max-height: 200px; font-size: 8pt; overflow: auto; cursor: text; border: gray 1px solid; padding: 4px;\">\n<div style=\"line-height: 12pt; background-color: #f4f4f4; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">\n<pre style=\"line-height: 12pt; background-color: white; margin: 0em; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\"><span style=\"color: #606060;\">   1:<\/span> <span style=\"color: #0000ff;\">&lt;<\/span><span style=\"color: #800000;\">asp:Localize<\/span> <span style=\"color: #ff0000;\">ID<\/span><span style=\"color: #0000ff;\">=\"Localize1\"<\/span> <span style=\"color: #ff0000;\">runat<\/span><span style=\"color: #0000ff;\">=\"server\"<\/span> <span style=\"color: #ff0000;\">meta:resourcekey<\/span><span style=\"color: #0000ff;\">=\"Localize1\"<\/span><span style=\"color: #0000ff;\">&gt;&lt;\/<\/span><span style=\"color: #800000;\">asp:Localize<\/span><span style=\"color: #0000ff;\">&gt;<\/span><\/pre>\n<\/div>\n<\/div>\n<p>PHP does not have a standard way to do this kind of localization. You&#8217;ll find various methods for replacing language specific strings in different web applications should they be language aware. For example, Elgg uses a language folder where you place PHP files, each defining an array of phrases for a particular language. Then your other PHP files must use the key name to get the array value which will be a string in the target language. This is very similar to ASP.NET&#8217;s approach but other PHP web applications use entirely different methods.<\/p>\n<p>I will be doing additional research on this topic as I spend more time brushing up on my French.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Last night I watched the movie Paris, Je T&#8217;Aime, a collection of short films set in various arrondissements. This is undoubtedly one of the best recent films to see before you travel to Paris. I especially liked the short film &hellip; <a href=\"http:\/\/williamsportwebdeveloper.com\/cgi\/wp\/?p=394\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,1,12,11],"tags":[1143,1156,244,245,1145],"_links":{"self":[{"href":"http:\/\/williamsportwebdeveloper.com\/cgi\/wp\/index.php?rest_route=\/wp\/v2\/posts\/394"}],"collection":[{"href":"http:\/\/williamsportwebdeveloper.com\/cgi\/wp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/williamsportwebdeveloper.com\/cgi\/wp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/williamsportwebdeveloper.com\/cgi\/wp\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/williamsportwebdeveloper.com\/cgi\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=394"}],"version-history":[{"count":6,"href":"http:\/\/williamsportwebdeveloper.com\/cgi\/wp\/index.php?rest_route=\/wp\/v2\/posts\/394\/revisions"}],"predecessor-version":[{"id":2957,"href":"http:\/\/williamsportwebdeveloper.com\/cgi\/wp\/index.php?rest_route=\/wp\/v2\/posts\/394\/revisions\/2957"}],"wp:attachment":[{"href":"http:\/\/williamsportwebdeveloper.com\/cgi\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=394"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/williamsportwebdeveloper.com\/cgi\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=394"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/williamsportwebdeveloper.com\/cgi\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=394"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}