diff --git a/src/languages/chinese.csv b/src/languages/chinese.csv index c35e2243..c0cc2346 100644 --- a/src/languages/chinese.csv +++ b/src/languages/chinese.csv @@ -17,28 +17,31 @@ dump,转储 write,写入 snap,快照 table,表格 -wait,等待 live,互动 -check,验证 download,下载 upload,上载 load,加载 receive,接收 frame,框架 popup,弹出 +wait,等待 timeout,倒数 seconds,秒 second,秒 api,api dom,dom js,js -as,为 -to,到 +else if,否则如果 +else,否则 +if,如果 +for,让 +while,当 +check,验证 more than or equals to,多过或等于 -greater than or equals to,多过或等于 -higher than or equals to,多过或等于 more than or equal to,多过或等于 +greater than or equals to,多过或等于 greater than or equal to,多过或等于 +higher than or equals to,多过或等于 higher than or equal to,多过或等于 less than or equals to,少过或等于 less than or equal to,少过或等于 @@ -62,7 +65,6 @@ contains,包括 contain,包括 and,和 or,或 -while,当 from,从 -for,让 -if,如果 +to,到 +as,为 diff --git a/src/translate.php b/src/translate.php index ccf7e923..bb6a3807 100644 --- a/src/translate.php +++ b/src/translate.php @@ -2,6 +2,28 @@ /* MULTI-LANGUAGE TRANSLATION SCRIPT FOR TAGUI FRAMEWORK ~ TEBEL.ORG */ +// english is used as reference language, define keywords for contextual translation + +// list of keywords that are supposed to be at the start of a flow statement +$start_keywords = '|click|tap|move|hover|type|enter|select|choose|read|fetch|show|print|save|echo|dump|write|snap|table|'; +$start_keywords.='wait|live|download|upload|load|receive|frame|popup|timeout|api|dom|js|else if|else|if|for|while|check|'; + +// list of keywords at start of flow statement for valid to and as separators +$to_separator_keywords = '|read|fetch|save|load|dump|write|snap|table|download|receive|for|'; +$as_separator_keywords = '|type|enter|select|choose|upload|'; + +// list of keywords that are supposed to happen specifically after for loop +$forloop_keywords = '|from|'; + +// list of keywords that are supposed to happen in conditions (after - else if, if, for, while, check) +$conditions_keywords = '|more than or equals to|more than or equal to|greater than or equals to|greater than or equal to|higher than or equals to|higher than or equal to|less than or equals to|less than or equal to|lesser than or equals to|lesser than or equal to|lower than or equals to|lower than or equal to|more than|greater than|higher than|less than|lesser than|lower than|not equals to|not equal to|equals to|equal to|not contains|not contain|contains|contain|and|or|'; + +// list of keywords at start of flow statement for valid conditions +$start_conditions_keywords = '|else if|if|for|while|check|'; + +// list of seconds keywords that are supposed to happen after wait and timeout steps +$seconds_keywords = '|seconds|second|'; $start_seconds_keywords = '|wait|timeout|'; + // experimental entry point $source_flow = $argv[1]; if ($source_flow=="") die("ERROR - specify flow filename as first parameter\n"); $direction = $argv[2]; if ($direction=="") die("ERROR - specify to or from as third parameter\n"); @@ -26,10 +48,39 @@ while(!feof($source_file)) {fwrite($target_file,translate_intent(fgets($source_file)));} fclose($source_file); fclose($target_file); -function translate_intent($script_line) { -$script_line = ' '.trim($script_line).' '; // use padding to prevent false replacement when a match happens mid-string -for ($language_check = 1; $language_check <= $GLOBALS['language_count']; $language_check++) -$script_line = str_replace(' '.$GLOBALS['language_data'][$language_check][$GLOBALS['column_from']].' ',' '.$GLOBALS['language_data'][$language_check][$GLOBALS['column_to']].' ',$script_line); return trim($script_line)."\n"; -} +// function to perform translation of automation flow by processing each flow line +function translate_intent($script_line) {if ($script_line == "") return ""; // avoid next line character if none +// use special padding to reduce mistakes by preventing false replacement when a match happens mid-string +$script_line = '[START_OF_LINE]'.trim($script_line).'[END_OF_LINE]'; // special padding to be removed later +$start_word = '[NOT_ASSIGNED]'; // used for tracking which start keyword the flow statement starts with + +for ($language_check = 1; $language_check <= $GLOBALS['language_count']; $language_check++) { + +if (strpos($GLOBALS['start_keywords'],'|'.$GLOBALS['language_data'][$language_check][0].'|')!==false) +{if ($start_word != '[NOT_ASSIGNED]') continue; // skip processing for start keyword if one is already found +$script_line = str_replace('[START_OF_LINE]'.$GLOBALS['language_data'][$language_check][$GLOBALS['column_from']].' ','[START_OF_LINE]'.$GLOBALS['language_data'][$language_check][$GLOBALS['column_to']].' ',$script_line,$replace_count); +if ($replace_count > 0) $start_word = $GLOBALS['language_data'][$language_check][0];} + +else if (strpos($GLOBALS['conditions_keywords'],'|'.$GLOBALS['language_data'][$language_check][0].'|')!==false) { +if (($start_word != '[NOT_ASSIGNED]') and (strpos($GLOBALS['start_conditions_keywords'],'|'.$start_word.'|')!==false)) +$script_line = str_replace(' '.$GLOBALS['language_data'][$language_check][$GLOBALS['column_from']].' ',' '.$GLOBALS['language_data'][$language_check][$GLOBALS['column_to']].' ',$script_line);} + +else if (strpos($GLOBALS['seconds_keywords'],'|'.$GLOBALS['language_data'][$language_check][0].'|')!==false) { +if (($start_word != '[NOT_ASSIGNED]') and (strpos($GLOBALS['start_seconds_keywords'],'|'.$start_word.'|')!==false)) +$script_line = str_replace(' '.$GLOBALS['language_data'][$language_check][$GLOBALS['column_from']].'[END_OF_LINE]',' '.$GLOBALS['language_data'][$language_check][$GLOBALS['column_to']].'[END_OF_LINE]',$script_line);} + +else if (strpos($GLOBALS['forloop_keywords'],'|'.$GLOBALS['language_data'][$language_check][0].'|')!==false) { +if ($start_word == 'for') $script_line = str_replace(' '.$GLOBALS['language_data'][$language_check][$GLOBALS['column_from']].' ',' '.$GLOBALS['language_data'][$language_check][$GLOBALS['column_to']].' ',$script_line);} + +else if ($GLOBALS['language_data'][$language_check][0]=='to') { +if (($start_word != '[NOT_ASSIGNED]') and (strpos($GLOBALS['to_separator_keywords'],'|'.$start_word.'|')!==false)) +$script_line = str_replace(' '.$GLOBALS['language_data'][$language_check][$GLOBALS['column_from']].' ',' '.$GLOBALS['language_data'][$language_check][$GLOBALS['column_to']].' ',$script_line);} + +else if ($GLOBALS['language_data'][$language_check][0]=='as') { +if (($start_word != '[NOT_ASSIGNED]') and (strpos($GLOBALS['as_separator_keywords'],'|'.$start_word.'|')!==false)) +$script_line = str_replace(' '.$GLOBALS['language_data'][$language_check][$GLOBALS['column_from']].' ',' '.$GLOBALS['language_data'][$language_check][$GLOBALS['column_to']].' ',$script_line);}} + +$script_line = str_replace('[START_OF_LINE]','',str_replace('[END_OF_LINE]','',$script_line)); +return trim($script_line)."\n";} ?>