function gen_description($user_lang, $target_lang) { $descriptions = array("en" => "for English speakers.", "nl" => "voor Nederlands sprekenden.", "ro" => "pentru Romani.", "de" => "fur Deutsch sprachichen."); return get_translated_language($user_lang, $target_lang) . " " . $descriptions[$user_lang]; }
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; }