2010-06-15 47 views
0

我想諮詢一下我做的事情。使用ASP和數據庫的多語言網站

我的網站有3種語言。希伯來語(主),英語和俄語。我正在使用一個數據庫有一個表與字段:ID,fieldName,1,2,3。其中1 2 3是語言。

在進入網站語言1(希伯來文),直到你選擇另一全自動選擇。並保存爲session("currentLanguage")

我寫了一個函數langstirng whice臨危一個字段名,並打印acording的語言session("currentLanguage")值:

Dim languageStrings 
Set languageStrings = Server.CreateObject("ADODB.Recordset") 
languageStrings.ActiveConnection = MM_KerenDB_STRING 
languageStrings.Source = "SELECT fieldName,"&current_Language&"FROM Multilangual" 
languageStrings.CursorType = 0 
languageStrings.CursorLocation = 2 
languageStrings.LockType = 1 
languageStrings.Open() 

sub langstring(fieldName) 
    do while NOT(languageStrings.EOF) 
     if (languageStrings.fields.item("fieldName").value = fieldName) then 
      exit do 
     else 
      languageStrings.movenext 
     end if 
    loop 

if (languageStrings.EOF) then 
    response.Write("***"&fieldName&"***") 
else 
    response.Write(languageStrings.fields.item(currentLanguage+1).value) 
end if 
    languageStrings.movefirst 
end sub 

我用它像這樣:<div>langstring("header")</div>

我覺得愚蠢,我一直將查詢發送到服務器上的任何和所有的網頁。由於多語言表不會改變「那」,我經常想以某種方式保存當前瀏覽的記錄集。

我期待幫助解決方案,請。

回答

1

如果他們不經常改變,爲什麼不只是轉儲字符串.asp文件?

該文件可以隨時作出更改數據庫被改寫。

另一種選擇是將緩存使用的東西在內存中的串像Caprock.Dictionary

0

另一種選擇是,如果你想存儲在單獨的表中的語言,然後用連接語句拉出基於該信息該語言設置爲的cookie或會話。

然後你從來沒有檢查的語言,並創建一樣,你只會有一個HTML組合框與表中的語言的唯一ID值的組合框。