Link to home
Start Free TrialLog in
Avatar of Coast Line
Coast LineFlag for Canada

asked on

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:
http://ricardo.parente.us/?p=18
<cfscript>
application.mainDSN = "myDatabase" ;
application.site = structNew();
application.site.defaultLanguage = "EN";
application.site.languages = "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
</cfscript>
<!--- 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() />
</cflock>
</cfif>
 
<cfprocessingdirective pageencoding="utf-8" suppresswhitespace="true">
<cfparam name="url.lang" default="#application.site.defaultLanguage#" />
<cfparam name="client.lang" default="#application.site.defaultLanguage#" />
<!--- 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) />
 
<cfcomponent>
<cffunction name="init" access="remote" output="false" returntype="Query">
<cfquery name="get" datasource="#application.mainDSN#">
select fieldName
<cfloop list="#application.site.languages#" index="lang">
, #lang#
</cfloop>
from dictionary
</cfquery>
<cfreturn get />
</cffunction>
<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(application.site.languages, arguments.selectedLanguage)>
<cfset arguments.selectedLanguage = application.site.defaultLanguage />
</cfif>
<cfif arguments.selectedLanguage neq client.lang>
<cfset client.lang = arguments.selectedLanguage />
</cfif>
<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)#)
</cfif>
</cfquery>
<cfset lang = structNew()>
<cfloop query=get>
<cfif not structKeyExists(lang, get.fieldName)>
<cfset structInsert(lang, get.fieldName, evaluate(get.#arguments.selectedLanguage#)) />
</cfif>
</cfloop>
<cfreturn lang />
</cffunction>
</cfcomponent>
 
USE [myDatabase]
GO
/****** Object: Table [dbo].[dictionary] Script Date: 08/04/2008 00:32:48 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
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
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
SET ANSI_PADDING OFF

Open in new window

Avatar of erikTsomik
erikTsomik
Flag of United States of America image

Avatar of Coast Line

ASKER

i have posted the code of your second link but that code does not work in any case

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?

Azadi
  • 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
SOLUTION
Avatar of azadisaryev
azadisaryev
Flag of Hong Kong image

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
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: http://www.microfinancelaopdr.org/

Azadi

ok so are saying something loike this:
i have one table with userdetails
table fields:
userid
username
details_eng
details_french
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
right
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).

Azadi
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
Thanks

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
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>
</cfif>

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)
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:

like:

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

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

Thanks
Thanks Mates