Hi I am trying to create a bilingual web site: Greek/English, but i am facing two problems: 1) While in default.aspx i run the following code when a button is clicked: "Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-GB") Thread.CurrentThread.CurrentUICulture
= Thread.CurrentThread.CurrentCulture" Everything Seems fine in default.aspx but when i redirect to home.aspx and try to get the "Thread.CurrentThread.CurrentCulture" I get "en-US". The second problem is when i want to automaticaly select the language according
to the user's primary language. So the code will be: "Dim cul As New CultureInfo(Request.UserLanguages(0)) Thread.CurrentThread.CurrentUICulture = cul Thread.CurrentThread.CurrentCulture=cul" But when the primary user language is Greek, i get the following
error: Culture name el;q=0.5 is not supported. Parameter name: name Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in
the code. Exception Details: System.ArgumentException: Culture name el;q=0.5 is not supported. Parameter name: name. I tried change the response encoding but i keep getting the same error. Looks to me more like an incompatibility between Internet Explorer's
and ASP.NET's language codes as IE will return el;q=0.5 while .NET accepts only el-GR. Is this a bug? :P
Nope not a bug, the Accept-Language header
field definition tellls us that the "q value" reflects the user's preference for that language (where 1 is most preferred). A French-Canadian might haveAccept-Language: fr-CA, fr-FR;q=0.8, en;q=0.5 What this really means is that 'language preference'
(when more than one is specified) is defined by the "q value" and not the 'order of appearance' in the Accept-Language string. So, what does that mean for you? You need to pass
Request.UserLanguages(0).Split(';')[0] // or something like that!to ensure you never pass the "q value" the to CreateCulture methods. You are passing "el;q=0.5" to CreateSpecificCulture, when you should only be passing "el"! The trick is that Request.UserLanguages(0)
by itself will work (no "q value") if the user only has one language set in their browser... it's when there are two or more preferences set that the "q value" typically gets added. Also might be an idea to wrap in a try/catch block, because IE lets users
input their own Accept-Language strings (i've come across "ie-EE" which breaks the CreateCulture methods, because it's not a "real" culture). Can't help you with the en-GB/en-US prob - not sure what's going on there...
Multi(lingual)Media? Trans-Asia.com Online Translation and Web Services...
Well with the en_GB, it switches just fine in the page where you select the language, but when i use Response.Redirect(url) to go to the next page, there the language is en-US, which is a bit odd
Sorry to put but in - but has anyone experienced this culture bug: When I set the culture to en-GB in web.config it works fine. When I set the culture programmatically to en-GB it has the shortdateformat property of the culture object as m/d/yyyy which is wrong?
Other cultures en-US, fr-FR work fine.
Among the other issues... The Thread's culture is set only for the thread ( the current request), it does not hold for subsequent pages that the same user requests. You use a cookie of the accepted languages to determine the language and you change it in the
Application_BeginRequest so that it happens every time.
Not to resurrect an old thread, but I have encountered an issue with setting the culture to the user's current settings and exporting to Excel: Currently I have my code:
Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs) ' Fires at the beginning of each request Dim DefaultCulture As String = "en-US" Dim UsrLan As String = Request.UserLanguages(0).Split(";")(0) Dim cul As New CultureInfo(UsrLan)
If cul.IsNeutralCulture Then cul = New CultureInfo(DefaultCulture) End If Thread.CurrentThread.CurrentCulture = cul Thread.CurrentThread.CurrentUICulture = cul End Sub
That is fine and works to localize the columns with date values in my tables. Now the issue is for a particular table/datagrid, if I right click and select "Export to Microsoft Excel" (essentially doing an Excel web query), it gives an error saying unable
to open file (it says this in Excel). I can't find much information on this, so does anyone else have any ideas? Thanks a lot.
Member
10 Points
38 Posts
Possible Bug: UserLanguages(x) Return Value Incompatible with CultureInfo constructor name parame...
Apr 12, 2004 09:38 PM|Lambros Vasiliou|LINK
None
0 Points
16 Posts
Re: Possible Bug: UserLanguages(x) Return Value Incompatible with CultureInfo constructor name pa...
Apr 21, 2004 07:43 PM|craigd|LINK
Accept-Language: fr-CA, fr-FR;q=0.8, en;q=0.5
What this really means is that 'language preference' (when more than one is specified) is defined by the "q value" and not the 'order of appearance' in the Accept-Language string. So, what does that mean for you? You need to passRequest.UserLanguages(0).Split(';')[0] // or something like that!
to ensure you never pass the "q value" the to CreateCulture methods. You are passing "el;q=0.5" to CreateSpecificCulture, when you should only be passing "el"! The trick is that Request.UserLanguages(0) by itself will work (no "q value") if the user only has one language set in their browser... it's when there are two or more preferences set that the "q value" typically gets added. Also might be an idea to wrap in a try/catch block, because IE lets users input their own Accept-Language strings (i've come across "ie-EE" which breaks the CreateCulture methods, because it's not a "real" culture). Can't help you with the en-GB/en-US prob - not sure what's going on there... Multi(lingual)Media? Trans-Asia.com Online Translation and Web Services...Member
10 Points
38 Posts
Re: Possible Bug: UserLanguages(x) Return Value Incompatible with CultureInfo constructor name pa...
May 05, 2004 09:35 AM|Lambros Vasiliou|LINK
None
0 Points
352 Posts
Re: Possible Bug: UserLanguages(x) Return Value Incompatible with CultureInfo constructor name pa...
May 05, 2004 09:49 AM|Ian O'Rourke|LINK
Member
132 Points
435 Posts
Re: Possible Bug: UserLanguages(x) Return Value Incompatible with CultureInfo constructor name pa...
May 11, 2004 10:23 AM|AndrewSeven|LINK
None
0 Points
40 Posts
Re: Possible Bug: UserLanguages(x) Return Value Incompatible with CultureInfo constructor name pa...
Nov 09, 2004 03:30 PM|rsdim|LINK
Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs) ' Fires at the beginning of each request Dim DefaultCulture As String = "en-US" Dim UsrLan As String = Request.UserLanguages(0).Split(";")(0) Dim cul As New CultureInfo(UsrLan) If cul.IsNeutralCulture Then cul = New CultureInfo(DefaultCulture) End If Thread.CurrentThread.CurrentCulture = cul Thread.CurrentThread.CurrentUICulture = cul End Sub
That is fine and works to localize the columns with date values in my tables. Now the issue is for a particular table/datagrid, if I right click and select "Export to Microsoft Excel" (essentially doing an Excel web query), it gives an error saying unable to open file (it says this in Excel). I can't find much information on this, so does anyone else have any ideas? Thanks a lot.Member
132 Points
435 Posts
Re: Possible Bug: UserLanguages(x) Return Value Incompatible with CultureInfo constructor name pa...
Jan 18, 2005 07:29 PM|AndrewSeven|LINK