Trying localization with Sams Tips&Tricks

G

Guest

Hi,

I have a very good book on asp.net Sams ASP.NET Tips, Tutorials and Code
ISBN 0-672-32143-2 and is trying to teach myself from examples from this book
Chapter 16.

Anyway I come quite close when trying to run one example but then I get this
message I don't understand:

"This .resources file shouldn't be used with this reader. Your resource
reader type: System.Resources.ResourceReader, mscorlib, Version=1.0.2411.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089"

What does it mean?

Seems my english isn't good enough.

TIA

Kenneth P
 
G

Guest

Hmmm...

Where should I post it, because it contains five very small (1kb) compiled
resource files as well as the code?

Kenneth P
 
G

Guest

Sure, why not,

Here's the code for the .aspx, named 16.3.2.aspx

<%@ Page Inherits="myCodeBehind_1633" Src="16.3.3.vb"
ResponseEncoding="utf-8" %>
<html>
<head>
<title>Using Resource Files in ASP.NET</title>
</head>
<body style="FONT: x-small Verdana, Arial, sans-serif">
<form method="post" runat="server">
<b>The Current Culture is:</b>
<asp:Label id="CultureType" runat="server"></asp:Label>
<hr />
<p>
<b>
<asp:Label id="Welcome" runat="server"></asp:Label>
</b>
</p>
<p>
<b>
<asp:Label id="Choose" runat="server"></asp:Label>
</b>
<asp:DropDownList id="EncodType" runat="server"
AutoPostBack="True">
<asp:ListItem Value="en-US" Text="English" />
<asp:ListItem Value="en-NZ" Text="English (New Zealand)" />
<asp:ListItem Value="fr-FR" Text="French" />
<asp:ListItem Value="de-DE" Text="German" />
<asp:ListItem Value="he-IL" Text="Hebrew" />
<asp:ListItem Value="ja-JP" Text="Japanese" />
<asp:ListItem Value="es-MX" Text="Spanish (Mexican)" />
<asp:ListItem Value="uk-UA" Text="Ukrainian (Ukraine)" />
</asp:DropDownList>
</p>
<asp:DataGrid id="myDataGrid" runat="server"
AutoGenerateColumns="False" HeaderStyle-ForeColor="White"
HeaderStyle-BackColor="Black" Font-Size="8pt" Font-Name="Verdana"
ShowFooter="false" BorderColor="black" Width="740">
<Columns>
<asp:BoundColumn DataField="FirstName" />
<asp:BoundColumn DataField="LastName" />
<asp:BoundColumn DataField="BirthDate"
DataFormatString="{0:D}" />
<asp:BoundColumn DataField="HireDate"
DataFormatString="{0:D}" />
</Columns>
</asp:DataGrid>
</form>
</body>
</html>

and here's the code behind file 16.3.3.vb

Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls
Imports System.Globalization
Imports System.Threading
Imports System.Resources
Imports System.IO

Public Class myCodeBehind_1633 : Inherits Page

Public myDataGrid As DataGrid
Public EncodType As DropDownList
Public CultureType As Label
Public Choose As Label
Public Welcome As Label
Public rm As ResourceManager =
ResourceManager.CreateFileBasedResourceManager("myResourceFile",
Server.MapPath("/resources") & Path.DirectorySeparatorChar, Nothing)

Public Sub Page_Load(Sender As Object, E As EventArgs)
Dim culture As CultureInfo
Dim myDataAdapter As SqlDataAdapter
Dim myDataSet As New DataSet

If Not Page.IsPostBack Then
culture = CultureInfo.CurrentCulture
Else
culture = New CultureInfo(EncodType.SelectedItem.Value)
Thread.CurrentThread.CurrentCulture = culture
End If

CultureType.Text = culture.EnglishName
Welcome.Text = rm.GetString("Greeting", culture)
Choose.Text = rm.GetString("EncMessage", culture)

myDataGrid.Columns(0).HeaderText = rm.GetString("FirstName", culture)
myDataGrid.Columns(1).HeaderText = rm.GetString("LastName", culture)
myDataGrid.Columns(2).HeaderText = rm.GetString("BirthDate", culture)
myDataGrid.Columns(3).HeaderText = rm.GetString("HireDate", culture)

myDataAdapter = New SqlDataAdapter("Select LastName, FirstName,
BirthDate, HireDate From Employees", _
"server=localhost;database=Northwind;uid=sa;pwd=ohlywohly;")
myDataAdapter.Fill(myDataSet, "Employees")

myDataGrid.DataSource = myDataSet.Tables("Employees").DefaultView
myDataGrid.DataBind()
End Sub

End Class

and here's the code for the five resources files. you have to compile them
first before using them using

resgen
C:\Inetpub\wwwroot\Sams\TipsTricks\C16\resources\myResourceFile.de-DE.txt
C:\Inetpub\wwwroot\Sams\TipsTricks\C16\resources\myResourceFile.de-DE.resources

resgen
C:\Inetpub\wwwroot\Sams\TipsTricks\C16\resources\myResourceFile.fr-FR.txt
C:\Inetpub\wwwroot\Sams\TipsTricks\C16\resources\myResourceFile.fr-FR.resources

resgen
C:\Inetpub\wwwroot\Sams\TipsTricks\C16\resources\myResourceFile.en-NZ.txt
C:\Inetpub\wwwroot\Sams\TipsTricks\C16\resources\myResourceFile.en-NZ.resources

resgen
C:\Inetpub\wwwroot\Sams\TipsTricks\C16\resources\myResourceFile.es-MX.txt
C:\Inetpub\wwwroot\Sams\TipsTricks\C16\resources\myResourceFile.es-MX.resources

resgen C:\Inetpub\wwwroot\Sams\TipsTricks\C16\resources\myResourceFile.txt
C:\Inetpub\wwwroot\Sams\TipsTricks\C16\resources\myResourceFile.resources

first 'myResourceFile.de-DE.txt'

[strings]
Greeting = Willkommen!
FirstName = Vorname
LastName = Familienname
BirthDate = Geburtsdatum
HireDate = Miete-Datum
EncMessage = Wählen Sie Ihre Verschlüsselung:

and then no two with the name 'myResourceFile.en-NZ.txt'

[strings]
Greeting = Good Day!

and number three 'myResourceFile.es-MX.txt'

[strings]
Greeting = Bienvenido!
FirstName = Nombre de pila
LastName = Apellido
BirthDate = Fecha de Nacimiento
HireDate = Fecha de Alquiler
EncMessage = Escoja su codificación:

number four: 'myResourceFile.fr-FR.txt'

[strings]
Greeting = Accueil!
FirstName = Prénom
LastName = Nom de famille
BirthDate = Date de Naissance
HireDate = Date de Location
EncMessage = Choisissez votre codage:

and at last number 5: 'myResourceFile.txt'

[strings]
;
; lines beginning with semi-colons are treated as comments
;
; Specify a locale-specific welcome message
Greeting = Welcome!
;
; Create locale-specific header text for our DataGrid
FirstName = First Name
LastName = Last Name
BirthDate = Birth Date
HireDate = Hire Date
;
; Create locale-specific text for our Label
EncMessage = Choose your encoding:

The .resources files should be saved to a /resources directory below the
root directory.

Kenneth P.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top