Solved

Multilingual website using Coldfusion

Posted on 2009-04-02
19
1,765 Views
Last Modified: 2013-12-16
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

0
Comment
Question by:myselfrandhawa
  • 9
  • 4
  • 2
  • +2
19 Comments
 
LVL 19

Expert Comment

by:erikTsomik
Comment Utility
0
 
LVL 15

Author Comment

by:myselfrandhawa
Comment Utility
i have posted the code of your second link but that code does not work in any case

0
 
LVL 27

Expert Comment

by:azadisaryev
Comment Utility
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
0
 
LVL 15

Author Comment

by:myselfrandhawa
Comment Utility
  • 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
0
 
LVL 27

Assisted Solution

by:azadisaryev
azadisaryev earned 50 total points
Comment Utility
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)

Azadi
0
 
LVL 15

Author Comment

by:myselfrandhawa
Comment Utility
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
0
 
LVL 27

Expert Comment

by:azadisaryev
Comment Utility
> 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

0
 
LVL 15

Author Comment

by:myselfrandhawa
Comment Utility
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
0
 
LVL 27

Expert Comment

by:azadisaryev
Comment Utility
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
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 15

Author Comment

by:myselfrandhawa
Comment Utility
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

0
 
LVL 2

Accepted Solution

by:
albrandwood earned 250 total points
Comment Utility
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
</cfquery>
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
</cfquery>

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

            <cfbreak>

        </cfif>

    </cfloop>

</cfloop>

<cfparam name="cookie.language" default="EN">

<cfquery dbtype="query" name="session.content">

    SELECT id,EN,#cookie.language# AS word

      FROM application.multilingual_content

</cfquery>

Open in new window

0
 
LVL 2

Expert Comment

by:albrandwood
Comment Utility
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)
0
 
LVL 15

Author Comment

by:myselfrandhawa
Comment Utility
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
0
 
LVL 39

Assisted Solution

by:gdemaria
gdemaria earned 200 total points
Comment Utility
>  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

EN/home.gif
FR/home.gif
GR/home.gif

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.
0
 
LVL 15

Author Comment

by:myselfrandhawa
Comment Utility
will the user entered info will appear in english, no matter which language is used?
is this what u are saying
0
 
LVL 39

Expert Comment

by:gdemaria
Comment Utility
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.  

0
 
LVL 15

Author Comment

by:myselfrandhawa
Comment Utility
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
0
 
LVL 15

Author Closing Comment

by:myselfrandhawa
Comment Utility
Thanks Mates
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

This is an updated version of a post made on my blog over 3 years ago. It is unfortunately, still very relevant as we continue to see both SQLi (SQL injection) and XSS (cross site scripting) attacks hitting some of the most recognizable website and …
I spent nearly three days trying to figure out how incorporate OAuth in Coldfusion for the Eventful API. Hopefully, this article will allow Coldfusion Programmers to buzz through the API when they need to. Basically, what this script does is authori…
The purpose of this video is to demonstrate how to insert an Iframe into WordPress. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Open Page or Post…
The purpose of this video is to demonstrate how to set up basic WordPress SEO. This will be demonstrated using a Windows 8 PC. The plugin used will be WordPress SEO by Yoast. Go to your WordPress login page. This will look like the following: myw…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now