
AndyGB4
Posts: 122
|
| Posted: 11/12/2012, 1:14 PM |
|
Hi all,
Take this table as an example:
fieldID - (this is the id)
fieldLabelEN - (this is the name given in English)
fieldLabelFR - (this is the name given in French)
My listbox has "fieldID" as its Bound Column, and it has "fieldLabelEN" as its Text Column,
but I want the Text Column to be dependant on which language the page is in (English or French).
There is a button on the page that will change the "locale" session to "en" or "fr", so is there anyway of getting the listbox to show to correct field based on which language is selected?
thank you in advance!
|
 |
 |
bannedone
Posts: 273
|
| Posted: 11/12/2012, 2:19 PM |
|
Sure
Add another field to your listbox table maybe call it Locale
For all the French Text records put fr in that field and en in for all the English ones.
Then in Query Builder for the listbox table add to select when the new fields Locale = locale (as a session variable).

Have fun
_________________
John Real
CodeCharge Studio Support, Training, Consulting, Development, Web based solutions
http://realsites.biz
http://ccselite.com
Other Banned IDs on this Forum. jjrjr1, jjrjr2 |
 |
 |
AndyGB4
Posts: 122
|
| Posted: 11/13/2012, 6:16 AM |
|
I see what you're saying, but I don't think I can use that.
There are tons of records in this table, and having a different record for en & fr would double its size.
Also, the ID of the record chosen is important, it must be the same for the english version and french version.
Is there a way to change the listbox's Text Column on the fly? so when the page loads, it can go get the local Session and then based on the language in the session, it would populate the listbox?
|
 |
 |
bannedone
Posts: 273
|
| Posted: 11/13/2012, 6:25 AM |
|
Then try swapping out tables at run time
Create 2 tables.. one for French and one for English.
The field names for bound and text must be the same in both.
Set the listbox to use the English table.
Then in the BeforeExecuteSelect custom code for the list box. do this.
if(CCGetSession("locale","")=="fr") $Component->ds->SQL="SELECT * FROM your_french_table_name";

PS. I am curious why a list box would have TONs of records..
_________________
John Real
CodeCharge Studio Support, Training, Consulting, Development, Web based solutions
http://realsites.biz
http://ccselite.com
Other Banned IDs on this Forum. jjrjr1, jjrjr2 |
 |
 |
AndyGB4
Posts: 122
|
| Posted: 11/13/2012, 7:26 AM |
|
by the way, thanks for the replies!
If im using VBScript though, what would that line be?
if CCGetSession("locale","") = "fr" then
[?? What goes here ??] = "SELECT * FROM your_french_table_name"
end if
|
 |
 |
bannedone
Posts: 273
|
| Posted: 11/13/2012, 7:35 AM |
|
VBScript??
That is Client side coding.
The code I gave you is server side PHP code.
Put it in the Server side BeforeExecuteSelect Custom code for the listbox just as I gave it to you.
Should work fine

_________________
John Real
CodeCharge Studio Support, Training, Consulting, Development, Web based solutions
http://realsites.biz
http://ccselite.com
Other Banned IDs on this Forum. jjrjr1, jjrjr2 |
 |
 |
AndyGB4
Posts: 122
|
| Posted: 11/13/2012, 7:36 AM |
|
Quote :PS. I am curious why a list box would have TONs of records..
Yeah, you're right, I guess it doesn't have as many records as I made it seem, but it can get really messy on the admin side where the user can go edit the possible records if he has 2 of every record just in a different language
|
 |
 |
AndyGB4
Posts: 122
|
| Posted: 11/13/2012, 7:38 AM |
|
Sorry, not VBscript, my mistake lol.
I'm using "ASP 3.0 with Templates", I don't know why I said VBscript lol
I have too many projects going on, I'm going crazy! haha
|
 |
 |
bannedone
Posts: 273
|
| Posted: 11/13/2012, 8:09 AM |
|
LOL
I can relate...
Sorry I am not familiar with ASP.
Try the CCS help to find out how to modify the SQL.
I do not know the syntax for this in ASP...
Sorry

_________________
John Real
CodeCharge Studio Support, Training, Consulting, Development, Web based solutions
http://realsites.biz
http://ccselite.com
Other Banned IDs on this Forum. jjrjr1, jjrjr2 |
 |
 |
AndyGB4
Posts: 122
|
| Posted: 11/13/2012, 8:12 AM |
|
No problem, thanks for all the help, I think I found how to access the SQL,
something like this:
myFormName.myComponentName.Datasource.SQL = " ... "
|
 |
 |
bannedone
Posts: 273
|
| Posted: 11/13/2012, 8:15 AM |
|
Quote AndyGB4:
Yeah, you're right, I guess it doesn't have as many records as I made it seem, but it can get really messy on the admin side where the user can go edit the possible records if he has 2 of every record just in a different language
If using a single table with a language field......
You could make your maintenance page for add/edit this listbox table to also be language sensitive using the locale session variable.
In other words when language is set to English, only the English records are managed edited or added. Same with French..
To the Admin it would look like 2 different tables.
Just saw you found the ASP equivalent to my PHP code.
GREAT.

BTW.. When I have developed muti-lang sites I have always opted for the table switch out method.
_________________
John Real
CodeCharge Studio Support, Training, Consulting, Development, Web based solutions
http://realsites.biz
http://ccselite.com
Other Banned IDs on this Forum. jjrjr1, jjrjr2 |
 |
 |
AndyGB4
Posts: 122
|
| Posted: 11/13/2012, 8:18 AM |
|
Yes, you're right, I'll have to ask my client, but that seems like a good solution.
|
 |
 |
AndyGB4
Posts: 122
|
| Posted: 11/13/2012, 9:05 AM |
|
I figured out the solution I needed!
OK so my listbox is in an Editable Grid, so in the Event "BeforeShowRow",
I added something like this:
'if french
if Session("locale")="fr" then
myFormName.lz_myComponentName.DataSource.SQL = "SELECT fieldID, fieldLabelEN AS useThisLabel FROM tableName"
else
'not french, so just put english
myFormName.lz_myComponentName.DataSource.SQL = "SELECT fieldID, fieldLabelFR AS useThisLabel FROM tableName"
end if
And for the ListBox's Text Column property, you would put "useThisLabel".
So for anyone else that this might help in the future,
basically, when the page loads, before it creates the row, it will check the language, and if its FR, set the FR field as the "useThisLabel". If its not FR show EN as default, and go get the EN field.
This way, although Text Column property only allows for 1 field, you can manage to get whichever field you want by using an alias!
Thanks again for all your help bannedone!
|
 |
 |
DataDoIT
|
| Posted: 11/13/2012, 11:36 AM |
|
Your best practice going forward is as has been suggested, and that's to
make your data table structure relational for the varying locales that
will be used. Use the locale key as is defined in CCS and in standards.
(ie: en for English, fr for French, etc.).
The more normalized your table structure the less language-centric your
application has to be. CodeCharge will be able to handle this scenario
and create the appropriate code for you, no matter which language you
choose. That's the whole point behind using CodeCharge Studio I think.
|
|
|
 |
|

|
|
|
|