Index: trunk/extensions/Wikidata/util/voctrain/i18n/messages/Messages_Default.php |
— | — | @@ -2,6 +2,6 @@ |
3 | 3 | |
4 | 4 | $fallback=false; |
5 | 5 | |
6 | | -require_once("Messages_eng.php"); |
| 6 | +include("Messages_eng.php"); |
7 | 7 | |
8 | 8 | ?> |
Index: trunk/extensions/Wikidata/util/voctrain/i18n/messages/Messages_eng.php |
— | — | @@ -54,6 +54,14 @@ |
55 | 55 | "Omegawiki"=>"Omegawiki", |
56 | 56 | "Exercise complete"=>"Exercise complete", |
57 | 57 | "Exercise terminated"=>"Exercise terminated", |
58 | | - "Start a new exercise"=>"Start a new exercise" |
| 58 | + "Start a new exercise"=>"Start a new exercise", |
| 59 | + "User name"=>"User name", |
| 60 | + "Password"=>"Password", |
| 61 | + "Login"=>"Login", |
| 62 | + "Create new user"=>"Create new user", |
| 63 | + "Switch language"=>"Switch language", |
| 64 | + "Language"=>"Language", |
| 65 | + "Log in"=>"Log in", |
| 66 | + "Omegawiki vocabulary trainer"=>"Omegawiki vocabulary trainer" |
59 | 67 | ); |
60 | 68 | ?> |
Index: trunk/extensions/Wikidata/util/voctrain/i18n/messages/Messages_nld.php |
— | — | @@ -21,9 +21,9 @@ |
22 | 22 | "Set up your exercise"=>"Stel uw oefening op", |
23 | 23 | "Number of questions"=>"Aantal vragen", |
24 | 24 | "Languages"=>"Talen", |
25 | | - "Please specify the languages you want to test in"=>"Geef aub de talen op waarin je wilt oefen", |
| 25 | + "Please specify the languages you want to test in"=>"Geef aub de talen op waarin u wilt oefen", |
26 | 26 | "(eg, eng for English, deu for Deutch (German))."=>"(bijv, eng voor English (Engels), deu voor Deutch (Duits)).", |
27 | | - "Depending on your test set, some combinations might work better than others."=>"Afhankelijk van je testset, werken sommige combinaties beter dan anderen.", |
| 27 | + "Depending on your test set, some combinations might work better than others."=>"Afhankelijk van uw testset, werken sommige combinaties beter dan anderen.", |
28 | 28 | "Questions"=>"Vragen", |
29 | 29 | "Answers"=>"Antwoorden", |
30 | 30 | "start exercise"=>"start oefening", |
— | — | @@ -32,7 +32,7 @@ |
33 | 33 | "There are %questions_remaining questions remaining, out of a total of %questions_total."=> |
34 | 34 | "Er zikn nog %questions_remaining over, uit een totaal van %questions_total.", |
35 | 35 | "Definition"=>"Definitie", |
36 | | - "Dictionary definition to help you"=>"Dictionary definitie om je te helpen", |
| 36 | + "Dictionary definition to help you"=>"Woordenboek definitie om u te helpen", |
37 | 37 | "Word"=>"Woord", |
38 | 38 | "Please type your answer here"=>"Typ alstublieft hier uw antwoord.", |
39 | 39 | "submit answer"=>"antwoord submitten", |
— | — | @@ -52,6 +52,13 @@ |
53 | 53 | "Omegawiki"=>"Omegawiki", |
54 | 54 | "Exercise complete"=>"Oefening voltooid", |
55 | 55 | "Exercise terminated"=>"Oefening afgebroken", |
56 | | - "Start a new exercise"=>"Start een nieuwe oefening" |
| 56 | + "Start a new exercise"=>"Start een nieuwe oefening", |
| 57 | + "User name"=>"Gebruikersnaam", |
| 58 | + "Password"=>"Wachtwoord", |
| 59 | + "Login"=>"Inloggen", |
| 60 | + "Create new user"=>"Nieuwe gebruiker aanmaken", |
| 61 | + "Switch language"=>"Wijzig taal", |
| 62 | + "Language"=>"Taal" |
| 63 | + |
57 | 64 | ); |
58 | 65 | ?> |
Index: trunk/extensions/Wikidata/util/voctrain/i18n/language.php |
— | — | @@ -10,25 +10,28 @@ |
11 | 11 | class Language { |
12 | 12 | |
13 | 13 | private $code; #language code, mostly for debugging purposes |
14 | | - private $messages; |
15 | | - private $fallback=false; |
| 14 | + private $messages; # assoc array of translations |
| 15 | + private $fallback=false; #a different Language object to fall back to |
| 16 | + # if we can't find a particular entry in $messages |
16 | 17 | |
17 | | - public function __construct($code=null) { |
| 18 | + public function __construct($code="Default") { |
| 19 | + if (!$code) |
| 20 | + $code="Default"; |
18 | 21 | $this->code=$code; |
19 | | - if ($code) |
20 | | - $this->loadMessages($code); |
| 22 | + $this->loadMessages($code); |
21 | 23 | |
| 24 | + |
22 | 25 | } |
23 | 26 | |
24 | 27 | public function loadMessages($code="Default") { |
25 | | - $messages="Messages_$code.php"; |
26 | | - $path=dirname(__FILE__)."/messages/$messages"; |
| 28 | + $messages_filename="Messages_$code.php"; |
| 29 | + $path=dirname(__FILE__)."/messages/$messages_filename"; |
27 | 30 | if (file_exists($path)) { |
28 | 31 | include($path); |
29 | 32 | if (isset($messages)) { |
30 | 33 | $this->messages=$messages; #messages is from the included file |
31 | 34 | } else { |
32 | | - throw new LocalisationException("messages file format problem, there's no $messages"); |
| 35 | + throw new LocalisationException("messages file format problem, there's no messages in $path"); |
33 | 36 | } |
34 | 37 | |
35 | 38 | if (isset($fallback)) { |
— | — | @@ -58,13 +61,11 @@ |
59 | 62 | $languageNames=Language::getAllLanguageNames(); |
60 | 63 | |
61 | 64 | $messageFiles = glob( dirname(__FILE__)."/messages/Messages_*.php" ); |
62 | | - var_dump($messageFiles); |
63 | 65 | $names = array(); |
64 | 66 | foreach ( $messageFiles as $file ) { |
65 | 67 | $m = array(); |
66 | 68 | if( preg_match( '/Messages_([a-z_]+)\.php$/', $file, $m ) ) { |
67 | 69 | $code = str_replace( '_', '-', strtolower( $m[1] ) ); |
68 | | - var_dump($code); |
69 | 70 | if ( isset( $languageNames[$code] ) ) { |
70 | 71 | $names[$code] = $languageNames[$code]; |
71 | 72 | } |
— | — | @@ -81,7 +82,8 @@ |
82 | 83 | } |
83 | 84 | } |
84 | 85 | |
85 | | - /** translate the phrase, but doesn't do any substitutions. use printf,sprintf, or vsprintf for that */ |
| 86 | + /** translate the phrase, but doesn't do any substitutions. |
| 87 | + * Use printf,sprintf, or vsprintf etc... for subsitutions */ |
86 | 88 | public function translate($phrase) { |
87 | 89 | if ($this->translation_exists($phrase)) { |
88 | 90 | return $this->messages[$phrase]; |
— | — | @@ -94,6 +96,7 @@ |
95 | 97 | |
96 | 98 | |
97 | 99 | # == Diverse sprintf-ish functions |
| 100 | + # (see also: php documentation for non-i18nified versions) |
98 | 101 | |
99 | 102 | /** i18nsprint is a simpler way to go about things, will do i18n replacement |
100 | 103 | on antyhing enclosed in <| |>, any %signs in these substrings |
— | — | @@ -111,6 +114,7 @@ |
112 | 115 | } |
113 | 116 | |
114 | 117 | |
| 118 | + # internationalized printf |
115 | 119 | public function printf($phrase) { |
116 | 120 | $args=func_get_args(); |
117 | 121 | $str=$this->vsprintf($phrase, $args); |
— | — | @@ -129,10 +133,10 @@ |
130 | 134 | return vsprintf($this->translate($phrase),$array); |
131 | 135 | } |
132 | 136 | |
133 | | - /** assoc variant on vsprintf, |
| 137 | + /** assoc variant of vsprintf, |
134 | 138 | * (modified from sprintf2 by "matt", 10-Mar-2008 06:13, |
135 | 139 | * http://nl2.php.net/manual/en/function.sprintf.php ) |
136 | | - * original Apparently Copyright © 2001-2008 The PHP Group, copied here |
| 140 | + * original apparently Copyright © 2001-2008 The PHP Group, copied here |
137 | 141 | * on condition that copyright notice is retained. ) |
138 | 142 | */ |
139 | 143 | function vsprintf2($phrase='', $vars=array(), $char='%') { |
Index: trunk/extensions/Wikidata/util/voctrain/model.php |
— | — | @@ -45,6 +45,24 @@ |
46 | 46 | $empty=DBTools::doQuery("UPDATE exercises SET completion=100 WHERE id='$id'"); |
47 | 47 | } |
48 | 48 | |
| 49 | + |
| 50 | + public function setUserLanguage($username, $language) { |
| 51 | + global $mysql_info; |
| 52 | + DBTools::connect($mysql_info); |
| 53 | + |
| 54 | + $language=mysql_real_escape_string($language); |
| 55 | + $empty=DBTools::doQuery("UPDATE auth SET uiLanguage=\"$language\""); |
| 56 | + } |
| 57 | + |
| 58 | + public function getUserLanguage($username) { |
| 59 | + global $mysql_info; |
| 60 | + DBTools::connect($mysql_info); |
| 61 | + |
| 62 | + $username=mysql_real_escape_string($username); |
| 63 | + $row=DBTools::doQuery("SELECT uiLanguage from auth where username=\"$username\""); |
| 64 | + return $row["uiLanguage"]; |
| 65 | + } |
| 66 | + |
49 | 67 | /** retrieve the exercice we're using for this session */ |
50 | 68 | public function getExercise($username) { |
51 | 69 | |
Index: trunk/extensions/Wikidata/util/voctrain/view.php |
— | — | @@ -15,25 +15,59 @@ |
16 | 16 | } |
17 | 17 | # I shouldn't be dealing with $_REQUEST here neither... but this function |
18 | 18 | # breaks all the other rules anyways :-P |
| 19 | + |
| 20 | + $language=new Language('Default'); |
19 | 21 | |
20 | | - echo "<h1>Log In. Omegawiki vocabulary trainer</h1>"; |
| 22 | + $language->i18nprint("<h1><|Log in|>. <|Omegawiki vocabulary trainer|></h1>"); |
21 | 23 | if (isset($_REQUEST["defaultCollection"])) { |
22 | 24 | $defaultCollection=(int) $_REQUEST["defaultCollection"]; |
23 | 25 | echo "<form method=\"post\" action=\"trainer.php?defaultCollection=$defaultCollection\">"; |
24 | 26 | } else { |
25 | 27 | echo "<form method=\"post\" action=\"trainer.php\">"; |
26 | 28 | } |
27 | | - echo '<fieldset class="settings">'; |
28 | | - echo"<div class='datarow'><label>User name: </label><input type=\"text\" name=\"username\" /></div><br/>"; |
29 | | - echo "<div class='datarow'><label>Password: </label><input type=\"password\" name=\"password\" /></div><br/>"; |
30 | | - echo '</fieldset>'; |
31 | | - echo '<fieldset class="settings">'; |
32 | | - echo '<div class="datarow"><input type="submit" value="Login"/> <input type="submit" value="Create new user" name="new_user"></div>'; |
33 | | - echo '</fieldset>'; |
34 | | - echo "</form>"; |
| 29 | + $language->i18nprint(' |
| 30 | + <fieldset class="settings"> |
| 31 | + <div class="datarow"><label><|User name|>: </label><input type="text" name="username" /></div><br/> |
| 32 | + <div class="datarow"><label><|Password|>: </label><input type="password" name="password" /></div><br/> |
| 33 | + <div class="datarow"><label><|Language|>: </label>'._langSelect().'</div><br/> |
| 34 | + </fieldset> |
| 35 | + <fieldset class="settings"> |
| 36 | + <div class="datarow"> |
| 37 | + <input type="submit" value="<|Login|>"/> |
| 38 | + <input type="submit" value="<|Create new user|>" name="new_user"> |
| 39 | + <!--<input type="submit" value="<|Switch language|>" name="switch_language">--> |
| 40 | + </div> |
| 41 | + </fieldset> |
| 42 | + </form>'); |
35 | 43 | } |
36 | 44 | |
| 45 | +function _langSelect($default="eng") { |
| 46 | + $names=Language::getI18NLanguageNames(); |
37 | 47 | |
| 48 | + $select="<select name='userLanguage'>\n"; |
| 49 | + foreach ($names as $iso639_3=>$name){ |
| 50 | + $select .= " |
| 51 | + <option |
| 52 | + value='$iso639_3' "; |
| 53 | + |
| 54 | + if ($iso639_3 == $default) { # check-mark default language |
| 55 | + $select.= " |
| 56 | + selected"; |
| 57 | + } |
| 58 | + |
| 59 | + $select.= " |
| 60 | + > |
| 61 | + ".$name." |
| 62 | + </option> |
| 63 | + "; |
| 64 | + } |
| 65 | + $select.= "</select>\n"; |
| 66 | + return $select; |
| 67 | + |
| 68 | +} |
| 69 | + |
| 70 | + |
| 71 | + |
38 | 72 | /** ~MVC: Generate html for user interface */ |
39 | 73 | class View { |
40 | 74 | |
— | — | @@ -41,9 +75,12 @@ |
42 | 76 | public $language; |
43 | 77 | |
44 | 78 | public function __construct($language_code="Default") { |
45 | | - $this->language=new language($language_code); |
| 79 | + $this->setLanguage_byCode($language_code); |
46 | 80 | } |
47 | 81 | |
| 82 | + public function setLanguage_byCode($code) { |
| 83 | + $this->language=new Language($code); |
| 84 | + } |
48 | 85 | /** print everyones favorite friendly message! */ |
49 | 86 | public function hello() { |
50 | 87 | $this->language->i18nprint("<h1><|Hello World|></h1>"); |
— | — | @@ -128,7 +165,6 @@ |
129 | 166 | (".$collection->count.") |
130 | 167 | </option> |
131 | 168 | "; |
132 | | - flush(); |
133 | 169 | } |
134 | 170 | $select.= "</select>\n"; |
135 | 171 | return $select; |
Index: trunk/extensions/Wikidata/util/voctrain/trainer.sql |
— | — | @@ -7,6 +7,7 @@ |
8 | 8 | CREATE TABLE `auth` ( |
9 | 9 | username VARCHAR(50) default '' NOT NULL, |
10 | 10 | password VARCHAR(32) default '' NOT NULL, |
| 11 | + `uiLanguage` CHAR(3) , |
11 | 12 | PRIMARY KEY (username), |
12 | 13 | KEY (password) |
13 | 14 | ) ENGINE=INNODB; |
Index: trunk/extensions/Wikidata/util/voctrain/controller.php |
— | — | @@ -37,8 +37,10 @@ |
38 | 38 | |
39 | 39 | $this->login(); |
40 | 40 | $logged_in=$this->auth->checkAuth(); |
| 41 | + $this->setLanguage(); |
41 | 42 | if ($_REQUEST["action"]=="logout") |
42 | 43 | $logged_in=false; |
| 44 | + |
43 | 45 | $this->view->header($logged_in); |
44 | 46 | $logged_in=$this->auth->checkAuth(); |
45 | 47 | if ($logged_in) { |
— | — | @@ -71,6 +73,13 @@ |
72 | 74 | $this->run_exercise(true); |
73 | 75 | } |
74 | 76 | |
| 77 | + /** sets the ui language */ |
| 78 | + public function setLanguage() { |
| 79 | + $username=$this->auth->getUsername(); |
| 80 | + $userLanguage=$this->model->getUserLanguage($username); |
| 81 | + $this->view->setLanguage_byCode($userLanguage); |
| 82 | + } |
| 83 | + |
75 | 84 | /**create a new exercise using $this->view->exercise_setup(); |
76 | 85 | * This function sort of grew over time. TODO Cleanup. */ |
77 | 86 | public function create_exercise() { |
— | — | @@ -122,7 +131,6 @@ |
123 | 132 | public function run_exercise($continue=false) { |
124 | 133 | # obtain an exercise |
125 | 134 | $userName=$this->auth->getUsername(); |
126 | | - |
127 | 135 | $exercise=$this->model->getExercise($userName); |
128 | 136 | if ($exercise===null) { |
129 | 137 | $exercise=$this->create_exercise(); |
— | — | @@ -216,9 +224,17 @@ |
217 | 225 | $auth=new Auth("DB", $options, "_displayLogin"); |
218 | 226 | $username=$_REQUEST["username"]; |
219 | 227 | $password=$_REQUEST["password"]; |
| 228 | + #to be implemented |
| 229 | + #if ($username="") { |
| 230 | + # $this->view->provideUsername(); |
| 231 | + # $this->view->footer(); |
| 232 | + # exit; |
| 233 | + #} |
220 | 234 | $success=$auth->addUser($username, $password); |
221 | 235 | if ($success===true) { |
222 | 236 | $this->auth->setAuth($username); |
| 237 | + $this->model->setUserLanguage($username,$_REQUEST["userLanguage"]); |
| 238 | + $this->setLanguage(); |
223 | 239 | $this->view->header(true); |
224 | 240 | $this->view->userAdded($username); |
225 | 241 | $this->view->footer(); |