Index: trunk/tools/ToolserverI18N/TsIntuition.php |
— | — | @@ -29,17 +29,17 @@ |
30 | 30 | |
31 | 31 | private $localBaseDir = __DIR__; // to be moved to p_i18n |
32 | 32 | |
33 | | - private $registeredTextdomains = null; |
| 33 | + private $registeredTextdomains; |
34 | 34 | |
35 | | - private $suppresserrors = false; |
36 | | - private $suppressnotices = true; |
37 | | - private $stayalive = false; |
38 | | - private $constructLang = false; |
39 | | - private $currentTextdomain = 'general'; |
40 | | - private $useRequestParam = true; |
| 35 | + // Construct options |
| 36 | + private $currentTextdomain; |
| 37 | + private $currentLanguage; |
| 38 | + private $suppressfatal; |
| 39 | + private $suppressnotice; |
| 40 | + private $suppressbrackets; |
| 41 | + private $stayalive; |
| 42 | + private $useRequestParam; |
41 | 43 | |
42 | | - private $currentLanguage = 'en'; |
43 | | - |
44 | 44 | // Changing this will invalidate all cookies |
45 | 45 | private $cookieNames = array( |
46 | 46 | 'userlang' => 'TsIntuition_userlang', |
— | — | @@ -89,12 +89,13 @@ |
90 | 90 | * Pass a string (domain) or array (options) |
91 | 91 | * |
92 | 92 | * Options: |
93 | | - * - suppresserrors |
94 | | - * - suppressnotices |
95 | | - * - stayalive |
96 | | - * - globalfunctions |
97 | 93 | * - lang |
98 | 94 | * - domain |
| 95 | + * - globalfunctions |
| 96 | + * - suppressfatal |
| 97 | + * - suppressnotice |
| 98 | + * - suppressbrackets |
| 99 | + * - stayalive |
99 | 100 | * - param |
100 | 101 | */ |
101 | 102 | function __construct( $options = array() ) { |
— | — | @@ -103,51 +104,52 @@ |
104 | 105 | $options = array( 'domain' => $options ); |
105 | 106 | } |
106 | 107 | |
107 | | - $this->loadDomains(); |
| 108 | + $defaultOptions = array( |
| 109 | + 'domain' => 'general', |
| 110 | + 'lang' => null, |
| 111 | + 'globalfunctions' => true, |
| 112 | + 'suppressfatal' => false, |
| 113 | + 'suppressnotice' => true, |
| 114 | + 'suppressbrackets' => false, |
| 115 | + 'stayalive' => false, |
| 116 | + 'param' => true, |
| 117 | + ); |
| 118 | + $options = array_merge( $defaultOptions, $options ); |
| 119 | + |
| 120 | + $this->loadDomainRegistry(); |
108 | 121 | |
109 | | - // Allow a tool to suppress errors, which will prevent TsIntuition from showing fatal errors |
110 | | - if ( isset( $options['suppresserrors'] ) && $options['suppresserrors'] == true ) { |
111 | | - $this->suppresserrors = true; |
112 | | - $this->suppressnotices = true; |
| 122 | + // The textdomain of your tool can be set here. |
| 123 | + // Otherwise defaults to 'general'. See also documentation of msg() |
| 124 | + // First character is case-insensitive |
| 125 | + if ( isset( $options['domain'] ) ) { |
| 126 | + $this->setDomain( $options['domain'] ); |
113 | 127 | } |
114 | 128 | |
115 | | - // Allow a tool to suppress errors, which will prevent TsIntuition from showing notices |
116 | | - if ( isset( $options['suppressnotices'] ) && $options['suppressnotices'] == false ) { |
117 | | - $this->suppressnotices = false; |
| 129 | + // Allow a tool to disable the loading of global functions, |
| 130 | + // in case they have a _() and/or _e() already. |
| 131 | + if ( $options['globalfunctions'] === true ) { |
| 132 | + //require_once( $this->localBaseDir . '/Functions.php' ); |
118 | 133 | } |
119 | 134 | |
120 | | - // Allow a tool to prevent TsIntuition for exiting/dieing on fatal errors |
121 | | - if ( isset( $options['stayalive'] ) && $options['stayalive'] == true ) { |
122 | | - $this->stayalive = true; |
123 | | - } |
| 135 | + // Allow a tool to suppress fatals, which will prevent TsIntuition from showing fatal errors. |
| 136 | + $this->suppressfatal = $options['suppressfatal']; |
124 | 137 | |
125 | | - // Allow a tool to disable the loading of global functions in case they have a _() and/or _e() already |
126 | | - if ( !isset( $options['globalfunctions'] ) || $options['globalfunctions'] == true ) { |
127 | | - require_once( $this->localBaseDir . '/Functions.php' ); |
128 | | - } |
| 138 | + // Allow a tool to suppress notices, which will prevent TsIntuition from showing notices. |
| 139 | + $this->suppressnotice = $options['suppressnotice']; |
129 | 140 | |
130 | | - // If the tool doesn't want to use the cookie and parameter or would like to test something |
131 | | - // The user language can be overridden here. Note you can also override it for individual |
132 | | - // messages by passing the language code as third argument to msg(). |
133 | | - if ( isset( $options['lang'] ) ) { |
134 | | - $this->constructLang = $options['lang']; |
135 | | - } |
| 141 | + // Allow a tool to suppress brackets, msg() will return "Messagekey" instead of "[messagekey]" |
| 142 | + // if this is true. |
| 143 | + $this->suppressbrackets = $options['suppressbrackets']; |
136 | 144 | |
137 | | - // The textdomain of your tool can be set here. |
138 | | - // Otherwise defaults to 'general'. See also documentation of msg() |
139 | | - // First character is case-insensitive |
140 | | - if ( isset( $options['domain'] ) ) { |
141 | | - $this->setDomain( $options['domain'] ); |
142 | | - } |
| 145 | + // Allow a tool to prevent TsIntuition for exiting/dieing on fatal errors. |
| 146 | + $this->stayalive = $options['stayalive']; |
143 | 147 | |
144 | 148 | // TsIntuition will choose the language based on a cookie. However it |
145 | 149 | // can be manually overriden for permalinks through a request parameter. |
146 | 150 | // By default this is 'userlang'. If you need this parameter for something else |
147 | 151 | // you can disable this system here. To avoid inconsistencies between tools |
148 | 152 | // a custom parameter name will not be supported. It's either on or off. |
149 | | - if ( isset( $options['param'] ) ) { |
150 | | - $this->setUseRequestParam( false ); |
151 | | - } |
| 153 | + $this->setUseRequestParam( $options['param'] ); |
152 | 154 | |
153 | 155 | // Load the initial text domain |
154 | 156 | $this->loadTextdomain( $this->getDomain() ); |
— | — | @@ -158,8 +160,14 @@ |
159 | 161 | // Load names |
160 | 162 | $this->loadNames(); |
161 | 163 | |
| 164 | + // A tool may override the automatic initiation with cookies and paramters |
| 165 | + // (ie. during development). Note you can also override it for individual msg calls, |
| 166 | + // by passing the language code as third argument to msg(). |
| 167 | + // If options['lang'] is a non-empty string, initLangSelect will use it, |
| 168 | + // instead of it's own routine. |
| 169 | + |
162 | 170 | // Initialize language choise |
163 | | - $this->initLangSelect(); |
| 171 | + $this->initLangSelect( $options['lang'] ); |
164 | 172 | |
165 | 173 | } |
166 | 174 | |
— | — | @@ -173,11 +181,17 @@ |
174 | 182 | |
175 | 183 | /** |
176 | 184 | * Set the current language which will be used when requesting messages etc. |
177 | | - * @return true |
| 185 | + * |
| 186 | + * @param $lang String of language code (lowercase). If not a valid string |
| 187 | + * setting will stay the same and false is returned. |
| 188 | + * @return boolean |
178 | 189 | */ |
179 | 190 | public function setLang( $lang ) { |
180 | | - $this->currentLanguage = $lang; |
181 | | - return true; |
| 191 | + if ( TsIntuitionUtil::nonEmptyStr( $lang ) ) { |
| 192 | + $this->currentLanguage = $lang; |
| 193 | + return true; |
| 194 | + } |
| 195 | + return false; |
182 | 196 | } |
183 | 197 | |
184 | 198 | /** |
— | — | @@ -426,7 +440,7 @@ |
427 | 441 | if ( !is_null( $fail ) ) { |
428 | 442 | return $fail; |
429 | 443 | } |
430 | | - if ( $this->suppresserrors ) { |
| 444 | + if ( $this->suppressbrackets ) { |
431 | 445 | return ucfirst( $key ); // Keyname |
432 | 446 | } |
433 | 447 | return "[$key]"; // [keyname] |
— | — | @@ -450,7 +464,7 @@ |
451 | 465 | /** |
452 | 466 | * Adds or overwrites a message in the blob. |
453 | 467 | * This function is public so tools can use it while testing their tools |
454 | | - * and don't need a message to exist in TranslateWiki yet, but don't want to see [msgkey] either. |
| 468 | + * and don't need a message to exist in translatewiki.net yet, but don't want to see [msgkey] either. |
455 | 469 | * See also addMsgs() for registering multiple messages. |
456 | 470 | * |
457 | 471 | * First two parameters are required. Others (domain, language) default to current environment. |
— | — | @@ -795,7 +809,7 @@ |
796 | 810 | * |
797 | 811 | * @return true |
798 | 812 | */ |
799 | | - private function loadDomains(){ |
| 813 | + private function loadDomainRegistry(){ |
800 | 814 | |
801 | 815 | // Don't load twice |
802 | 816 | if ( is_array( $this->registeredTextdomains ) ) { |
— | — | @@ -906,9 +920,16 @@ |
907 | 921 | * |
908 | 922 | * @param $imgSize integer (optional) Defaults to 28px. |
909 | 923 | * If 0 or a non-integer the image will be hidden. |
| 924 | + * @param $helpTranslateDomain mixed (optional) |
| 925 | + * - null (or nothing, default): Current domain |
| 926 | + * - true: All domains |
| 927 | + * - string: Custom domain |
| 928 | + * - false: Disable this message all together. |
910 | 929 | * @return The HTML for the promo box. |
911 | 930 | */ |
912 | | - public function getPromoBox( $imgSize = 28 ) { |
| 931 | + public function getPromoBox( $imgSize = 28, $helpTranslateDomain = null ) { |
| 932 | + |
| 933 | + // Logo |
913 | 934 | if ( is_int( $imgSize ) && $imgSize > 0 ) { |
914 | 935 | $src = 'http://upload.wikimedia.org/wikipedia/commons/thumb/b/be' |
915 | 936 | . '/Wikimedia_Community_Logo-Toolserver.svg' |
— | — | @@ -924,27 +945,55 @@ |
925 | 946 | } else { |
926 | 947 | $img = ''; |
927 | 948 | } |
| 949 | + |
| 950 | + // Promo message |
928 | 951 | $promoMsgOpts = array( |
929 | 952 | 'domain' => 'tsintuition', |
930 | 953 | 'escape' => 'html', |
931 | 954 | 'raw-variables' => true, |
932 | 955 | 'variables' => array( |
933 | | - '<a href="http://translatewiki.net/">TranslateWiki</a>', |
| 956 | + '<a href="http://translatewiki.net/">translatewiki.net</a>', |
934 | 957 | '<a href="http://toolserver.org/~krinkle/TsIntuition/">Toolserver Intuition</a>' |
935 | 958 | ), |
936 | 959 | ); |
937 | 960 | $powered = $this->msg( 'bl-promo', $promoMsgOpts ); |
938 | 961 | $change = $this->msg( 'bl-changelanguage', 'tsintuition' ); |
939 | | - return "<div id=\"tsint-promobox\"><a href=\"{$this->getDashboardReturnToUrl()}\">$img</a>" |
940 | | - . "<p>$powered <a href=\"{$this->dashboardHome}\">$change</a></p></div>"; |
| 962 | + |
| 963 | + // Help translation |
| 964 | + if ( $helpTranslateDomain === true ) { |
| 965 | + $helpTranslateDomain = '0-all'; |
| 966 | + $twLinkText = $this->msg( 'help-translate-all', 'tsintuition' ); |
| 967 | + } elseif ( is_null( $helpTranslateDomain ) ) { |
| 968 | + $helpTranslateDomain = $this->getDomain(); |
| 969 | + $twLinkText = $this->msg( 'help-translate-tool', 'tsintuition' ); |
| 970 | + } else { |
| 971 | + $twLinkText = $this->msg( 'help-translate-tool', 'tsintuition' ); |
| 972 | + } |
| 973 | + $helpTranslateLink = ''; |
| 974 | + if ( is_string( $helpTranslateDomain ) ) { |
| 975 | + $helpTranslateDomain = strtolower( $helpTranslateDomain ); |
| 976 | + // https://translatewiki.net/w/i.php?language=nl&title=Special:Translate&group=tsint-0-all |
| 977 | + $twParams = array( |
| 978 | + 'title' => 'Special:Translate', |
| 979 | + 'language' => $this->getLang(), |
| 980 | + 'group' => "tsint-$helpTranslateDomain", |
| 981 | + ); |
| 982 | + $twParams = http_build_query( $twParams ); |
| 983 | + $helpTranslateLink = TsIntuitionUtil::tag( $twLinkText, 'a', array( 'href' => "https://translatewiki.net/w/i.php?$twParams", 'title' => $this->msg( 'help-translate-tooltip', 'tsintuition' ) ) ); |
| 984 | + } |
| 985 | + |
| 986 | + // Build output |
| 987 | + return |
| 988 | + "<div id=\"tsint-promobox\"><p><a href=\"{$this->getDashboardReturnToUrl()}\">$img</a> " |
| 989 | + . "$powered {$this->dashboardBacklink()} $helpTranslateLink</p></div>"; |
941 | 990 | } |
942 | 991 | |
943 | 992 | /** |
944 | 993 | * Show a typical "powered by .." footer line. |
945 | 994 | * Same as getPromoBox() but without the image. |
946 | 995 | */ |
947 | | - public function getFooterLine(){ |
948 | | - return $this->getPromoBox( 'no-image' ); |
| 996 | + public function getFooterLine( $helpTranslateDomain = null ){ |
| 997 | + return $this->getPromoBox( 'no-image', $helpTranslateDomain ); |
949 | 998 | } |
950 | 999 | |
951 | 1000 | |
— | — | @@ -1071,10 +1120,10 @@ |
1072 | 1121 | * |
1073 | 1122 | * @return true |
1074 | 1123 | */ |
1075 | | - private function initLangSelect() { |
| 1124 | + private function initLangSelect( $option ) { |
1076 | 1125 | $set = false; |
1077 | | - if ( $this->constructLang ) { |
1078 | | - $set = $this->setLang( $this->constructLang ); |
| 1126 | + if ( isset( $option ) && !empty( $option ) ) { |
| 1127 | + $set = $this->setLang( $option ); |
1079 | 1128 | } |
1080 | 1129 | if ( !$set && $this->getUseRequestParam() === true && isset( $_GET[ $this->paramNames['userlang'] ] ) ) { |
1081 | 1130 | $set = $this->setLang( $_GET[ $this->paramNames['userlang'] ] ); |
— | — | @@ -1082,6 +1131,9 @@ |
1083 | 1132 | if ( !$set && isset( $_COOKIE[ $this->cookieNames['userlang'] ] ) ) { |
1084 | 1133 | $set = $this->setLang( $_COOKIE[ $this->cookieNames['userlang'] ] ); |
1085 | 1134 | } |
| 1135 | + if ( !$set ) { |
| 1136 | + $set = $this->setLang( 'en' ); |
| 1137 | + } |
1086 | 1138 | return $set; |
1087 | 1139 | } |
1088 | 1140 | |
— | — | @@ -1137,10 +1189,10 @@ |
1138 | 1190 | $code = 'Unknown error: '; |
1139 | 1191 | } |
1140 | 1192 | |
1141 | | - if ( $error && $this->suppresserrors ) { |
| 1193 | + if ( $error && $this->suppressfatal ) { |
1142 | 1194 | return; |
1143 | 1195 | } |
1144 | | - if ( $notice && $this->suppressnotices ) { |
| 1196 | + if ( $notice && $this->suppressnotice ) { |
1145 | 1197 | return; |
1146 | 1198 | } |
1147 | 1199 | |
Index: trunk/tools/ToolserverI18N/public_html/sandbox.php |
— | — | @@ -1,19 +0,0 @@ |
2 | | -<?php |
3 | | -/* Load Toolserver Intuition */ |
4 | | -require_once( '/home/krinkle/TsIntuition/ToolStart.php' ); |
5 | | - |
6 | | - |
7 | | -// Output-header |
8 | | -echo '<h3 style="margin: 8px 0px 5px 0px; border-bottom: 1px solid #AAA;">Output</h3>'; |
9 | | - |
10 | | - |
11 | | -// Source |
12 | | -function view_source( $file ) { |
13 | | - echo '<h3 style="margin: 8px 0px 5px 0px; border-bottom: 1px solid #AAA;">Source</h3>' |
14 | | - . '<pre style="background: #f2f2f2; padding: 5px 8px; border: 1px solid #CCC;">' |
15 | | - . htmlspecialchars( file_get_contents( $file ) ) |
16 | | - . '</pre>'; |
17 | | -} |
18 | | - |
19 | | - |
20 | | -if(basename($_SERVER['SCRIPT_NAME'])=='sandbox.php') view_source( __FILE__ ); |
\ No newline at end of file |
Index: trunk/tools/ToolserverI18N/public_html/sandbox1.php |
— | — | @@ -1,15 +0,0 @@ |
2 | | -<?php |
3 | | -/* Config */ |
4 | | -require_once( 'sandbox.php' ); |
5 | | - |
6 | | - |
7 | | -/* Demonstration */ |
8 | | -// 1) Init $I18N |
9 | | -$I18N = new TsIntuition( 'general' /* name of textdomain here */ ); |
10 | | - |
11 | | -// 2) Get message |
12 | | -echo $I18N->msg( 'welcome' ); |
13 | | - |
14 | | - |
15 | | -/* View source */ |
16 | | -view_source( __FILE__ ); |
\ No newline at end of file |
Index: trunk/tools/ToolserverI18N/public_html/sandbox2.php |
— | — | @@ -1,24 +0,0 @@ |
2 | | -<?php |
3 | | -/* Config */ |
4 | | -require_once( 'sandbox.php' ); |
5 | | - |
6 | | - |
7 | | -/* Demonstration */ |
8 | | - |
9 | | -// 1) Init TsIntuition |
10 | | -$options = array( |
11 | | - 'domain' => 'tsintuition', |
12 | | - |
13 | | - // Show notices |
14 | | - 'suppressnotices' => false, |
15 | | -); |
16 | | -$I18N = new TsIntuition( $options ); |
17 | | - |
18 | | -// 2) Request an undefined message |
19 | | -// Because 'suppressnotices' is false, |
20 | | -// this will trigger a Notice: 'r4nd0mstr1n9' undefined |
21 | | -echo $I18N->msg( 'r4nd0mstr1n9' ); |
22 | | - |
23 | | - |
24 | | -/* View source */ |
25 | | -view_source( __FILE__ ); |
\ No newline at end of file |
Index: trunk/tools/ToolserverI18N/public_html/sandbox3.php |
— | — | @@ -1,24 +0,0 @@ |
2 | | -<?php |
3 | | -/* Config */ |
4 | | -require_once( 'sandbox.php' ); |
5 | | - |
6 | | - |
7 | | -/* Demonstration */ |
8 | | - |
9 | | -// 1) Init TsIntuition |
10 | | -$options = array( |
11 | | - 'domain' => 'tsintuition', |
12 | | - |
13 | | - // Hide any kind of warning sign, errors, fatals and never call die |
14 | | - 'suppresserrors' => true, |
15 | | -); |
16 | | -$I18N = new TsIntuition( $options ); |
17 | | - |
18 | | -// 2) Request an undefined message |
19 | | -// Because 'suppresserrors' is true, |
20 | | -// this will display "R4nd0mstr1n9" instead of [r4nd0mstr1n9] |
21 | | -echo $I18N->msg( 'r4nd0mstr1n9' ); |
22 | | - |
23 | | - |
24 | | -/* View source */ |
25 | | -view_source( __FILE__ ); |
Index: trunk/tools/ToolserverI18N/public_html/sandbox4.php |
— | — | @@ -1,14 +0,0 @@ |
2 | | -<?php |
3 | | -/* Config */ |
4 | | -require_once( 'sandbox.php' ); |
5 | | -$I18N = new TsIntuition( 'general' ); |
6 | | - |
7 | | - |
8 | | -/* Demonstration */ |
9 | | -echo $I18N->dashboardBacklink(); |
10 | | -echo $I18N->getPromoBox(); |
11 | | -echo $I18N->getFooterLine(); |
12 | | - |
13 | | - |
14 | | -/* View source */ |
15 | | -view_source( __FILE__ ); |
Index: trunk/tools/ToolserverI18N/public_html/demo/demo5.php |
— | — | @@ -0,0 +1,16 @@ |
| 2 | +<?php |
| 3 | +/* Config */ |
| 4 | +require_once( 'demoBase.php' ); |
| 5 | +$I18N = new TsIntuition( 'general' ); |
| 6 | + |
| 7 | + |
| 8 | +/* Demonstration */ |
| 9 | +echo $I18N->dashboardBacklink(); |
| 10 | +echo $I18N->getPromoBox(); |
| 11 | +echo $I18N->getFooterLine(); |
| 12 | +echo $I18N->getFooterLine( false ); |
| 13 | +echo $I18N->getFooterLine( true ); |
| 14 | + |
| 15 | +/* View source */ |
| 16 | +view_source( __FILE__ ); |
| 17 | +close_demo(); |
Property changes on: trunk/tools/ToolserverI18N/public_html/demo/demo5.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 18 | + native |
Index: trunk/tools/ToolserverI18N/public_html/demo/demoBase.php |
— | — | @@ -0,0 +1,90 @@ |
| 2 | +<?php |
| 3 | +error_reporting(E_ALL); ini_set('display_errors', 1); |
| 4 | + |
| 5 | +/* Load Toolserver Intuition from the main directory */ |
| 6 | +require_once( dirname(dirname( __DIR__ )) . '/ToolStart.php' ); |
| 7 | + |
| 8 | +// Known demos |
| 9 | +$demoRegistry = array( |
| 10 | + 'demo1' => 'Basic setup to load a message', |
| 11 | + 'demo2' => 'Undefined message (default)', |
| 12 | + 'demo3' => 'Undefined message (notice)', |
| 13 | + 'demo4' => 'Undefined message (no brackets)', |
| 14 | + 'demo5' => 'Dashboard backlink and footer line', |
| 15 | +); |
| 16 | + |
| 17 | +$thisFile = basename( $_SERVER['SCRIPT_NAME'], '.php' ); |
| 18 | +$thisDescr = htmlspecialchars( @$demoRegistry[$thisFile] ); |
| 19 | + |
| 20 | +// HTML fragments |
| 21 | +$startHTML = <<<HTML |
| 22 | +<!DOCTYPE html> |
| 23 | +<html dir="ltr" lang="en-US"> |
| 24 | +<head> |
| 25 | + <meta charset="utf-8"> |
| 26 | + <title>Toolserver Intuition | Demonstration sandboxes | $thisFile: $thisDescr</title> |
| 27 | + <style> |
| 28 | + /* Demo framework */ |
| 29 | + body { |
| 30 | + font-family: sans-serif; |
| 31 | + } |
| 32 | + img { |
| 33 | + vertical-align: middle; |
| 34 | + } |
| 35 | + h3 { |
| 36 | + clear: both; |
| 37 | + margin: 10px 0px; |
| 38 | + border-bottom: 1px solid #AAA; |
| 39 | + } |
| 40 | + pre { |
| 41 | + background: #F9F9F9; |
| 42 | + padding: 5px 8px; |
| 43 | + border: 1px solid #CCC; |
| 44 | + } |
| 45 | + ul { |
| 46 | + color: #777777; |
| 47 | + list-style: none; |
| 48 | + } |
| 49 | + ul li { |
| 50 | + background: #F9F9F9; |
| 51 | + display: inline; |
| 52 | + float: left; |
| 53 | + padding: 3px 2px; |
| 54 | + margin: 0px 2px; |
| 55 | + } |
| 56 | + /* Example */ |
| 57 | + #tsint-promobox { background: #F9F9F9; padding: 5px 8px; margin: 10px; } |
| 58 | + </style> |
| 59 | +</head> |
| 60 | +<body> |
| 61 | +HTML; |
| 62 | +$outputHead = '<h3>Output</h3>'; |
| 63 | + |
| 64 | + |
| 65 | +// Start output |
| 66 | +header( 'Content-Type: text/html; charset=utf-8' ); |
| 67 | +echo $startHTML . '<ul>'; |
| 68 | +foreach ( $demoRegistry as $demoFilename => $descr ) { |
| 69 | + $descr = htmlspecialchars( $descr ); |
| 70 | + echo "<li><a href=\"$demoFilename.php\" title=\"$descr\">$demoFilename</a><br /><small>$descr</small></a></li>"; |
| 71 | +} |
| 72 | +echo "</ul>$outputHead"; |
| 73 | + |
| 74 | + |
| 75 | +// Output source-heading and source code |
| 76 | +function view_source( $file ) { |
| 77 | + echo '<h3>Source</h3>' |
| 78 | + . '<pre>' |
| 79 | + . show_source( $file, true ) |
| 80 | + . '</pre>'; |
| 81 | +} |
| 82 | + |
| 83 | +// End of track |
| 84 | +function close_demo(){ |
| 85 | + echo '</body></html>'; |
| 86 | +} |
| 87 | + |
| 88 | +// Make this file viewable as well |
| 89 | +if( $thisFile == 'demoBase' ){ |
| 90 | + view_source( __FILE__ ); |
| 91 | +} |
\ No newline at end of file |
Property changes on: trunk/tools/ToolserverI18N/public_html/demo/demoBase.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 92 | + native |
Index: trunk/tools/ToolserverI18N/public_html/demo/demo1.php |
— | — | @@ -0,0 +1,15 @@ |
| 2 | +<?php |
| 3 | +/* Config */ |
| 4 | +require_once( 'demoBase.php' ); |
| 5 | + |
| 6 | +/* Demonstration */ |
| 7 | +// 1) Init $I18N |
| 8 | +$I18N = new TsIntuition( 'general' /* name of textdomain here */ ); |
| 9 | + |
| 10 | +// 2) Get message |
| 11 | +echo $I18N->msg( 'welcome' ); |
| 12 | + |
| 13 | + |
| 14 | +/* View source */ |
| 15 | +view_source( __FILE__ ); |
| 16 | +close_demo(); |
\ No newline at end of file |
Property changes on: trunk/tools/ToolserverI18N/public_html/demo/demo1.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 17 | + native |
Index: trunk/tools/ToolserverI18N/public_html/demo/demo2.php |
— | — | @@ -0,0 +1,22 @@ |
| 2 | +<?php |
| 3 | +/* Config */ |
| 4 | +require_once( 'demoBase.php' ); |
| 5 | + |
| 6 | + |
| 7 | +/* Demonstration */ |
| 8 | + |
| 9 | +// 1) Init TsIntuition |
| 10 | +$options = array( |
| 11 | + 'domain' => 'tsintuition', |
| 12 | +); |
| 13 | +$I18N = new TsIntuition( $options ); |
| 14 | + |
| 15 | +// 2) Request an undefined message |
| 16 | +// Because 'suppressnotices' is true (default), |
| 17 | +// this won't trigger a Notice, and show a bracket msg: '[r4nd0mstr1n9]' |
| 18 | +echo $I18N->msg( 'r4nd0mstr1n9' ); |
| 19 | + |
| 20 | + |
| 21 | +/* View source */ |
| 22 | +view_source( __FILE__ ); |
| 23 | +close_demo(); |
\ No newline at end of file |
Property changes on: trunk/tools/ToolserverI18N/public_html/demo/demo2.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 24 | + native |
Index: trunk/tools/ToolserverI18N/public_html/demo/demo3.php |
— | — | @@ -0,0 +1,25 @@ |
| 2 | +<?php |
| 3 | +/* Config */ |
| 4 | +require_once( 'demoBase.php' ); |
| 5 | + |
| 6 | + |
| 7 | +/* Demonstration */ |
| 8 | + |
| 9 | +// 1) Init TsIntuition |
| 10 | +$options = array( |
| 11 | + 'domain' => 'tsintuition', |
| 12 | + |
| 13 | + // Show notices |
| 14 | + 'suppressnotice' => false, |
| 15 | +); |
| 16 | +$I18N = new TsIntuition( $options ); |
| 17 | + |
| 18 | +// 2) Request an undefined message |
| 19 | +// Because 'suppressnotices' is false, |
| 20 | +// this will trigger a Notice: 'r4nd0mstr1n9' undefined |
| 21 | +echo $I18N->msg( 'r4nd0mstr1n9' ); |
| 22 | + |
| 23 | + |
| 24 | +/* View source */ |
| 25 | +view_source( __FILE__ ); |
| 26 | +close_demo(); |
\ No newline at end of file |
Property changes on: trunk/tools/ToolserverI18N/public_html/demo/demo3.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 27 | + native |
Index: trunk/tools/ToolserverI18N/public_html/demo/demo4.php |
— | — | @@ -0,0 +1,25 @@ |
| 2 | +<?php |
| 3 | +/* Config */ |
| 4 | +require_once( 'demoBase.php' ); |
| 5 | + |
| 6 | + |
| 7 | +/* Demonstration */ |
| 8 | + |
| 9 | +// 1) Init TsIntuition |
| 10 | +$options = array( |
| 11 | + 'domain' => 'tsintuition', |
| 12 | + |
| 13 | + // Hide any sign of an undefined message to the end-user |
| 14 | + 'suppressbrackets' => true, |
| 15 | +); |
| 16 | +$I18N = new TsIntuition( $options ); |
| 17 | + |
| 18 | +// 2) Request an undefined message |
| 19 | +// Because 'suppressbrackets' is true, |
| 20 | +// this will display "R4nd0mstr1n9" instead of [r4nd0mstr1n9] |
| 21 | +echo $I18N->msg( 'r4nd0mstr1n9' ); |
| 22 | + |
| 23 | + |
| 24 | +/* View source */ |
| 25 | +view_source( __FILE__ ); |
| 26 | +close_demo(); |
Property changes on: trunk/tools/ToolserverI18N/public_html/demo/demo4.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 27 | + native |
Index: trunk/tools/ToolserverI18N/public_html/index.php |
— | — | @@ -245,8 +245,13 @@ |
246 | 246 | // About tab |
247 | 247 | $about = '<div id="tab-about">' |
248 | 248 | . 'Technical documentation: <a href="https://wiki.toolserver.org/view/Toolserver_Intuition">https://wiki.toolserver.org/view/Toolserver_Intuition</a>' |
249 | | - . '<div class="tab-paragraph-head">' . _( 'usage' ) . '</div><ul>'; |
250 | | - |
| 249 | + . '<div class="tab-paragraph-head">' . _( 'usage' ) . '</div>'; |
| 250 | + |
| 251 | +$about .= '<div class="aligncenter"><a href="http://translatewiki.net/wiki/Translating:Toolserver">' |
| 252 | + . '<img src="http://translatewiki.net/w/i.php?title=Special:TranslationStats&' |
| 253 | + . 'graphit=1&width=600&height=400&group=tsint-0-all" width="600" height="400" alt="" />' |
| 254 | + . '</a></div>'; |
| 255 | +$about .= '<ul>'; |
251 | 256 | foreach ( $I18N->getAllRegisteredDomains() as $domainKey => $domainFile ) { |
252 | 257 | $domainInfo = $I18N->getDomainInfo( $domainKey ); |
253 | 258 | $title = $I18N->msg( 'title', $domainKey, /* fallback = */ $domainKey ); |