2 define(
'TRANSLATION_STATUS_UNTRANSLATED',8);
3 define(
'TRANSLATION_STATUS_UNKNOWN',0);
4 define(
'TRANSLATION_STATUS_SOURCE',1);
5 define(
'TRANSLATION_STATUS_MACHINE',2);
6 define(
'TRANSLATION_STATUS_UNVERIFIED', 3);
7 define(
'TRANSLATION_STATUS_APPROVED',4);
8 define(
'TRANSLATION_STATUS_NEEDS_UPDATE',5);
9 define(
'TRANSLATION_STATUS_NEEDS_UPDATE_MACHINE',6);
10 define(
'TRANSLATION_STATUS_NEEDS_UPDATE_UNVERIFIED',7);
11 define(
'TRANSLATION_STATUS_EXTERNAL', 9);
18 'id'=>array(
'Field'=>
'id',
'Type'=>
'int(11)',
'Key'=>
'PRI',
'Null'=>
'NOT NULL',
'Extra'=>
'auto_increment'),
19 'record_id'=>array(
'Field'=>
'record_id',
'Type'=>
'varchar(126)',
'Key'=>
'record_key',
'Null'=>
'NOT NULL',
'Extra'=>
''),
20 'language'=>array(
'Field'=>
'language',
'Type'=>
'varchar(2)',
'Key'=>
'record_key',
'Null'=>
'NOT NULL',
'Extra'=>
''),
21 'table'=>array(
'Field'=>
'table',
'Type'=>
'varchar(128)',
'Key'=>
'record_key',
'Null'=>
'NOT NULL',
'Extra'=>
''),
22 'version'=>array(
'Field'=>
'version',
'Type'=>
'int(11)',
'Key'=>
'',
'Null'=>
'NOT NULL',
'Default'=>1,
'Extra'=>
''),
23 'translation_status'=>array(
'Field'=>
'translation_status',
'Type'=>
'int(11)',
'Key'=>
'',
'Null'=>
'NOT NULL',
'Default'=>0,
'Extra'=>
''),
24 'last_modified'=>array(
'Field'=>
'last_modified',
'Type'=>
'datetime',
'Key'=>
'',
'Null'=>
'',
'Default'=>
'0000-00-00',
'Extra'=>
'')
28 'id'=>array(
'Field'=>
'id',
'Type'=>
'int(11)',
'Key'=>
'PRI',
'Null'=>
'NOT NULL',
'Extra'=>
'auto_increment'),
29 'record_id'=>array(
'Field'=>
'record_id',
'Type'=>
'varchar(126)',
'Key'=>
'record_key',
'Null'=>
'NOT NULL',
'Extra'=>
''),
30 'language'=>array(
'Field'=>
'language',
'Type'=>
'varchar(2)',
'Key'=>
'record_key',
'Null'=>
'NOT NULL',
'Extra'=>
''),
31 'url'=>array(
'Field'=>
'url',
'Type'=>
'text',
'Key'=>
'',
'Null'=>
'NOT NULL',
'Default'=>
'',
'Extra'=>
''),
32 'original_text'=>array(
'Field'=>
'original_text',
'Type'=>
'text',
'Key'=>
'',
'Null'=>
'NOT NULL',
'Default'=>
'',
'Extra'=>
''),
33 'translated_text'=>array(
'Field'=>
'translated_text',
'Type'=>
'text',
'Key'=>
'',
'Null'=>
'NOT NULL',
'Default'=>
'',
'Extra'=>
''),
34 'translated_by'=>array(
'Field'=>
'translated_by',
'Type'=>
'varchar(128)',
'Key'=>
'',
'Null'=>
'NOT NULL',
'Default'=>
'',
'Extra'=>
''),
35 'date_submitted'=>array(
'Field'=>
'last_modified',
'Type'=>
'timestamp',
'Key'=>
'',
'Null'=>
'',
'Default'=>
'',
'Extra'=>
'')
76 $default = $trec->val(
'translation_status');
80 <select name=
"$name" onchange=
'$onchange'>
82 if ( $default == -1 ){
84 <option value=
"-1" selected>No translation provided</option>
87 foreach ( $this->translation_status_codes as $key=>$val){
88 if ( $default == $key ) $selected =
"selected";
91 <option value=
"$key" $selected>$val</option>
95 return implode(
"\n",
$out);
103 $sql =
"create table if not exists `dataface__translations` (";
105 $primary_key_cols = array();
106 $other_keys = array();
107 foreach ($this->schema as
$field){
108 $default = (isset($field[
'Default']) ?
"DEFAULT '{$field['Default']}'" :
'');
109 $cols[] =
"`{$field['Field']}` {$field['Type']} {$field['Extra']} {$field['Null']} {$default}";
110 if ( strcasecmp($field[
'Key'],
'PRI') === 0 ){
111 $primary_key_cols[$field[
'Field']] =
$field;
112 }
else if ( $field[
'Key'] ){
113 $other_keys[$field[
'Key']][$field[
'Field']] =
$field;
117 $sql .= implode(
',',$cols).
", PRIMARY KEY (`".implode(
'`,`',array_keys($primary_key_cols)).
"`)";
118 if ( count($other_keys) > 0 ){
120 foreach ($other_keys as $key_name=>$key){
121 $sql .=
"KEY `$key_name` (`".implode(
'`,`',array_keys($key)).
"`)";
126 $res = mysql_query($sql,
$app->db());
127 if ( !$res ) {
throw new Exception(mysql_error(
$app->db()), E_USER_ERROR);}
137 $res = mysql_query(
"show columns from `dataface__translations`",
$app->db());
138 if ( !$res )
throw new Exception(mysql_error(
$app->db()), E_USER_ERROR);
140 while ( $row = mysql_fetch_assoc($res) ){
141 $cols[$row[
'Field']] = $row;
143 foreach ($this->schema as
$field ){
144 if (!isset($cols[$field[
'Field']]) ){
145 $default = (isset($field[
'Default']) ?
"DEFAULT '{$field['Default']}'" :
'');
146 $sql =
"alter table `dataface__translations` add column `{$field['Field']}` {$field['Type']} {$field['Null']} {$default}";
147 $res = mysql_query($sql,
$app->db());
148 if (!$res )
throw new Exception(mysql_error(
$app->db()), E_USER_ERROR);
161 $sql =
"create table if not exists `dataface__translation_submissions` (";
163 $primary_key_cols = array();
164 $other_keys = array();
165 foreach ($this->submission_schema as
$field){
166 $default = (isset($field[
'Default']) ?
"DEFAULT '{$field['Default']}'" :
'');
167 $cols[] =
"`{$field['Field']}` {$field['Type']} {$field['Extra']} {$field['Null']} {$default}";
168 if ( strcasecmp($field[
'Key'],
'PRI') === 0 ){
169 $primary_key_cols[$field[
'Field']] =
$field;
170 }
else if ( $field[
'Key'] ){
171 $other_keys[$field[
'Key']][$field[
'Field']] =
$field;
175 $sql .= implode(
',',$cols).
", PRIMARY KEY (`".implode(
'`,`',array_keys($primary_key_cols)).
"`)";
176 if ( count($other_keys) > 0 ){
178 foreach ($other_keys as $key_name=>$key){
179 $sql .=
"KEY `$key_name` (`".implode(
'`,`',array_keys($key)).
"`)";
184 $res = mysql_query($sql,
$app->db());
185 if ( !$res ) {echo $sql;
throw new Exception(mysql_error(
$app->db()), E_USER_ERROR);}
195 $res = mysql_query(
"show columns from `dataface__translation_submissions`",
$app->db());
196 if ( !$res )
throw new Exception(mysql_error(
$app->db()), E_USER_ERROR);
198 while ( $row = mysql_fetch_assoc($res) ){
199 $cols[$row[
'Field']] = $row;
201 foreach ($this->submission_schema as
$field ){
202 if (!isset($cols[$field[
'Field']]) ){
203 $default = (isset($field[
'Default']) ?
"DEFAULT '{$field['Default']}'" :
'');
204 $sql =
"alter table `dataface__translation_submissions` add column `{$field['Field']}` {$field['Type']} {$field['Null']} {$default}";
205 $res = mysql_query($sql,
$app->db());
206 if (!$res )
throw new Exception(mysql_error(
$app->db()), E_USER_ERROR);
218 $trec =
new Dataface_Record(
'dataface__translation_submissions', array());
219 $trec->setValues($params);
228 throw new Exception(
"No record provided");
230 $vals = $record->strvals(array_keys($record->_table->keys()));
232 foreach ($vals as $key=>$val){
233 $parts[] = urlencode($key).
'='.urlencode($val);
235 return implode(
'&',$parts);
244 $sql =
"select `id` from `dataface__translations` where `record_id`='".addslashes($this->
getRecordId($record)).
"' and `table`='".addslashes($record->_table->tablename).
"' and `language`='".addslashes($language).
"' limit 1";
245 $res = mysql_query($sql,
$app->db());
248 $res = mysql_query($sql,
$app->db());
250 throw new Exception(mysql_error(
$app->db()), E_USER_ERROR);
253 if ( mysql_num_rows($res) === 0 ){
254 @mysql_free_result($res);
255 $sql =
"insert into `dataface__translations` (`record_id`,`language`,`table`,`last_modified`) VALUES (
257 '".addslashes($language).
"',
258 '".addslashes($record->_table->tablename).
"',
261 $res = mysql_query($sql,
$app->db());
264 $res = mysql_query($sql,
$app->db());
266 throw new Exception(mysql_error(
$app->db()), E_USER_ERROR);
269 $id = mysql_insert_id(
$app->db());
271 list($id) = mysql_fetch_row($res);
272 @mysql_free_result($res);
289 $trecord =& df_get_record(
'dataface__translations', array(
'id'=>$id));
290 if ( !isset($trecord) ) {
292 $trecord =& df_get_record(
'dataface__translations', array(
'id'=>$id));
293 if ( !isset($trecord) )
throw new Exception(
"Error loading translation record for translation id '$id'", E_USER_ERROR);
309 return $trecord->val(
'version');
321 $trecord->setValue(
'version', $trecord->val(
'version')+1);
323 $res = $trecord->save();
345 $records = df_get_records(
'dataface__translations',array(
'record_id'=>
'='.$this->
getRecordId($record),
'table'=>$record->_table->tablename));
347 throw new Exception($records->toString(), E_USER_ERROR);
349 while ($records->hasNext()){
350 $trecord =& $records->next();
352 switch($trecord->val(
'translation_status')){
369 $res = $trecord->save();
380 $trecord->setValue(
'translation_status', $status);
385 $trecord->setValue(
'version', $def_record->val(
'version'));
404 switch ($trecord->val(
'translation_status')){
408 $keyvals = $record->strvals(array_keys($record->_table->keys()));
410 foreach ($keyvals as $key=>$val){
411 $clauses[] =
"`{$key}`='".addslashes($val).
"'";
413 if ( count($clauses) === 0 )
throw new Exception(
"Error trying to untranslate record: '".$record->getTitle().
"'. The table '".$record->_table->tablename.
"' does not appear to have a primary key.");
415 $sql =
"update `{$record->_table->tablename}_{$language}` set `{$fieldname}`=NULL where ".implode(
' and ', $clauses).
" limit 1";
417 $sql =
"delete from `{$record->_table->tablename}_{$language}` where ".implode(
' and ', $clauses).
" limit 1";
419 $res = mysql_query($sql,
$app->db());
420 if ( !$res )
throw new Exception(mysql_error(
$app->db()), E_USER_ERROR);
441 if ( !isset($lang) ) $lang =
$app->_conf[
'lang'];
442 list($major_version,$minor_version) = explode(
'.', $version);
445 import(
'Dataface/HistoryTool.php');
448 $hrecord = $ht->searchArchives($trecord, array(
'major_version'=>$major_version,
'minor_version'=>$minor_version), $lang);
449 $modified = $hrecord->strval(
'history__modified');
450 return $ht->getDiffsByDate($record, $modified, null, $lang,
$fieldname);
466 import(
'Dataface/Utilities.php');
467 import(
'Dataface/IO.php');
469 $no_fallback = @
$app->_conf[
'default_language_no_fallback'];
481 $t_tablename = $tablename.
'_'.
$app->_conf[
'default_language'];
484 $res = mysql_query(
"create table `{$tablename}_bu_".time().
"` select * from `{$tablename}`",
$app->db());
485 $sql =
"select `".join(
'`,`', array_keys(
$table->keys())).
"` from `".$tablename.
"`";
486 $res2 = mysql_query($sql,
$app->db());
488 $io->lang = $newDefault;
489 while ( $rec = mysql_fetch_assoc($res2) ){
493 $app->_conf[
'default_language_no_fallback'] = 1;
495 $record = df_get_record($tablename, $rec, $io);
498 $app->_conf[
'default_language_no_fallback'] = 0;
501 $record2->setValues($record->vals());
503 $r = $io->write($record2);
505 $log[
$tablename] =
"Failed to migrate data from table '{$t_tablename}' to '{$tablename}': ".$r->getMessage().
"'";
508 $log[
$tablename] =
"Successfully migrated data from table '{$t_tablename}' to '{$tablename}'.";
514 mysql_free_result($res2);
516 $res = mysql_query(
"create table `{$t_tablename}_bu_".time().
"` select * from `{$t_tablename}`",
$app->db());
517 $res = mysql_query(
"truncate `{$t_tablename}`",
$app->db());
525 $app->_conf[
'default_language_no_fallback'] = $no_fallback;
536 if ( count($migrations) > 0 ){
537 return "<p>The following tables need to be migrated so that the default language is stored inside the main table - not the translation table:</p>
538 <ul><li>".implode(
'</li><li>', $migrations).
"</li></ul>
539 <p>This migration is necessary because older versions of the query translation extension would automatically store translations
540 in their respective translation tables rather than the main table. However it is desirable to store the default language
541 in the default table so that other translations can fall-back to the correct default translation if the record does not
542 have a translation.</p>";
553 if ( @
$app->_conf[
'default_language_no_fallback'] )
return false;
556 $migrations = array();
557 $res = mysql_query(
"show tables",
$app->db());
559 while ( $row = mysql_fetch_row($res) ){
562 mysql_free_result($res);
564 $translation_tablename = $tablename.
"_".
$app->_conf[
'default_language'];
565 if ( mysql_num_rows($res = mysql_query(
"show tables like '".addslashes($translation_tablename).
"'",
$app->db())) > 0){
566 @mysql_free_result($res);
567 list($num) = mysql_fetch_row($res = mysql_query(
"select count(*) from `".$translation_tablename.
"`",
$app->db()));
574 mysql_free_result($res);
587 if ( !isset($language) ){
589 $language =
$app->_conf[
'lang'];
593 $status = $trec->val(
'translation_status');
596 $msg = df_translate(
'machine translation warning',
"This section was translated using a machine translator and may contain errors.");
600 $msg = df_translate(
'old machine translation warning',
"This section was translated using a machine translator and may contain errors. The original version has also been modified since this translation was completed so this translation may be out of date.");
603 case TRANSLATION_STATUS_UNVERIVIED:
604 $msg = df_translate(
'unverified translation warning',
"This translation has not been verified by an administrator yet.");
608 $msg = df_translate(
'old unverified translation warning',
"This translation has not been verified by an administrator yet. The original version has also been modified since this translation was completed so this translation may be out of date.");
612 $msg = df_translate(
'old translation warning',
"This translation may be out of date as the original version has been modified since this was last translated.");
616 if ( !@$msg )
return;
617 import(
'Dataface/ActionTool.php');
619 $actions = $at->getActions(array(
'category'=>
'translation_warning_actions',
'record_id'=>$record->getId()));
620 $actions_html =
"<ul class=\"translation_options\">";
621 foreach ($actions as $action){
622 $actions_html .= <<<END
623 <li><a href=
"{$action['url']}" title=
"{$action['description']}">{$action[
'label']}</a></li>
627 $actions_html .=
'</ul>';
630 <div
class=
"portalMessage">