我正在开发一个必须支持丹麦字符的网站(支持的语言将来会增加)。
我正在使用数据库表 - 让我们调用它Strings
- 我在我的网站上显示每个字符串的记录。例如,登录页面中的问候消息将输入数据库,如下所示:
ID |说明|文字| LANG_CODE
1 |登录|登录|烯
这是从数据库中提取lang_code的代码:
Public Shared Function GetLanguageCodeFromBrowser()
Dim language_code As String
Dim databaseConnection As New DBConnectionAdapter
Dim DataReader, DataReader1 As MySqlDataReader
Dim serverVar As String = HttpContext.Current.Request.ServerVariables("HTTP_ACCEPT_LANGUAGE")
language_code = LCase(serverVar)
Dim Query As String = "SELECT language_code FROM languages WHERE language_code = '" & LCase(language_code) & "' AND disabled = 0"
Dim Query1 As String = "SELECT language_code FROM languages WHERE language_code = '" & LCase(Left(language_code, 2)) & "' AND disabled = 0"
Dim cmdSelect As New MySqlCommand(Query, databaseConnection.connectionWebServices)
Dim cmdSelect1 As New MySqlCommand(Query1, databaseConnection.connectionWebServices)
Try
databaseConnection.OpenWebServices()
DataReader = cmdSelect.ExecuteReader
If Not DataReader.Read Then
DataReader.Dispose()
DataReader1 = cmdSelect1.ExecuteReader
If Not DataReader1.Read Then
DataReader1.Dispose()
Return language_code = "en"
Else
Return DataReader1("language_code")
End If
DataReader1 = Nothing
DataReader1.Dispose()
Else
Return DataReader("language_code")
End If
DataReader = Nothing
DataReader.Dispose()
Catch ex As Exception
' TODO Error handling
HttpContext.Current.Response.Write(ex.Message)
Finally
databaseConnection.CloseWebServices()
End Try
databaseConnection = Nothing
End Function
我在MasterPage的Page_Init事件中使用它,如下所示:
Session("language_code") = Language_from_Browser.GetLanguageCodeFromBrowser
一切都用英语很好,但谈到丹麦语时,有些人物会受到损害。
我尝试在web.config中更改此内容:
<globalization
fileEncoding="ISO-8859-1"
requestEncoding="ISO-8859-1"
responseEncoding="ISO-8859-1"
culture="auto"
/>
仍然无法正常工作。
请注意,我的每个文件夹中都有一个default.aspx
页面,所以我不必费心去重写URL(这就是我最不明白的方式)