Link to home
Start Free TrialLog in
Avatar of coddie
coddieFlag for United States of America

asked on

Developing a Multi Language Site

Hi all,

I am preparing to develop a site for myself which will need to be in both French and English and will need to be designed to allow for the addition of other languages at a later date.

The main content of the site will come from a regularly updated database.

I want to offer a choice of language on the first page and then have the site remember that choice throught the users visit and subsequent return visits. (Sessions and Cookies).

Once the language choice is made, I need all page content to change to the chosen language, menu items, general texts and comments, all the rest is dynamic and will be supplied in each language. but each page should have the posibility to change to another language.

I am relatively competent with ASP and I can construct a database no problem, my question is really can anyone point me in the right direction for the methodology for a multi-language site. I really need a few pointers as to how to set thing up from someone that has done this before.

Questions :-
(1) Should I use different db tables for each language or seperate language include files?
(2) If Database, what is the preffered layout ?
(3) Content management for a multi language site ?

Any suggestions or code examples would be much appreciated.

Cheers
Coddie
SOLUTION
Avatar of jmelika
jmelika

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mmiika
mmiika

Some thoughts can be found at http://www.codeproject.com/asp/localising.asp
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Ah hell, seems EE has encoded my arabic text!
Avatar of coddie

ASKER

AlfaNoMore
This looks like an interesting option, which I had'nt considered before, can you please explain in a little greater depth how these xml file should be used in the final pages.

Coddie
I have a couple of classes that handle the retrieval of data from the XML file, but it's used something like this:

<%
Const IDENTITY_SECTION = "System"
Const IDENTITY_PAGE = "Left-hand Menu"

Set thisTranslator = New Translator

With thisTranslator
      .LanguageID = languageID
      .PageIdentity = IDENTITY_SECTION & " / " & IDENTITY_PAGE
      .setContent()
End With

Response.Write(thisTranslator.getContent(IDENTITY_PAGE & "_1"))
%>

So, based on the PageIdentity property, the class loops through all the text elements within the given node. The @id attribute of the XML is used for the identity. I could copy the classes here, but there are a few of them!

I'll give the DTD though and you might be able to figure it out?
     <!ELEMENT content (language+)>
      <!ELEMENT language (section+)>
      <!ELEMENT section (page+)>
      <!ELEMENT page (text*)>
      <!ELEMENT text (#PCDATA)*>
      <!ATTLIST language
      name CDATA #REQUIRED
            id CDATA #REQUIRED
>
      <!ATTLIST section
      name CDATA #REQUIRED
>
      <!ATTLIST page
      name CDATA #REQUIRED
            heading CDATA #IMPLIED
            skilltype (hard | soft) #IMPLIED
            question CDATA #IMPLIED
>
      <!ATTLIST text
      maxlength CDATA #IMPLIED
            type (textarea | heading | question | table | link | confirm | button) #IMPLIED
            class CDATA #IMPLIED
            href CDATA #IMPLIED
            number CDATA #IMPLIED
            identifier CDATA #IMPLIED
            id CDATA #IMPLIED
>
Avatar of coddie

ASKER

AlfaNoMore
Its going to take me a while to understand and figure out what you are saying here, as this approach is totally new to me, but I am very interested in the idea of using xml. So anything that you can give me regarding the implimentation of your code would be very interesting and helpful.

Thanks
Coddie
Avatar of coddie

ASKER

AlfaNoMore
Thanks very much for your help but i am sorry, I dont understand your last posting at all, what is that code?, how is it used?, where does it go?, etc ....!!????

I get the stuff about storing the page elements for the different languages in xml files, i sort of get the bit about calling the files to retrieve the data from the xml.
but the last bit - I have no idea about whats happening here ??  (:-|

Can you give me a quick run through of how all this hangs together.

I much appreciate your help
I just need a little more of an understanding of how it all works together,
maybe a simple page example of how it all works together.

Cheers
Coddie
That's a DTD. The schema behind the XML file. It's how I have structured my files. In truth, probably not that useful, but thought it might help? Guess not.... I'll give you the setContent and getContent methods then:


      Public Sub setContent()
      
            Dim objLanguageContent, _
                  objTranslatedContent, _
                  objTextElement
            Dim arrPageIdentity, _
                  strPageName, _
                  strDictKey
            
            With gLanguageClass
                  're-use many of the methods alreday created within the LanguagePageClass.asp file
                  .LanguageID            = gLanguageID
                  .PageIdentity      = gPageIdentity
                  .QuestionID            = gQuestionID
                  .setResponseHeaders()
                  gCharset            = .CharSet
            End With
            
            Set objLanguageContent = gLanguageClass.GetVersionedContent()
            
            'objLanguageContent.Save(Response)
            'Response.End()
            
            Set objTranslatedContent = objLanguageContent.selectSingleNode( _
                                                            "content/translation/page")

            strPageName = objTranslatedContent.getAttribute("name")
            
            If objTranslatedContent.getAttribute("heading") <> "" Then
                  gContentDict(strPageName & "_0") = objTranslatedContent.getAttribute("heading")
            End If
            
            For Each objTextElement In objTranslatedContent.childNodes
                  strDictKey = strPageName & "_" & objTextElement.getAttribute("id")
                  gContentDict(strDictKey) = objTextElement.Text
            Next

            Set objTranslatedContent = Nothing
            Set objLanguageContent = Nothing
            
      End Sub


      Public Function getContent(textIdentity)

            If gContentDict.Exists(textIdentity) Then      '// return content
                  'getContent = NewlineToBR( gContentDict(textIdentity) )
                  getContent = gContentDict(textIdentity) ' contains all the HTML we need already!
            Else      '// mark it as missing
                  getContent = "Text missing for '" & textIdentity & "'"            
            End If

      End Function      '// getContent


You can ignore most of the stuff to do with the gLanguageClass object. I'm loading in my template version (English) and overlaying my translated version over the top, thus giving me a complete version no matter the state of the translation. You might not need this type of complexity, so you could just load your wanted version in and use that?
Avatar of coddie

ASKER

Thanks for the rapid response, I will try to figure out whats happening here ..... this is all very new to me.

Looks like I have contributed a fair amount of time/code to this, so would appreciate the reward?
I also contributed with the concept and a sample code.
So what do you thnk of a 70/30% split?
I agree you contributed more than I did.  It would only be fair if you were given more points than me, and not 50%-50%.

Sure why not! :)
Avatar of coddie

ASKER

Hi sorry for not responding more quickly, but I have been away traveling.

In the end i did not use either of these suggestions .......
the xml suggestion from AlfaNoMore  was far to complicated for me to get my head around, and the various rows in different tables seemed a bit untidy. however i have indead used Cookies to maintain the chosen language across the site.

After much research I have found that the simplest and neatest way to acheive what I wanted was to use the Asp Dictionary object to hold the different language items.
I created a different dictionary for each language and fed it in to the page using the file system object.
Easy to create a new dictionary for each new language.

I would like to thank both AlfaNoMore and jmelika for their time and efforts, and I greatly appreciate all the help offered by contributeres to this valuable site.

Since I used neither suggestion, one is no better than the other so I would therefore like to award the points equally. I am rewarding your time and efforts and willingness to help others.

cheers guys


Coddie