21 import(
'Dataface/QuickForm.php');
34 if ( $lang ==
'zt' )
return 'zh-TW';
35 else if ( $lang ==
'zh' )
return 'zh-CN';
50 if ( is_string($record) ){
57 $translations =&
$table->getTranslations();
58 foreach (array_keys($translations) as $trans){
59 $table->getTranslation($trans);
62 if ( !isset($translations) || count($translations) < 2 ){
66 'scripts.Dataface.TranslationForm.ERROR_NO_TRANSLATIONS',
67 'Attempt to translate a record in a table "'.
$table->tablename.
'" that contains no translations.',
68 array(
'table'=>
$table->tablename)
73 $this->translatableLanguages = array_keys($translations);
75 $source = ( isset($source) ? $source : $this->translatableLanguages[0] );
76 $dest = ( isset($dest) ? $dest : $this->translatableLanguages[1] );
78 while ( $dest == $source ){
79 if ( $i>count($this->translatableLanguages)-1 )
throw new Exception(
"Failed to find an eligible language to translate to.");
80 $dest = $this->translatableLanguages[$i++];
85 $this->sourceLanguage = $source;
86 $this->destinationLanguage = $dest;
92 $this->
Dataface_QuickForm($record,
'', $query,
'translation_form',
false, $fieldnames, $this->destinationLanguage );
93 $this->_renderer->elementTemplate =
'Dataface_TranslationForm_element.html';
94 $this->_renderer->groupeElementTemplate =
'Dataface_TranslationForm_groupelement.html';
103 if ( isset( $this->_record ) ){
105 foreach ( array_keys($this->_table->keys()) as $key ){
106 if ( !$this->_record->val($key) ){
119 'scripts.Dataface.TranslationForm.ERROR_NO_RECORD_FOUND',
120 "No record was found to be translated."
127 foreach ( array_keys($this->_table->keys()) as $key ){
128 $query[$key] =
'='.$this->_record->strval($key);
132 foreach ( $this->translatableLanguages as $lang ){
135 $io->read($query, $record);
136 $this->records[$lang] =& $record;
140 unset($this->_record);
152 if ( is_a($res,
'HTML_QuickForm_element') and is_array($this->_dest_translatedFields) and !in_array(
$field[
'name'], $this->_dest_translatedFields ) ){
155 if (
$field[
'widget'][
'type'] !=
'hidden' ){
156 $res->setProperty(
'translation', $this->records[$this->sourceLanguage]->
display(
$field[
'name']));
163 $atts =& $this->_table->attributes();
165 import(
'Dataface/TranslationTool.php');
168 $status_selector_html = $tt->getHTMLStatusSelector($this->_record, $this->destinationLanguage,
'__translation__[status]');
169 $trec =& $tt->getTranslationRecord($this->_record, $this->destinationLanguage);
170 $strec =& $tt->getTranslationRecord($this->_record, $this->sourceLanguage);
174 <legend>".$atts[
'label'].
"</legend>
175 <table class=\"translation-form-table\">
178 <th width=\"150\" class=\"translation-label-cell-header\"><!-- Field name--></th>
179 <th width=\"325\" class=\"source-translation-cell-header\">".df_translate(
'scripts.Dataface.TranslationForm.LABEL_SOURCE_TRANSLATION',
'Source Translation').
"</th>
180 <th width=\"325\" class=\"destination-translation-cell-header\">".df_translate(
'scripts.Dataface.TranslationForm.LABEL_DESTINATION_TRANSLATION',
'Destination Translation').
"</th>
184 <tr><th>".df_translate(
'scripts.Dataface.TranslationForm.LABEL_TRANSLATION_STATUS',
'Translation Status').
":</th>
185 <td>".df_translate(
'scripts.Dataface.TranslationForm.LABEL_VERSION',
'Version').
": ".$strec->val(
'version').
"</td>
186 <td>$status_selector_html Version: ".$trec->val(
'version').
"</td>
198 $group =& $this->_table->getField($name);
205 $context = array(
'group'=>&$group,
'content'=>
'{content}');
208 $skinTool->display($context,
'Dataface_TranslationForm_group.html');
209 $o = ob_get_contents();
217 $group =& $this->_table->getFieldgroup($name);
226 <th>".$group[
'label'].
"</th>
229 <table width=\"100%\" border=\"0\">
241 import(
'Dataface/TranslationTool.php');
243 $tt->setTranslationStatus($this->_record, $this->destinationLanguage, $_POST[
'__translation__'][
'status']);
248 if ( $this->_resultSet->found()>0 ||
$this->_new ){
262 $this->accept($this->_renderer);
267 echo $this->_renderer->toHtml();
270 echo
"<p>".df_translate(
'scripts.GLOBAL.INSUFFICIENT_PERMISSIONS_TO_VIEW_RECORD',
'Sorry you have insufficient permissions to view this record.').
"</p>";
275 echo
"<p>".df_translate(
'scripts.GLOBAL.NO_RECORDS_MATCHED_REQUEST',
'No records matched your request.').
"</p>";