Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / August 2007

Tip: Looking for answers? Try searching our database.

Globalization not working as intended when using da-DK

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Basildk - 30 Aug 2007 16:17 GMT
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..
Patrice - 30 Aug 2007 16:30 GMT
What if you display CurrentUICulture ?

---
Patrice

> Hi.
>
[quoted text clipped - 28 lines]
>
> Thanks for the help..
Basildk - 30 Aug 2007 16:48 GMT
> What if you display CurrentUICulture ?
>
[quoted text clipped - 36 lines]
>
> > Thanks for the help..

That displays en-US, but as far as i know, that does not affect
formatting?
Basildk - 30 Aug 2007 16:51 GMT
> > What if you display CurrentUICulture ?
>
[quoted text clipped - 39 lines]
> 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..
Basildk - 30 Aug 2007 17:19 GMT
> > > What if you display CurrentUICulture ?
>
[quoted text clipped - 42 lines]
> 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[i] + "<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:)
Patrice - 31 Aug 2007 09:26 GMT
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

> > On 30 Aug., 17:30, "Patrice" <http://www.chez.com/scribe/> wrote:
>
[quoted text clipped - 47 lines]
> 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[i] + "<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:)
Juan T. Llibre - 30 Aug 2007 17:21 GMT
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/
======================================
> On 30 Aug., 17:30, "Patrice" <http://www.chez.com/scribe/> wrote:
>
[quoted text clipped - 41 lines]
> 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..
Basildk - 30 Aug 2007 17:33 GMT
> See if this sample code helps...
>
[quoted text clipped - 110 lines]
> 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
Juan T. Llibre - 30 Aug 2007 17:53 GMT
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.

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/
======================================
On 30 Aug., 18:21, "Juan T. Llibre" <nomailrepl...@nowhere.com> wrote:
> See if this sample code helps...
>
[quoted text clipped - 114 lines]
> 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

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.