joejac
Posts: 242
|
| Posted: 07/29/2010, 3:32 PM |
|
Hello,
I have a record form with a listbox. The listbox names (condition_name) contains the Key of the Translation resources, so when somebody switch language their meaning switch too according to the translation resources table
The Control Source : condition_no
Data Source Table : condition
Bound Column : condition_no
Text Column : condition_name
The listbox is no more than 10 values with its names.
I need a way to get each listbox pair, look for the translation for the corresponding:
Text Column: condition_name
and to assign the component with something like this:
$condition_name_lang = $CCSLocales->GetText($condition_name, ' ');
$Container->condition_name->SetText($condition_name_lang); // This do not work: "non object" error ...
But this is an array and I am not very much familiar with this and how CCS handle that in listboxes. I spent some hours with no success.
I appreciate a lot if somebody can help me to find the solution.
A PHP example code is very much appreciated.
Best regards
joejac
|
 |
 |
datadoit
|
| Posted: 07/29/2010, 5:46 PM |
|
Do you already have a translation defined for every possible listbox
value? So for every 'condition_name', you'll need translations for each
value. Could be daunting to maintain over time.
Since you're pulling from a database your listbox values (and not doing
'list of values'), I would recommend building your data table with those
translated values.
condition_no (INT)
en (VARCHAR)
es (VARCHAR)
etc.
where 'en', 'es' are your translated names. Then in BeforeBuildSelect
for the listbox, dynamically modify the SQL to pull the appropriate
translation field based on the session's locale.
|
|
|
 |
Oper
Posts: 1195
|
| Posted: 07/29/2010, 7:26 PM |
|
in resume dont doit CCS Way
Doit DATABASE way.
data(DOIT)
easy to use this aproach from the same database.
_________________
____________________________
http://www.7bz.com (Free CMS,CRM Developed in CCS)
http://www.PremiumWebTemplate.com
Affiliation Web Site Templates
Please do backup first |
 |
 |
datadoit
|
| Posted: 07/30/2010, 5:22 AM |
|
What he says. :)
Now, it'd be kinda nice if there were a feature in CCS to use a database
table for translations instead of (or in addition to) text files.
If there is a connection designed for your project, then selecting 'Use
Database Table for Translations' in CodeCharge would create the
appropriate table. When modifying translations, the table would be
updated instead of the text files. Or, the text files could be created
from the database table as it's edited and saved.
This would give the developer the ability to create interfaces within
their applications for users to maintain translations also.
|
|
|
 |
joejac
Posts: 242
|
| Posted: 08/07/2010, 2:29 PM |
|
Thank you Oper and datadoit,
I know your solution is the ideal, but these are control tables, not content tables, and I do not like the idea of create for these tables the counterpart for each language. I prefer to have one table with the transaction resources names and to create/read those names from the transaction resources files.
1.- I did this in the Before show event of the listbox component:
global $locale;
global $CCSLocales;
$Array_contition_name = $Container->condition_name->Values; // Get array of database table from CCS4 component
//Create translated array elements with foreach from CCS4 Translation Resource Locales
foreach ($Array_contition_name as $value) { // Read each element of the array
foreach ($value as $conditionname) {
$ConditionNameLang = $CCSLocales->GetText($conditionname, ' ');
$value_lang[] = $ConditionNameLang;
}
$Array_condition_Lang[] = $value_lang ; //Get corresponding translation and store it in new array
}
$Container->estado_no->Values = $Array_condition_Lang; // Set the value of the listbox with the corresponding translations
2.- I echo with a foreach $value_lang and the translated array is there in good order:
Condition Name Lang = 1
Condition Name Lang = Pending for Approval
Condition Name Lang = 2
Condition Name Lang = Not Finished do not Approve
Condition Name Lang = 3
Condition Name Lang = Approved and Publish
Condition Name Lang = 4
Condition Name Lang = Approved Do Not Publish
Condition Name Lang = 5
Condition Name Lang = Archive Do Not Show in Site
3.- But in the listbox, I only have repeated 5 times the first option:
Pending for Approval
Pending for Approval
Pending for Approval
Pending for Approval
Pending for Approval
4.- Do you have any idea of what am I doing wrong when I write to the Component array?
I appreciate a lot some code,
Thanks and regards
joejac
|
 |
 |
roeya
Posts: 181
|
| Posted: 08/08/2010, 6:29 AM |
|
Hi,
To handle such requirements we create a second pass for translating values from the DB:
1. In the database you'll keep values such as '{res:CCS_Pending}'
2. Create a translation for those values the CCS way
3. Use a simple hack to handle this in page BeforeOutput event:
PAGE_NAME_HERE::main_block =~ s/\{res:\s*(\w+)\}/$Common::CCSLocales->GetText($1)/iseg;
This is a Perl version but I believe PHP is similar
And that is it.
We added a request to wish list to add this feature, see : http://forums.yessoftware.com/posts.php?post_id=101557
If you think this is a good solution then please add you're name to the list there
Roey
_________________
http://www.infoneto.com/ |
 |
 |
datadoit
|
| Posted: 08/08/2010, 7:50 AM |
|
Create an entry in a database table AND create a translation in CCS?
Doesn't exactly sound optimum. Rather than choosing the lesser of two
evils, this proposes choosing both evils.
|
|
|
 |
joejac
Posts: 242
|
| Posted: 08/08/2010, 8:13 AM |
|
Hello and thanks for your time and information,
My problem now, that I was able to create the translated array, is to write it to the array component, any idea and code it is very much appreciated, so I can pass my array of translated listbox options to the CCS4 listbox component.
Roeya, your idea is fine, but I do not know how to implement it in php, and also if I do it, some code in other part of the application will fail. I agree with your wish but it seems that it has been closed to more posts.
Best regards
joejac
|
 |
 |
datadoit
|
| Posted: 08/08/2010, 10:55 AM |
|
http://docs.codecharge.com/studio40/html/ProgrammingTec...Values.html?toc
|
|
|
 |
|