March 2012
M T W T F S S
« Jan   Apr »
 1234
567891011
12131415161718
19202122232425
262728293031  

Categories

<!–:ja–>ASP.NET国際化プログラミング – リソース管理<!–:–><!–:en–>ASP.NET Internationalization Programming – Resource Administration<!–:–>

The following are extracts from ASP.NET Internationalization of Software Internationalization Tool World Wide Navi‘s Internationalization Programming Advisory Info.

ASP.NET uses resx resources (About resx, see Resource Administration, .NET chapter) for internationalization in some different ways from C# and other .NET programming languages.

This page describes its unique points with World Wide Navi string externalization samples.

1. Adding headers in ASPX

Add culture (language and region) settings to ASPX header area.

Default.aspx

  <%@ Page  Language="C#" ...%>
=><%@ Page  Culture="auto"
UICulture="auto" Language="C#" ...%>

2. String Externalization (literal replacement)

ASP.NET has 4 syntaxes for string resource handling.

  • Syntax 1 needs ‘<%=..%>’.
  • ‘”‘ are truncated in Syntax 2.
  • Syntax 3 is very similar to syntax 1, but some different.
  • The default text can remain adding meta in Syntax 4.
  • Syntax 3 & 4 can be used for ASP tags only.
Default.aspx

* Syntax 1. (tag text replacement)
 '<%=' + 'Resources.Default.' + RESOURCE_KEY + '%>'
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>This is a sample site!</title>
 => <title><%=Resources.Default.
DefaultWwnaviMsg1%></title>
</head>
<body>

* Syntax 2. (program literal replacement)
'Resources.Default.' + RESOURCE_KEY
<div>
    <% Response.Write("Hello, World!"); %>
 => <% Response.Write(Resources.
Default.DefaultWwnaviMsg2); %>
</div> 

* Syntax 3. (text replacement in ASP tag)
 '<%$' + 'Resources.Default,' + RESOURCE_KEY + '%>'
<asp:Label ID="Label1" runat="server"
Text="This is label 1.">
=><asp:Label ID="Label1" runat="server"
Text="<%$Resources:Default,
DefaultWwnaviMsg3%>">
</asp:Label>

* Syntax 4. (meta insertion in ASP tag)
 'meta:resourcekey="' + RESOURCE_KEY + '"'
<asp:Label ID="Label1" runat="server"
Text="This is label 1.">
=><asp:Label ID="Label2" runat="server"
 Text="This is label 1."
meta:resourcekey="DefaultWwnaviMsg4" >
</asp:Label>

You need to use proper process for each string based on its location.

(You can choose either 3 or 4 in ASP tags.)

3. Creating Resx Files

Put externalized strings into resx (resource) files.You need to create ‘App_GlobalResources’ folder under your project directory and put resx files there named ‘ASPX_FILE_NAME(without extension).resx’(*1).

PROJECT_DIRECTORY
    -  App_GlobalResources
         -  Default.resx
         -  WebForm1.resx
         *1)If you use syntax 4 (meta attribute),
           you heed to add extension
           (Default.aspx.resx).
Default.resx 

<?xml version="1.0" encoding="utf-8"?>
<root>
  <xsd:schema id="root" xmlns=""
  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
    ...
  </xsd:schema>
  ...
  <resheader name="writer">
    <value>System.Resources.ResXResourceWriter,
     System.Windows.Forms, Version=2.0.0.0,
     Culture=neutral,
     PublicKeyToken=b77a5c561934e089</value>
  </resheader>
  <data name="DefaultWwnaviMsg1" xml:space="preserve">
     (RESOURCE_KEY)
    <value>This is a sample site!</value>
     (RESOURCE_STRING)
  </data>
</root>

4. Compiling and localization

Build and run, you will see the resource strings shown in browser.If you want to add other language resources, put ASPX_FILE_NAME.LOCALE_CODE(e.g. ‘ja’).resx in App_GlobalResources.

App_GlobalResources
  -  Default.resx
    ... master resource (e.g. English)
  -  Default.ja.resx
    ... localized resource (e.g. Japanese)


Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>