function try_to_translate($translations, $w) { if (isset($translations[strtolower($w)])) { $t = $translations[strtolower($w)]; // echo("english $w romanian $t[ro] \n"); // create the spelling for each of the languages $source = array(); foreach ($t as $c => $sp) { $source['layers'][0]['lang'][$c]['sp'] = $sp; } $c = addslashes(json_encode($source, JSON_UNESCAPED_UNICODE)); // if we don't have the data yet then insert it // this ensures that cards generated with older data still point // to relevant source information. Presumably during the card // generation phase these can then be identified and uncoupled // from the older version data. if (sql_simple_query("select count(*) from sourcedata where chunk='{$c}'") == 0) { mysql_query("insert into sourcedata set chunk = '{$c}'"); } } else { echo "english {$w} ??????\n"; } }
function learn(&$user, $filter) { $card = next_card($user, $filter); if ($card == NULL) { return false; } $user_card = sql_single_query("select * from user_cards where user_id = {$user['id']} and card_id = {$card['id']}"); $mylang = $user['language']; // pick out the second language from a (for example: /en-ro/) tag (which should be the first tag) // note this only works for language cards, this needs work WORK !!! $learning = substr($card['tags'], 4, 2); $language = get_translated_language($mylang, $learning); $prompt = array("en" => "What is the {$language} for ", "nl" => "Wat is het {$language} voor", "de" => "Wie sagt man auf {$language}", "ro" => "Cum se zice in {$language}")[$mylang]; $goodanswer = array("en" => "the right answer was", "nl" => "het goede antwoord was", "de" => "die richtige antword war", "ro" => "bun resuns e"); $front = json_decode($card['front'], 1); $back = json_decode($card['back'], 1); $exposure_start = microtime(true); // prompt the user and wait for the answer if (abs($user_card['first'] - time(0)) < 5) { $fresh = red("*"); } else { $fresh = " "; } $answer = termline("{$fresh} {$prompt}: " . color_string($front['sp'], "yellow") . " "); $exposure_took = intval(1000 * (microtime(true) - $exposure_start)); if ($answer === NULL) { return false; } if (process_answer($user, $card, $answer, $exposure_took)) { echo correct($mylang); $user['ngood']++; } else { $user['nfalse']++; echo $goodanswer[$mylang] . ": " . color_string($back['sp'], "yellow") . "\n"; echo wrong($mylang); } $ratio = intval(100 * ($user['ngood'] / ($user['ngood'] + $user['nfalse']))); $interval = sql_simple_query("select `interval` from user_cards where id={$user_card['id']}"); echo "! took {$exposure_took} ms, right this session: {$ratio}% total score {$user['score']} next in {$interval} seconds\n"; echo "\n"; echo "\n"; return true; }