Globalization not working as intended when using da-DK

B

Basildk

Hi.

I have a strange problem. We have an asp.net application running on
several server with different setups.
On 2 of our servers we experience that the globalization settings are
misbehaving.

We have boiled the problem down to this: (exemplified by a very simple
page)

protected void Page_Load(object sender, EventArgs e)
{
Response.Write(Thread.CurrentThread.CurrentCulture.Name + "<br />");
Response.Write(2.ToString("c", Thread.CurrentThread.CurrentCulture) +
"<br />");
Response.Write(DateTime.Now.ToString() + "<br />");
}

Output is the following:
da-DK
$2.00
8/30/2007 5:14:02 PM

Since currentCulture is "da-DK" i would have expected the something
like the following:
kr 2.00
30-08-2007
This is in fact the result coming from the servers that are working.

How come the Culture is not formatting the values correctly?

Thanks for the help..
 
B

Basildk

I just tried setting CurrentUICulture to "da-DK", but with the same
result..

I researched a little further:
If i insert the following code:
Response.Write("Language " + cultureInfo.Name + "<br />");
Response.Write("---------------------------------<br />");
Response.Write("CurrencySymbol " +
cultureInfo.NumberFormat.CurrencySymbol.ToString() + "<br />");
Response.Write("DateSeparator " +
cultureInfo.DateTimeFormat.DateSeparator + "<br />");
Response.Write("LongDatePattern " +
cultureInfo.DateTimeFormat.LongDatePattern.ToString() + "<br />");
Response.Write("ShortDatePattern " +
cultureInfo.DateTimeFormat.ShortDatePattern.ToString() + "<br />");
string[] days = cultureInfo.DateTimeFormat.DayNames;
for( int i = 0; i < days.Length; i++)
{
Response.Write(days + "<br />");
}
Response.Write("---------------------------------<br />");


I get the following output:

Language da-DK
---------------------------------
CurrencySymbol $
DateSeparator /
LongDatePattern dddd, MMMM dd, yyyy
ShortDatePattern M/d/yyyy
søndag
mandag
tirsdag
onsdag
torsdag
fredag
lørdag

In other words: Some of the values are perfect danish (the days) while
others are stille american (datepattern, dateseperator and
currencySymbol)
I am puzzled:)
 
J

Juan T. Llibre

See if this sample code helps...

cultureChange.aspx:
-----------------------------
<%@ Page Language="VB" uiculture="auto" %>
<%@ Import Namespace="System.Threading" %>
<%@ Import Namespace="System.Globalization" %>

<script runat="server">
Protected Overrides Sub InitializeCulture()
If Request.Form("ListBox1") IsNot Nothing Then
Dim selectedLanguage As String = Request.Form("ListBox1")
UICulture = Request.Form("ListBox1")
Culture = Request.Form("ListBox1")
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(selectedLanguage)
Thread.CurrentThread.CurrentUICulture = New CultureInfo(selectedLanguage)
End If
MyBase.InitializeCulture()
End Sub
Sub Page_Load(obj as object, e as eventargs)
Dim value as Double = 2.0
Dim s as String 'create a string and format it as currency.
s = String.Format("{0:c}", value)
lblMessage.Text = Listbox1.SelectedItem.Text
lblMessage2.Text = Listbox1.SelectedItem.Value & " " & DateTime.Now & " " & s

End Sub
</script>
<html>
<body>
<form id="form1" runat="server">
<div>
<asp:ListBox ID="ListBox1" runat="server">
<asp:ListItem Value="en-US" Selected="True">English</asp:ListItem>
<asp:ListItem Value="es-MX">Español</asp:ListItem>
<asp:ListItem Value="da-DK">Danish</asp:ListItem>
</asp:ListBox><br />
<asp:Button ID="Button1" runat="server"
Text="Set Language/Culture"
meta:resourcekey="Button1" />
<br />
<asp:Label ID="Label1" runat="server"
Text=""
meta:resourcekey="Label1" />
</div>
<div>
<asp:Label id="lblMessage" runat="server"/></asp:Label> <br />
<asp:Label id="lblMessage2" runat="server"/></asp:Label> <br />
</div>

</form>
</body>
</html>
----------

That code changes the culture/language on demand...

If you select Danish and click the Button, you'll see kr displayed, and the Danish time format,
but if you select English, you'll see $ displayed and the US time format.

You should be able to adapt it for your purposes.





That displays en-US, but as far as i know, that does not affect
formatting?

I just tried setting CurrentUICulture to "da-DK", but with the same
result..
 
B

Basildk

See if this sample code helps...

cultureChange.aspx:
-----------------------------
<%@ Page Language="VB" uiculture="auto" %>
<%@ Import Namespace="System.Threading" %>
<%@ Import Namespace="System.Globalization" %>

<script runat="server">
Protected Overrides Sub InitializeCulture()
If Request.Form("ListBox1") IsNot Nothing Then
Dim selectedLanguage As String = Request.Form("ListBox1")
UICulture = Request.Form("ListBox1")
Culture = Request.Form("ListBox1")
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(selectedLanguage)
Thread.CurrentThread.CurrentUICulture = New CultureInfo(selectedLanguage)
End If
MyBase.InitializeCulture()
End Sub
Sub Page_Load(obj as object, e as eventargs)
Dim value as Double = 2.0
Dim s as String 'create a string and format it as currency.
s = String.Format("{0:c}", value)
lblMessage.Text = Listbox1.SelectedItem.Text
lblMessage2.Text = Listbox1.SelectedItem.Value & " " & DateTime.Now & " " & s

End Sub
</script>
<html>
<body>
<form id="form1" runat="server">
<div>
<asp:ListBox ID="ListBox1" runat="server">
<asp:ListItem Value="en-US" Selected="True">English</asp:ListItem>
<asp:ListItem Value="es-MX">Español</asp:ListItem>
<asp:ListItem Value="da-DK">Danish</asp:ListItem>
</asp:ListBox><br />
<asp:Button ID="Button1" runat="server"
Text="Set Language/Culture"
meta:resourcekey="Button1" />
<br />
<asp:Label ID="Label1" runat="server"
Text=""
meta:resourcekey="Label1" />
</div>
<div>
<asp:Label id="lblMessage" runat="server"/></asp:Label> <br />
<asp:Label id="lblMessage2" runat="server"/></asp:Label> <br />
</div>

</form>
</body>
</html>
----------

That code changes the culture/language on demand...

If you select Danish and click the Button, you'll see kr displayed, and the Danish time format,
but if you select English, you'll see $ displayed and the US time format.

You should be able to adapt it for your purposes.

Juan T. Llibre, asp.net MVP
asp.net faq :http://asp.net.do/faq/
foros de asp.net, en español :http://asp.net.do/foros/




I just tried setting CurrentUICulture to "da-DK", but with the same
result..

Thanks for the reply. I tried you code, but with the feared result:

Danish
da-DK 8/30/2007 6:32:32 PM $2.00
 
J

Juan T. Llibre

re:
!> Thanks for the reply. I tried you code, but with the feared result:

I don't have a clue why it would work at my server and not on yours.

See the online sample at :

http://asp.net.do/test/culture3.aspx

Are you formatting the string as currency, per the sample ?

!> Dim value as Double = 2.0
!> Dim s as String 'create a string and format it as currency.
!> s = String.Format("{0:c}", value)

If you don't format the string as currency, no currency symbol change can occur.





See if this sample code helps...

cultureChange.aspx:
-----------------------------
<%@ Page Language="VB" uiculture="auto" %>
<%@ Import Namespace="System.Threading" %>
<%@ Import Namespace="System.Globalization" %>

<script runat="server">
Protected Overrides Sub InitializeCulture()
If Request.Form("ListBox1") IsNot Nothing Then
Dim selectedLanguage As String = Request.Form("ListBox1")
UICulture = Request.Form("ListBox1")
Culture = Request.Form("ListBox1")
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(selectedLanguage)
Thread.CurrentThread.CurrentUICulture = New CultureInfo(selectedLanguage)
End If
MyBase.InitializeCulture()
End Sub
Sub Page_Load(obj as object, e as eventargs)
Dim value as Double = 2.0
Dim s as String 'create a string and format it as currency.
s = String.Format("{0:c}", value)
lblMessage.Text = Listbox1.SelectedItem.Text
lblMessage2.Text = Listbox1.SelectedItem.Value & " " & DateTime.Now & " " & s

End Sub
</script>
<html>
<body>
<form id="form1" runat="server">
<div>
<asp:ListBox ID="ListBox1" runat="server">
<asp:ListItem Value="en-US" Selected="True">English</asp:ListItem>
<asp:ListItem Value="es-MX">Español</asp:ListItem>
<asp:ListItem Value="da-DK">Danish</asp:ListItem>
</asp:ListBox><br />
<asp:Button ID="Button1" runat="server"
Text="Set Language/Culture"
meta:resourcekey="Button1" />
<br />
<asp:Label ID="Label1" runat="server"
Text=""
meta:resourcekey="Label1" />
</div>
<div>
<asp:Label id="lblMessage" runat="server"/></asp:Label> <br />
<asp:Label id="lblMessage2" runat="server"/></asp:Label> <br />
</div>

</form>
</body>
</html>
----------

That code changes the culture/language on demand...

If you select Danish and click the Button, you'll see kr displayed, and the Danish time format,
but if you select English, you'll see $ displayed and the US time format.

You should be able to adapt it for your purposes.

Juan T. Llibre, asp.net MVP
asp.net faq :http://asp.net.do/faq/
foros de asp.net, en español :http://asp.net.do/foros/
message



I just tried setting CurrentUICulture to "da-DK", but with the same
result..

Thanks for the reply. I tried you code, but with the feared result:

Danish
da-DK 8/30/2007 6:32:32 PM $2.00
 
P

Patrice

Yeah just random thoughts & tries for now...

What if you try a *Windows* .NET based application on the server that you'll
run under a regular account. Do you have the same result ? In case it would
work what if you make your ASP.NET application run under the same account ?

I'm not sure how .NET get these info (my understanding at least for 2.0
would be that they are build right into the framework ??). If the FW uses
system files to get those info then it could be a system level problem with
nls support files and I belive I saw once this in classic ASP and it was a
profile related issue...

--
Good luck, sorry for the poor help


"Basildk" <[email protected]> a écrit dans le message de
(e-mail address removed)...
I just tried setting CurrentUICulture to "da-DK", but with the same
result..

I researched a little further:
If i insert the following code:
Response.Write("Language " + cultureInfo.Name + "<br />");
Response.Write("---------------------------------<br />");
Response.Write("CurrencySymbol " +
cultureInfo.NumberFormat.CurrencySymbol.ToString() + "<br />");
Response.Write("DateSeparator " +
cultureInfo.DateTimeFormat.DateSeparator + "<br />");
Response.Write("LongDatePattern " +
cultureInfo.DateTimeFormat.LongDatePattern.ToString() + "<br />");
Response.Write("ShortDatePattern " +
cultureInfo.DateTimeFormat.ShortDatePattern.ToString() + "<br />");
string[] days = cultureInfo.DateTimeFormat.DayNames;
for( int i = 0; i < days.Length; i++)
{
Response.Write(days + "<br />");
}
Response.Write("---------------------------------<br />");


I get the following output:

Language da-DK
---------------------------------
CurrencySymbol $
DateSeparator /
LongDatePattern dddd, MMMM dd, yyyy
ShortDatePattern M/d/yyyy
søndag
mandag
tirsdag
onsdag
torsdag
fredag
lørdag

In other words: Some of the values are perfect danish (the days) while
others are stille american (datepattern, dateseperator and
currencySymbol)
I am puzzled:)
 

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,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top