开发者

Multilingual website using ASP and a database

开发者 https://www.devze.com 2023-01-03 08:25 出处:网络
i want to consult about something i do. my website has 3 languages. Hebrew (main), english and russian. i am using a database having a table with the fields: ID, fieldName, 1, 2, 3. where 1 2 3 are

i want to consult about something i do.

my website has 3 languages. Hebrew (main), english and russian. i am using a database having a table with the fields: ID, fieldName, 1, 2, 3. where 1 2 3 are the languages.

upon entering the website language 1 (hebrew) is chosen automatically until you choose another. and saved as a session("currentLanguage").

i wrote a function langstirng whice receives a field name and prints the value according to the language in 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(languag开发者_运维知识库eStrings.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

and I use it like so: <div>langstring("header")</div>.

I find it stupid that I keep sending the query to the server on any and every page. since the multilingual table does not change "THAT" often I want to somehow save the recordset for the current browsing.

I am looking help for THIS solution, Please.


If they don't change very often, why not just dump the strings to an .asp file?

This file can be rewritten whenever you have made changes in the database.

Another option would be to cache the strings in memory using something like Caprock.Dictionary


Another option would be if you wanted to store the languages in a separate table and then use a join statement to pull that information out based on the cookie or session that the language is set to.

Then you never have to check the language and create the combobox like that you would just have an html combo box with values of the unique ID of the language in the table.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号