Multilingual website using Coldfusion

Hi experts. Can anyone tell me tha multilingual websites are easily possible in Coldfusion or not.

What is the exact procedure of doing it. i searched google and did not find any solution which can guide me that my website will be multilingual.

Approches, i see.

1. in PHP files, diffrent languages are created
   But how the dyanmic data get translated.
2. Found one multilingual article in coldfusion but the support is null and it did not helped me to work.

here is the code of the coldfusion

the code is below or link is this:
application.mainDSN = "myDatabase" ; = structNew(); = "EN"; = "EN,FR,DE,ES,PT"; // list of languages allowed for this site
application.oLang = createObject("component", "dictionary"); //create the object
thisPage = structNew(); //create structure for page verbs and other stuff
<!--- if the dictionary is not already loaded into application scope, then load it --->
<cfif not structKeyExists(application, "dictionary")>
<cflock scope="Application" type="exclusive" timeout="10">
<cfset application.dictionary = oLang.init() />
<cfprocessingdirective pageencoding="utf-8" suppresswhitespace="true">
<cfparam name="url.lang" default="" />
<cfparam name="client.lang" default="" />
<!--- Here goes the field list to retrieve from the dictionary table --->
<cfset thisPage.wordList = "name,address,city,state,zipCode,selectLang,save,requestMoreInfo" />
<cfset lang = application.oLang.setLanguage(url.Lang, thisPage.wordList) />
<cffunction name="init" access="remote" output="false" returntype="Query">
<cfquery name="get" datasource="#application.mainDSN#">
select fieldName
<cfloop list="" index="lang">
, #lang#
from dictionary
<cfreturn get />
<cffunction name="setLanguage" access="remote" output="false" returntype="Struct">
<cfargument name="selectedLanguage" type="string" required="false" default="#application.selectedLanguage#" />
<cfargument name="wordList" type="string" required="false" default="" />
<cfset arguments.wordlist = "'" & reReplace(arguments.wordList,"[,], ,, all) &  />
<cfif not listFindNoCase(, arguments.selectedLanguage)>
<cfset arguments.selectedLanguage = />
<cfif arguments.selectedLanguage neq client.lang>
<cfset client.lang = arguments.selectedLanguage />
<cfquery name=get dbtype=query>
select #arguments.selectedLanguage#, fieldName from application.dictionary
where 1=1
<cfif len(trim(arguments.wordList))>
and fieldName in (#preserveSingleQuotes(arguments.wordList)#)
<cfset lang = structNew()>
<cfloop query=get>
<cfif not structKeyExists(lang, get.fieldName)>
<cfset structInsert(lang, get.fieldName, evaluate(get.#arguments.selectedLanguage#)) />
<cfreturn lang />
USE [myDatabase]
/****** Object: Table [dbo].[dictionary] Script Date: 08/04/2008 00:32:48 ******/
CREATE TABLE [dbo].[dictionary](
[fieldName] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[en] [text] COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[fr] [ntext] COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[de] [ntext] COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[pt] [ntext] COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[es] [ntext] COLLATE SQL_Latin1_General_CP1_CI_AS NULL

Open in new window

LVL 16
Gurpreet Singh RandhawaWeb DeveloperAsked:
Who is Participating?
albrandwoodConnect With a Mentor Commented:
Just my 3 cents ...

I use tables similar to suggested above ... id,EN,FR,IT,DE,etc

In my application, I do this once ... (to load it in memory ...
<cfquery datasource="#dsn#" name="application.multilingual_content">
     SELECT * FROM multilingual_content_table
then using a cookie ...
<cfset cookie.language='FR'>
I create a session level query to work from ...
<cfquery dbtype="query" name="session.content">
    SELECT id,EN,#cookie.language# AS word
      FROM application.multilingual_content

that way, for that user, I'm always looking up against their session.content to get the translation I need.

remember, you can use cgi.HTTP_ACCEPT_LANGUAGE to try to predict their prefered language ... (the list provided by the browser is in order of preference ...)
when initializing the session, you could do something similar to the code below.

<cfif not (IsDefined("cookie.language") and ListFind(cookie.language,applicaion.multilanguage_content.columnlist))>
    <cfloop list="#listfirst(cgi.http_accept_language,";")#" index="i">
        <cfif ListFindNoCase(trim(i),application.multilanguage_content.columnlist)>
            <cfset cookie.language=uCase(trim(j))>
<cfparam name="cookie.language" default="EN">
<cfquery dbtype="query" name="session.content">
    SELECT id,EN,#cookie.language# AS word
      FROM application.multilingual_content

Open in new window

erikTsomikSystem Architect, CF programmer Commented:
Gurpreet Singh RandhawaWeb DeveloperAuthor Commented:
i have posted the code of your second link but that code does not work in any case

Easily Design & Build Your Next Website

Squarespace’s all-in-one platform gives you everything you need to express yourself creatively online, whether it is with a domain, website, or online store. Get started with your free trial today, and when ready, take 10% off your first purchase with offer code 'EXPERTS'.

the translations for each label/word should be stored in your database, in a designated.
YOU have to make the translations of each an every thing you want to display in different languages on your pages - CF will NOT translate anything for you. you then have to invoke the component posted in the article you mention on every page that requires multilingual support, and pass to the cfc the list of words that need to be returned, and the language they should be returned in. you then use the elements of the structure returned by the component instead of labels/words in the page.

what exactly did you not understand in that article or had trouble implementing?

Gurpreet Singh RandhawaWeb DeveloperAuthor Commented:
  • creating a new databse for french language with same structure
  • create a new databse with english language eith same structure
can i use the above code to manage my website. the above seems very cumbersome
azadisaryevConnect With a Mentor Commented:
you need ONE table in your db with a structure similar to:

FiledName      EN            DE            FR      
search      search      suchen      cherche
and so on

(pardon any misspellings... my German and French are very rusty)

Gurpreet Singh RandhawaWeb DeveloperAuthor Commented:
ok but:
how will i store the values of the dynamic values like dynamic  text.
to be hosnest,i build many websites but multilingual is the first for me and i am so much confused i am just lost
> how will i store the values of the dynamic values like dynamic  text

you really don't. all this can help you do is display simple static elements - like button labels, form field names, maybe menu and pagination elements if they are text-based on your pages - in the language selected by the user, provided you have stored translations of these elements in the db.

to display your dynamic CONTENT in different languages, you will have to have that content translated into other languages and stored in your db as well.

here's one of my sites as an example for you:


Gurpreet Singh RandhawaWeb DeveloperAuthor Commented:
ok so are saying something loike this:
i have one table with userdetails
table fields:
while entering the data from front, i need to use the translation engine to translate the details_eng into freanch and then add it to the database field details_frech
for as many languageas as many datafields are required
generally, yes, though i would question the need to translate USER DATA into any language at all...
what you want to translate is YOUR content.
if you want to have user details in other languages - let your users submit the translations. that way they won;t complain when your translation of their details into french is totally wrong...
on the display side - if user's details are not available in the language the rest of the page is displayed in - display the details in default language (i.e. english).

Gurpreet Singh RandhawaWeb DeveloperAuthor Commented:
two questions ares here:
  • if user enters content in english, while they are using the site in french mode and wanna view the site in french mode, like all its content.
  • FiledName      EN            DE            FR      
    search      search      suchen      cherche
    you provided above.
  • will i have to create fields like: username, password, search, about etc and say5 rows have to created for each field.
  • if that above is the case, how can i use the code i provided above to manage the website's staic contents easily through this this.
  • also in the above code. the main thing is all is stored in application vars.
  • will that cause any effect if i store it in request or session. vars

Request variables are not suited for this problem, as they dont have persistance ...

Use a cookie to store their prefered language (that way, it's persistant accross sessions, without requiring a user to log in first)

Use a Session query to store the data for THEIR session ...

You don't have to use application variables, but I would recommend it ...

in you applicaton.cfm (or in application.cfc)
do something like:

<cfif(not (IsDefined("application.ready") and application.ready)>
    do your application definitions here.
    end with:
    <cfset application.ready=true>

that way, application data is loaded ONCE for the entire time that the application is in memory ... (and yes, this is very simplified ... google CFAPPLICATION and Application.CFC for better examples)
Gurpreet Singh RandhawaWeb DeveloperAuthor Commented:
Thanks Pals:

Before i jump into this i wanted to have some queries to clear that i am not doing something stupid:

1. Suppose i have fields like Home, services, my things, mailbox, help, feedback, others. They are static and appear on the website. they are not dynamic, i cannot change them
2. should i store all the static values [other languages] in the database as specified by azadi:


id                  fieldname                                en                         fr                           gr
1                   home                                      home                    hune                      whatever
1                   services                                      services                    setcy                      whatever
1                   others                                      home                    hune                      whatever

Please make my this funda clear then i will see how i can try to do with dynamic content
gdemariaConnect With a Mentor Commented:
>  should i store all the static values [other languages] in the database as specified by azadi

Yes, you can store these values in your database as a simple way to fetch and display them depending on the user's selected language.

If they are graphics, you could store them in a language specific file under the same name.

Such as


Notice the name of my gif file is the same.  That makes coding easier as you just get the folder name from the cookie which specifies your language.

I agree with the other, there is typically no need to translate user entered data.  The only information you should be concerned with is the information from your web site (navigation, help info, privacy statement, instructions, about us, etc.. etc...)   Do not attempt to translate forums or other information entered by the user.
Gurpreet Singh RandhawaWeb DeveloperAuthor Commented:
will the user entered info will appear in english, no matter which language is used?
is this what u are saying
user entered data would appear in whatever language they enter it, not necessarily English.

I think you will find this to be common among any multilingual website.  

Gurpreet Singh RandhawaWeb DeveloperAuthor Commented:
Thanks definately due to time constraint i have yet to implement it.

once i get practical used to it, i will come across many problems, i think so i will try to post all my erros, but for the base i think this is the best way i should go for it

Gurpreet Singh RandhawaWeb DeveloperAuthor Commented:
Thanks Mates
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.