Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Offering content in many languages

Status
Not open for further replies.

vpekulas

Programmer
Jan 8, 2002
154
CA
Hello all,

I have an application that needs to be in more then English language. Now, what would be the ideal way of dealing with the translations. I only want to have 1 instance of the application, and include language files with it, so the user can just select what language to use and be done with it, no need to reinstall or change anything.

Is it a good idea to have the text in say arrays in text files and load the file each time the page needs to be rendered ?

Any ideas are appreciated as this is a big application, and I'm not quite sure I want to load 200 K's of text for each page :(

"Taxes are the fees we pay for civilized society" G.W.
 
I have done the exact thing you mention. Visit
What I did was have ALL text of the site in the database. I first made the english version, then I took each bit of text and assigned it a token. (I did this in an excel spreadsheet for future reference, so I don't always have to go into the database to look things up.) After filling column A in the spreadsheet with tokens (you can give them incrimental numbers, for simplicity, or name them if you want. Naming a token with a descriptive word makes it harder later on, so I would stick with the sequencial numbering system.) I filled in the bits of text in column B.

Now we have a token-text relationship. This means that token '1' will represent the text 'hello world' for example. Having the base english tokens in my spreadsheet, I had coumn B translated into my 2nd language in column C. Note that both the english and second language are now assigned to the same token.

Ok, we have our spreadsheet set up. Now to set up the database we need the following tables:

language
========
language_id
language_text

token
=====
token_id
token_code
token_language
token_text

language_id is an autonumber primary key field.
language_text is the name of the language.
token_id is an autonumber primary key field.
token_code is the token number we assigned it in our spreadsheet.
token_language is the number of the language corresponding to language_id of this token.
token_text is the textual value of the token.

Now we need to create a function that will do the lookups for us:
Code:
<%
    Function getTokenText(intTokenCode, intLanguageID)
        Dim strSQL

        strSQL = &quot;SELECT token_text FROM token WHERE token_code = &quot; & intTokenCode & &quot; AND token_language = &quot; & intLanguageID
        'run query
        'set getTokenText = query result
   End Function
%>
Keep this function in an include file that you have included on every page of your site.

Next, we need to store the language of the user by using session variables. Then whenever we want to display a bit of text, we do this:

<%= getTokenText(12, Session(&quot;LanguageID&quot;)) %>

The session variable was previously set in the users profile and loaded when he logged on, or you can have the user choose the language somewhere on your site, and then store it in the session variable.

I hope this gets you on your way. let me know if you have additional questions :).

Take Care,
Mike
 
Hi Mike,

This was my other options. I like the idea of spreadsheet, I guess it makes things much easier. How is the performance of your application after implementing this language pack ? As I mentioned above, my app is rather large, so if I could I'd rather not tap into the database each time I need
something translated.

If I was to keep the text for each language in it's own file it'd work well, but unfortunately it'd slow down tremendously
as more users login :(

&quot;Taxes are the fees we pay for civilized society&quot; G.W.
 
I don't use the spreadsheet in the application itself. i only use the spreadsheet for my personal reference. I actual tap into the database, and even on high-volume sites it doesn't have much impact, since the queries are very lightweight.

Take Care,
Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top