Noam Smadja
Noam Smadja

Reputation: 1035

Multilingual website using ASP and a database

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(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

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.

Upvotes: 0

Views: 203

Answers (2)

rBg
rBg

Reputation: 33

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.

Upvotes: 0

Thomas Kj&#248;rnes
Thomas Kj&#248;rnes

Reputation: 1927

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

Upvotes: 1

Related Questions