r100023 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r100022‎ | r100023 | r100024 >
Date:11:35, 17 October 2011
Author:amire80
Status:ok (Comments)
Tags:
Comment:
Bug 29357: CategoryTree should have built-in localizable support for pretty Categorytree-member-num.

Added the messages:
* categorytree-num-categories
* categorytree-num-pages
* categorytree-num-files
* categorytree-num-empty

Added documentation for all of them and for categorytree-member-num and also localized them for Hebrew.

Rewrote the part that uses categorytree-member-num to automatically create a comma-separated list of relevant member counts. categorytree-member-num will still be used the same way if it is customized on wiki.
Modified paths:
  • /trunk/extensions/CategoryTree/CategoryTree.i18n.php (modified) (history)
  • /trunk/extensions/CategoryTree/CategoryTreeFunctions.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CategoryTree/CategoryTree.i18n.php
@@ -38,7 +38,11 @@
3939 'categorytree-page-bullet' => ' ', # do not translate or duplicate this message to other languages
4040
4141 'categorytree-member-counts' => 'contains {{PLURAL:$1|1 subcategory|$1 subcategories}}, {{PLURAL:$2|1 page|$2 pages}}, and {{PLURAL:$3|1 file|$3 files}}', # $1=subcategories, $2=subpages, $3=files, $4=total, $5=shown-in-tree
42 - 'categorytree-member-num' => '($5)', # do not translate or duplicate this message to other languages
 42+ 'categorytree-member-num' => '($5)', # do not translate or duplicate this message to other languages
 43+ 'categorytree-num-categories' => '$1 C',
 44+ 'categorytree-num-pages' => '$1 P',
 45+ 'categorytree-num-files' => '$1 F',
 46+ 'categorytree-num-empty' => 'empty',
4347
4448 'categorytree-load' => 'load',
4549 'categorytree-loading' => 'loading…',
@@ -63,6 +67,7 @@
6468 * @author Yekrats
6569 * @author Александр Сигачёв
6670 * @author פוילישער
 71+ * @author Amire80
6772 */
6873 $messages['qqq'] = array(
6974 'categorytree' => 'Title of [[Special:CategoryTree]]',
@@ -91,6 +96,11 @@
9297 * $4 = total number of members,
9398 * $5 = members to be shown in the tree, depending on mode.
9499 Use with <nowiki>{{PLURAL}}</nowiki>',
 100+ 'categorytree-member-num' => 'Do not translate or duplicate this message to other languages. It can be customized locally on a wiki.',
 101+ 'categorytree-num-categories' => 'Number of sub-categories in a category. The word "categories" should be abbreviated. Appears in brackets after a name of an empty category. This message supports PLURAL.',
 102+ 'categorytree-num-pages' => 'Number of pages in a category. The word "pages" should be abbreviated. Appears in brackets after a name of an empty category. This message supports PLURAL.',
 103+ 'categorytree-num-files' => 'Number of sub-categories in a category. The word "files" should be abbreviated. Appears in brackets after a name of an empty category. This message supports PLURAL.',
 104+ 'categorytree-num-empty' => 'The word "empty", as in "empty category". Appears in brackets after a name of an empty category.',
95105 'categorytree-load' => '{{Identical|Load}}
96106
97107 Tooltip for the "expend" button, if the content was not yet loaded',
@@ -1654,6 +1664,10 @@
16551665 'categorytree-collapse' => 'כיווץ',
16561666 'categorytree-expand' => 'הרחבה',
16571667 'categorytree-member-counts' => 'כוללת {{PLURAL:$1|קטגוריית משנה אחת|$1 קטגוריות משנה}}, {{PLURAL:$2|דף אחד|$2 דפים}}, ו{{PLURAL:$3|קובץ אחד|־$3 קבצים}}',
 1668+ 'categorytree-num-categories' => '{{PLURAL:$1|קט אחת|$1 קט}}',
 1669+ 'categorytree-num-pages' => '{{PLURAL:$1|דף אחד|$1 דפים}}',
 1670+ 'categorytree-num-files' => '{{PLURAL:$1|קובץ אחד|$1 קב}}',
 1671+ 'categorytree-num-empty' => 'ריקה',
16581672 'categorytree-load' => 'טעינה',
16591673 'categorytree-loading' => 'בטעינה',
16601674 'categorytree-nothing-found' => 'לא נמצאו תוצאות',
Index: trunk/extensions/CategoryTree/CategoryTreeFunctions.php
@@ -650,12 +650,31 @@
651651 if ( $count !== false && $this->getOption( 'showcount' ) ) {
652652 $pages = $pageCount - $subcatCount - $fileCount;
653653
 654+ global $wgContLang, $wgLang;
654655 $attr = array(
655 - 'title' => wfMsgExt( 'categorytree-member-counts', 'parsemag', $subcatCount, $pages , $fileCount, $pageCount, $count )
 656+ 'title' => wfMsgExt( 'categorytree-member-counts', 'parsemag', $subcatCount, $pages , $fileCount, $pageCount, $count ),
 657+ 'dir' => $wgLang->getDir() # numbers and commas get messed up in a mixed dir env
656658 );
657659
658 - global $wgContLang, $wgLang;
659660 $s .= $wgContLang->getDirMark() . ' ';
 661+
 662+ # Create a list of category members with only non-zero member counts
 663+ $memberNums = array();
 664+ if ( $subcatCount ) {
 665+ $memberNums[] = wfMessage( 'categorytree-num-categories', $wgLang->formatNum( $subcatCount ) )->text();
 666+ }
 667+ if ( $pageCount ) {
 668+ $memberNums[] = wfMessage( 'categorytree-num-pages', $wgLang->formatNum( $pageCount ) )->text();
 669+ }
 670+ if ( $fileCount ) {
 671+ $memberNums[] = wfMessage( 'categorytree-num-files', $wgLang->formatNum( $fileCount ) )->text();
 672+ }
 673+ $memberNumsShort = $memberNums
 674+ ? $wgLang->commaList( $memberNums )
 675+ : wfMessage( 'categorytree-num-empty' )->text();
 676+
 677+ # Only $5 is actually used in the default message.
 678+ # Other arguments can be used in a customized message.
660679 $s .= Xml::tags( 'span', $attr,
661680 wfMsgExt( 'categorytree-member-num',
662681 array( 'parsemag', 'escapenoentities' ),
@@ -663,7 +682,7 @@
664683 $pages,
665684 $fileCount,
666685 $pageCount,
667 - $wgLang->formatNum( $count ) ) );
 686+ $memberNumsShort ) );
668687 }
669688
670689 $s .= Xml::closeElement( 'div' );

Follow-up revisions

RevisionCommit summaryAuthorDate
r102998MFT r98140 r100023 r102786 r102802 r102893nikerabbit18:20, 14 November 2011
r103260(follow-up r100023; bug 32438) $pagesCount is total number of members a categ...bawolff23:35, 15 November 2011

Comments

#Comment by Nikerabbit (talk | contribs)   13:00, 17 October 2011

Looks good. It is possible to shorten the code a bit more by doing:

-wfMessage( 'categorytree-num-pages', $wgLang->formatNum( $pageCount ) )->text();
+wfMessage( 'categorytree-num-pages' )->numParams( $pageCount )->text();

Is there risk breaking customisations of this message that expect $5 to be a number?

#Comment by Amire80 (talk | contribs)   13:42, 31 October 2011

FWIW, no Wikimedia projects use $5.

It's possible to restore $wgLang->formatNum( $count ) as $5 and add $memberNumsShort as $6 and then change 'categorytree-member-num' to ($6), although i doubt it's worth the trouble.

(Using the parentheses message on 'categorytree-member-num' might be a good idea, though.)

#Comment by Umherirrender (talk | contribs)   11:30, 16 November 2011

Your changes at 'categorytree-member-num' in language qqq was removed with the next regular export (r100072), please change the documentation on translatewiki instead. Thanks.

Status & tagging log