r54342 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r54341‎ | r54342 | r54343 >
Date:04:09, 4 August 2009
Author:laner
Status:resolved (Comments)
Tags:
Comment:
Adding internationalization for error messages.
Modified paths:
  • /trunk/extensions/ExternalData/ED_Utils.php (modified) (history)
  • /trunk/extensions/ExternalData/ExternalData.i18n.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ExternalData/ExternalData.i18n.php
@@ -14,6 +14,15 @@
1515 // user messages
1616 'getdata' => 'Get data',
1717 'externaldata-desc' => 'Allows for retrieving data in CSV, JSON and XML formats from both external URLs and local wiki pages',
 18+ 'externaldata-ldap-unable-to-connect' => 'Unable to connect to $1\n',
 19+ 'externaldata-json-decode-not-supported' => 'Error: json_decode() is not supported in this version of PHP',
 20+ 'externaldata-xml-error' => 'XML error: $1 at line $2',
 21+ 'externaldata-db-incomplete-information' => '<p>ERROR: Incomplete information for this server ID.</p>\n',
 22+ 'externaldata-db-could-not-get-url' => 'Could not get URL after $1 tries.\n\n',
 23+ 'externaldata-db-unknown-type' => '<p>ERROR: Unknown database type.</p>\n',
 24+ 'externaldata-db-could-not-connect' => '<p>ERROR: Could not connect to database.</p>\n',
 25+ 'externaldata-db-no-return-values' => '<p>ERROR: No return values specified.</p>\n',
 26+ 'externaldata-db-invalid-query' => 'Invalid query.',
1827 );
1928
2029 /** Message documentation (Message documentation)
Index: trunk/extensions/ExternalData/ED_Utils.php
@@ -93,7 +93,7 @@
9494 # should check the result of the bind here
9595 return $ds;
9696 } else {
97 - echo "Unable to connect to $server\n";
 97+ echo ( wfMsg( "externaldata-ldap-unable-to-connect", $server ) );
9898 }
9999 }
100100
@@ -117,7 +117,7 @@
118118 (! array_key_exists($server_id, $edgDBName)) ||
119119 (! array_key_exists($server_id, $edgDBUser)) ||
120120 (! array_key_exists($server_id, $edgDBPass))) {
121 - echo "<p>ERROR: Incomplete information for this server ID.</p>\n";
 121+ echo ( wfMsg( "externaldata-db-incomplete-information" ) );
122122 return;
123123 }
124124
@@ -135,16 +135,16 @@
136136 } elseif ($db_type == "mssql") {
137137 $db = new DatabaseMssql($db_server, $db_username, $db_password, $db_name);
138138 } else {
139 - echo "<p>ERROR: Unknown database type.</p>\n";
 139+ echo ( wfMsg( "externaldata-db-unknown-type" ) );
140140 return;
141141 }
142142 if (! $db->isOpen()) {
143 - echo "<p>ERROR: Could not connect to database.</p>\n";
 143+ echo ( wfMsg( "externaldata-db-could-not-connect" ) );
144144 return;
145145 }
146146
147147 if (count($columns) == 0) {
148 - echo "<p>ERROR: No return values specified.</p>\n";
 148+ echo ( wfMsg( "externaldata-db-no-return-values" ) );
149149 return;
150150 }
151151
@@ -168,7 +168,7 @@
169169
170170 $result = $db->query($sql);
171171 if (!$result) {
172 - echo "Invalid query.";
 172+ echo ( wfMsg( "externaldata-db-invalid-query" ) );
173173 return false;
174174 } else {
175175 $rows = Array();
@@ -187,9 +187,9 @@
188188 xml_set_element_handler( $xml_parser, array( 'EDUtils', 'startElement' ), array( 'EDUtils', 'endElement' ) );
189189 xml_set_character_data_handler( $xml_parser, array( 'EDUtils', 'getContent' ) );
190190 if (!xml_parse($xml_parser, $xml, true)) {
191 - echo(sprintf("XML error: %s at line %d",
 191+ echo ( wfMsg( 'externaldata-xml-error',
192192 xml_error_string(xml_get_error_code($xml_parser)),
193 - xml_get_current_line_number($xml_parser)));
 193+ xml_get_current_line_number($xml_parser)) );
194194 }
195195 xml_parser_free( $xml_parser );
196196 return $edgXMLValues;
@@ -263,7 +263,7 @@
264264 static function getJSONData( $json ) {
265265 // escape if json_decode() isn't supported
266266 if ( ! function_exists( 'json_decode' ) ) {
267 - echo( "Error: json_decode() is not supported in this version of PHP" );
 267+ echo ( wfMsg( "externaldata-json-decode-not-supported" ) );
268268 return array();
269269 }
270270 $json_tree = json_decode($json, true);
@@ -300,7 +300,7 @@
301301 if ( $page === false ) {
302302 sleep( 1 );
303303 if( $try_count >= self::$http_number_of_tries ){
304 - echo "could not get URL after " . self::$http_number_of_tries . " tries.\n\n";
 304+ echo ( wfMsg( "externaldata-db-could-not-get-url", self::$http_number_of_tries ) );
305305 return '';
306306 }
307307 $try_count++;

Comments

#Comment by Nikerabbit (talk | contribs)   07:48, 4 August 2009

Few notes:

  • The messages are not escaped. New unescaped messages are discouraged in the core at least.
  • You are adding literal \n in the messages because it is in single quotes. Add them in the code if needed. And preferably take the <p> tags out of the messages too.
  • externaldata-db-could-not-get-url should support plurals
  • It would be nice to have some documentation for the variables
#Comment by Siebrand (talk | contribs)   00:21, 7 August 2009

This user hadn't been linked to a wiki account up to now. Should be fixed and he should at least get a notification from this comment. FIXME.

#Comment by Ryan lane (talk | contribs)   20:34, 16 August 2009

Sorry, still getting used to the i18n system.

When you say it would be nice to have documentation for the variables, do you mean in the extension code, or the i18n code?

#Comment by Ryan lane (talk | contribs)   21:04, 19 August 2009

This should be fixed in 55349

#Comment by Siebrand (talk | contribs)   21:35, 19 August 2009

More in r55350 (using wfMsgExt). Fixed.

Status & tagging log