Index: trunk/extensions/Translate/groups/MediaWikiExtensions.php |
— | — | @@ -0,0 +1,113 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +class PremadeMediawikiExtensionGroups { |
| 5 | + protected $groups; |
| 6 | + |
| 7 | + public function init() { |
| 8 | + if ( $this->groups !== null ) return; |
| 9 | + |
| 10 | + $dir = dirname( __FILE__ ); |
| 11 | + $defines = file_get_contents( $dir . '/defines.txt' ); |
| 12 | + $sections = preg_split( "/\n\n/", $defines, -1, PREG_SPLIT_NO_EMPTY ); |
| 13 | + |
| 14 | + $groups = $fixedGroups = array(); |
| 15 | + |
| 16 | + foreach ( $sections as $section ) { |
| 17 | + $lines = preg_split( "/\n/", $section ); |
| 18 | + $newgroup = array(); |
| 19 | + |
| 20 | + foreach ( $lines as $line ) { |
| 21 | + if ( strpos( $line, '=' ) === false ) { |
| 22 | + if ( empty($newgroup['name']) ) { |
| 23 | + $newgroup['name'] = $line; |
| 24 | + } else { |
| 25 | + throw new MWException( "Trying to define name twice: " . $line ); |
| 26 | + } |
| 27 | + } else { |
| 28 | + list( $key, $value ) = array_map( 'trim', explode( '=', $line, 2 ) ); |
| 29 | + switch ($key) { |
| 30 | + case 'file': |
| 31 | + case 'var': |
| 32 | + case 'id': |
| 33 | + $newgroup[$key] = $value; |
| 34 | + break; |
| 35 | + case 'optional': |
| 36 | + case 'ignored': |
| 37 | + $values = array_map( 'trim', explode( ',', $value ) ); |
| 38 | + if ( !isset($newgroup[$key]) ) { |
| 39 | + $newgroup[$key] = array(); |
| 40 | + } |
| 41 | + $newgroup[$key] = array_merge( $newgroup[$key], $values ); |
| 42 | + break; |
| 43 | + default: |
| 44 | + throw new MWException( "Unknown key:" . $key ); |
| 45 | + } |
| 46 | + } |
| 47 | + } |
| 48 | + |
| 49 | + if ( count($newgroup) ) { |
| 50 | + if ( empty($newgroup['name']) ) { |
| 51 | + throw new MWException( "Name missing\n" . print_r($newgroup, true) ); |
| 52 | + } |
| 53 | + $groups[] = $newgroup; |
| 54 | + } |
| 55 | + } |
| 56 | + |
| 57 | + |
| 58 | + foreach ( $groups as $g ) { |
| 59 | + if ( !is_array($g) ) { |
| 60 | + $g = array($g); |
| 61 | + } |
| 62 | + |
| 63 | + $name = $g['name']; |
| 64 | + |
| 65 | + if ( isset($g['id']) ) { |
| 66 | + $id = $g['id']; |
| 67 | + } else { |
| 68 | + $id = 'ext-' . preg_replace( '/\s+/', '', strtolower( $name ) ); |
| 69 | + } |
| 70 | + |
| 71 | + if ( isset($g['file']) ) { |
| 72 | + $file = $g['file']; |
| 73 | + } else { |
| 74 | + $file = preg_replace( '/\s+/', '', "$name/$name.i18n.php" ); |
| 75 | + } |
| 76 | + |
| 77 | + $newgroup = array( |
| 78 | + 'name' => $name, |
| 79 | + 'file' => $file, |
| 80 | + ); |
| 81 | + |
| 82 | + $copyvars = array( 'ignored', 'optional', 'var' ); |
| 83 | + foreach ( $copyvars as $var ) { |
| 84 | + if ( isset($g[$var]) ) { |
| 85 | + $newgroup[$var] = $g[$var]; |
| 86 | + } |
| 87 | + } |
| 88 | + |
| 89 | + $fixedGroups[$id] = $newgroup; |
| 90 | + } |
| 91 | + |
| 92 | + $this->groups = $fixedGroups; |
| 93 | + } |
| 94 | + |
| 95 | + public function addAll() { |
| 96 | + global $wgTranslateAC, $wgTranslateEC; |
| 97 | + $this->init(); |
| 98 | + foreach ( $this->groups as $id => $g ) { |
| 99 | + $wgTranslateAC[$id] = array( $this, 'factory' ); |
| 100 | + $wgTranslateEC[] = $id; |
| 101 | + } |
| 102 | + } |
| 103 | + |
| 104 | + public function factory( $id ) { |
| 105 | + $info = $this->groups[$id]; |
| 106 | + $group = ExtensionMessageGroup::factory( $info['name'] . ' (mw ext)', $id ); |
| 107 | + $group->setMessageFile( $info['file'] ); |
| 108 | + if ( !empty($info['var']) ) $group->setVariableName( $info['var'] ); |
| 109 | + if ( !empty($info['optional']) ) $group->setOptional( $info['optional'] ); |
| 110 | + if ( !empty($info['ignored']) ) $group->setIgnored( $info['ignored'] ); |
| 111 | + return $group; |
| 112 | + } |
| 113 | + |
| 114 | +} |
\ No newline at end of file |
Property changes on: trunk/extensions/Translate/groups/MediaWikiExtensions.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 115 | + native |
Index: trunk/extensions/Translate/groups/defines.txt |
— | — | @@ -0,0 +1,601 @@ |
| 2 | +Absentee Landlord |
| 3 | + |
| 4 | +Advanced Random |
| 5 | +file = AdvancedRandom/SpecialAdvancedRandom.i18n.php |
| 6 | + |
| 7 | +Ajax Query Pages |
| 8 | + |
| 9 | +Ajax Show Editors |
| 10 | + |
| 11 | +Anti Bot |
| 12 | + |
| 13 | +Anti Spoof |
| 14 | + |
| 15 | +APC |
| 16 | +file = APC/ViewAPC.i18n.php |
| 17 | + |
| 18 | +Asksql |
| 19 | + |
| 20 | +Assert Edit |
| 21 | + |
| 22 | +Author Protect |
| 23 | + |
| 24 | +Babel |
| 25 | +ignored = babel-box-cellspacing, babel-category-prefix, babel-category-suffix |
| 26 | +ignored = babel-portal-prefix, babel-portal-suffix, babel-template-prefix |
| 27 | +ignored = babel-template-suffix |
| 28 | +optional = babel-0-female, babel-1-female, babel-2-female, babel-3-female |
| 29 | +optional = babel-4-female, babel-5-female, babel-N-female, babel-0-n-female |
| 30 | +optional = babel-1-n-female, babel-2-n-female, babel-3-n-female |
| 31 | +optional = babel-4-n-female, babel-5-n-female, babel-N-n-female, babel-0-male |
| 32 | +optional = babel-1-male, babel-2-male, babel-3-male, babel-4-male, babel-5-male |
| 33 | +optional = babel-N-male, babel-0-n-male, babel-1-n-male, babel-2-n-male |
| 34 | +optional = babel-3-n-male, babel-4-n-male, babel-5-n-male, babel-N-n-male |
| 35 | + |
| 36 | +Back and Forth |
| 37 | +file = BackAndForth/BackAndForth.i18n.php |
| 38 | + |
| 39 | +Bad Image |
| 40 | + |
| 41 | +Blahtex |
| 42 | + |
| 43 | +Block Titles |
| 44 | + |
| 45 | +Board Vote |
| 46 | +ignored = boardvote_footer |
| 47 | + |
| 48 | +Book Information |
| 49 | + |
| 50 | +Breadcrumbs navigation |
| 51 | +file = BreadCrumbs/BreadCrumbs.i18n.php |
| 52 | +id = ext-breadcrumbs |
| 53 | + |
| 54 | +Call |
| 55 | + |
| 56 | +Category Intersection |
| 57 | + |
| 58 | +Category Stepper |
| 59 | +ignored = categorystepper |
| 60 | + |
| 61 | +Category Tree |
| 62 | + |
| 63 | +Category Feed |
| 64 | +file = catfeed/catfeed.i18n.php |
| 65 | +id = ext-catfeed |
| 66 | + |
| 67 | +Central Auth |
| 68 | + |
| 69 | +Central Notice |
| 70 | + |
| 71 | +Change Author |
| 72 | +optional = changeauthor-rev |
| 73 | +ignored = changeauthor-short,changeauthor-logpagetext |
| 74 | + |
| 75 | +CharInsert |
| 76 | + |
| 77 | +Check User |
| 78 | + |
| 79 | +Chemistry |
| 80 | +file = Chemistry/ChemFunctions.i18n.php |
| 81 | +optional = chemFunctions_SearchExplanation |
| 82 | +ignored = chemFunctions_EINECS, chemFunctions_CHEBI, chemFunctions_PubChem, |
| 83 | +ignored = chemFunctions_SMILES, chemFunctions_InChI, chemFunctions_RTECS, |
| 84 | +ignored = chemFunctions_KEGG, chemFunctions_DrugBank |
| 85 | + |
| 86 | +Cite |
| 87 | +optional = cite_reference_link_key_with_num, cite_reference_link_prefix |
| 88 | +optional = cite_reference_link_suffix, cite_references_link_prefix |
| 89 | +optional = cite_references_link_suffix, cite_reference_link |
| 90 | +optional = cite_references_link_one, cite_references_link_many |
| 91 | +optional = cite_references_link_many_format |
| 92 | +optional = cite_references_link_many_format_backlink_labels |
| 93 | +optional = cite_references_link_many_sep, cite_references_link_many_and |
| 94 | +ignored = cite_references_prefix, cite_references_suffix |
| 95 | + |
| 96 | +Cite (special page) |
| 97 | +id = ext-citespecial |
| 98 | +file = Cite/SpecialCite.i18n.php |
| 99 | +ignored = cite_text |
| 100 | + |
| 101 | +Clean Changes |
| 102 | + |
| 103 | +Collection |
| 104 | + |
| 105 | +Comment Pages |
| 106 | +ignored = commenttab-editintro, commenttab-preload |
| 107 | + |
| 108 | +Comment Spammer |
| 109 | + |
| 110 | +Configure |
| 111 | +optional = configure-section-html, configure-section-ajax |
| 112 | +optional = configure-section-djvu, configure-section-imagemagick |
| 113 | +optional = configure-section-interwiki, configure-section-memcached |
| 114 | +optional = configure-section-squid, configure-section-svg, configure-section-tex |
| 115 | +optional = configure-section-tidy |
| 116 | + |
| 117 | +Confirm Account |
| 118 | +optional = requestaccount-info, requestaccount-footer |
| 119 | + |
| 120 | +Confirm Edit |
| 121 | + |
| 122 | +ConfirmEdit Fancy Captcha |
| 123 | +file = ConfirmEdit/FancyCaptcha.i18n.php |
| 124 | + |
| 125 | +Contact Page |
| 126 | + |
| 127 | +Contribution Scores |
| 128 | + |
| 129 | +Contributions Edit Count |
| 130 | +file = Contributionseditcount/Contributionseditcount.i18n.php |
| 131 | + |
| 132 | +Contributors |
| 133 | + |
| 134 | +Contributors Add-on |
| 135 | +id = ext-contributorsaddon |
| 136 | +file = ContributorsAddon/ContributorsAddon.i18n.php |
| 137 | + |
| 138 | +Count Edits |
| 139 | + |
| 140 | +Create Box |
| 141 | + |
| 142 | +Cross Namespace Links |
| 143 | +file = CrossNamespaceLinks/SpecialCrossNamespaceLinks.i18n.php |
| 144 | + |
| 145 | +Crosswiki Block |
| 146 | +file = Crosswiki/Block/CrosswikiBlock.i18n.php |
| 147 | + |
| 148 | +Crowd Authentication |
| 149 | + |
| 150 | +Data Transfer |
| 151 | +file = DataTransfer/languages/DT_Messages.php |
| 152 | + |
| 153 | +Deleted Contributions |
| 154 | +id = ext-deletedcontribs |
| 155 | + |
| 156 | +Did You Mean |
| 157 | + |
| 158 | +Dismissable SiteNotice |
| 159 | +ignored = sitenotice_id |
| 160 | + |
| 161 | +Double Wiki |
| 162 | + |
| 163 | +DPL Forum |
| 164 | +file = DPLforum/DPLforum.i18n.php |
| 165 | + |
| 166 | +Duplicator |
| 167 | + |
| 168 | +Edit Count |
| 169 | +file = Editcount/SpecialEditcount.i18n.php |
| 170 | + |
| 171 | +Edit Messages |
| 172 | + |
| 173 | +Edit Own |
| 174 | + |
| 175 | +Edit Similar |
| 176 | + |
| 177 | +Edit Subpages |
| 178 | + |
| 179 | +Edit User |
| 180 | + |
| 181 | +Email Address Image |
| 182 | + |
| 183 | +Email Article |
| 184 | + |
| 185 | +Eval |
| 186 | +file = Eval/SpecialEval.i18n.php |
| 187 | + |
| 188 | +Expand Templates |
| 189 | + |
| 190 | +Farmer |
| 191 | +optional = farmercreateurl |
| 192 | +ignored = farmerwikiurl, farmerinterwikiurl |
| 193 | + |
| 194 | +Flagged Revisions - Flagged Revs |
| 195 | +id = ext-fr-flaggedrevs |
| 196 | +file = FlaggedRevs/language/FlaggedRevs.i18n.php |
| 197 | +optional = revreview-toggle |
| 198 | + |
| 199 | +Flagged Revisions - Depreciation Oversight |
| 200 | +id = ext-fr-depreciationoversight |
| 201 | +file = FlaggedRevs/language/DepreciationOversight.i18n.php |
| 202 | + |
| 203 | +Flagged Revisions - Flagged Revs Aliases |
| 204 | +id = ext-fr-flaggedrevsaliases |
| 205 | +file = FlaggedRevs/language/FlaggedRevsAliases.i18n.php |
| 206 | + |
| 207 | +Flagged Revisions - Old Reviewed Pages |
| 208 | +id = ext-fr-oldreviewedpages |
| 209 | +file = FlaggedRevs/language/OldReviewedPages.i18n.php |
| 210 | + |
| 211 | +Flagged Revisions - Quality Oversight |
| 212 | +id = ext-fr-qualityoversight |
| 213 | +file = FlaggedRevs/language/QualityOversight.i18n.php |
| 214 | + |
| 215 | +Flagged Revisions - Reviewed Pages |
| 216 | +id = ext-fr-reviewedpages |
| 217 | +file = FlaggedRevs/language/ReviewedPages.i18n.php |
| 218 | + |
| 219 | +Flagged Revisions - Stabilization |
| 220 | +id = ext-fr-stabilization |
| 221 | +file = FlaggedRevs/language/Stabilization.i18n.php |
| 222 | + |
| 223 | +Flagged Revisions - Stable Pages |
| 224 | +id = ext-fr-stablepages |
| 225 | +file = FlaggedRevs/language/StablePages.i18n.php |
| 226 | + |
| 227 | +Flagged Revisions - Stable Versions |
| 228 | +id = ext-fr-stableversions |
| 229 | +file = FlaggedRevs/language/StableVersions.i18n.php |
| 230 | + |
| 231 | +Flagged Revisions - Unreviewed Pages |
| 232 | +id = ext-fr-unreviewedpages |
| 233 | +file = FlaggedRevs/language/UnreviewedPages.i18n.php |
| 234 | + |
| 235 | +Find Spam |
| 236 | + |
| 237 | +Fixed Image |
| 238 | + |
| 239 | +Force Preview |
| 240 | + |
| 241 | +Format Email |
| 242 | +ignored = email_header |
| 243 | + |
| 244 | +Gadgets |
| 245 | +ignored = gadgets-definition |
| 246 | + |
| 247 | +Global Blocking |
| 248 | +ignored = globalblocking-expiry-options |
| 249 | + |
| 250 | +Global Usage |
| 251 | + |
| 252 | +Gnuplot |
| 253 | + |
| 254 | +Google Analytics |
| 255 | +file = googleAnalytics/googleAnalytics.i18n.php |
| 256 | + |
| 257 | +Google Maps |
| 258 | +var = wgGoogleMapsMessages |
| 259 | + |
| 260 | +Go To Category |
| 261 | + |
| 262 | +HTMLets |
| 263 | + |
| 264 | +Parser i18n tags |
| 265 | +id = ext-i18ntags |
| 266 | +file = I18nTags/I18nTags.i18n.php |
| 267 | + |
| 268 | +Icon |
| 269 | + |
| 270 | +Image Map |
| 271 | +ignored = imagemap_desc_types |
| 272 | + |
| 273 | +Image Tagging |
| 274 | + |
| 275 | +Import Free Images |
| 276 | + |
| 277 | +Import Users |
| 278 | +file = ImportUsers/SpecialImportUsers.i18n.php |
| 279 | + |
| 280 | +Input Box |
| 281 | +file = inputbox/InputBox.i18n.php |
| 282 | + |
| 283 | +Inspect Cache |
| 284 | + |
| 285 | +Intersection |
| 286 | +file = intersection/DynamicPageList.i18n.php |
| 287 | + |
| 288 | +Interwiki Edit Page |
| 289 | +id = ext-interwiki |
| 290 | +file = Interwiki/SpecialInterwiki.i18n.php |
| 291 | +optional = interwiki_defaulturl, interwiki_local, interwiki_trans |
| 292 | +ignored = interwiki_logentry, interwiki_url |
| 293 | + |
| 294 | +Invitations |
| 295 | +ignored = invitations-uninvitedlist-item |
| 296 | + |
| 297 | +Labeled Section Transclusion |
| 298 | +file = LabeledSectionTransclusion/lst.i18n.php |
| 299 | + |
| 300 | +Cldr |
| 301 | +file = cldr/LanguageNames.i18n.php |
| 302 | + |
| 303 | +Language Selector |
| 304 | + |
| 305 | +Latex Doc |
| 306 | + |
| 307 | +Link Search |
| 308 | + |
| 309 | +Liquid Threads |
| 310 | +file = LiquidThreads/Lqt.i18n.php |
| 311 | +ignored = lqt_header_warning_before_big |
| 312 | + |
| 313 | +Lookup User |
| 314 | + |
| 315 | +Maintenance |
| 316 | +ignored = maintenance-initEditCount, maintenance-runJobs, maintenance-showJobs |
| 317 | +ignored = maintenance-stats |
| 318 | + |
| 319 | +Math Stat |
| 320 | +file = MathStatFunctions/MathStatFunctions.i18n.php |
| 321 | + |
| 322 | +Media Functions |
| 323 | + |
| 324 | +Metavid Wiki |
| 325 | +file = MetavidWiki/languages/MV_Messages.php |
| 326 | +optional = ao_file_64Kb_MPEG4, ao_file_256Kb_MPEG4, ao_file_MPEG1, ao_file_MPEG2 |
| 327 | +optional = ao_file_flash_flv |
| 328 | + |
| 329 | +Mibbit |
| 330 | + |
| 331 | +MicroID |
| 332 | + |
| 333 | +Mini Donation |
| 334 | + |
| 335 | +Minimum Name Length |
| 336 | + |
| 337 | +Mini Preview |
| 338 | + |
| 339 | +Multi Boilerplate |
| 340 | +ignored = multiboilerplate, multiboilerplate-label |
| 341 | + |
| 342 | +Multi Upload |
| 343 | +file = MultiUpload/SpecialMultipleUpload.i18n.php |
| 344 | + |
| 345 | +MediaWiki Search |
| 346 | +id = ext-mwsearch |
| 347 | +file = MWSearch/MWSearch.i18n.php |
| 348 | + |
| 349 | +Navigation Popups |
| 350 | + |
| 351 | +Network Auth |
| 352 | +optional = networkauth-name, networkauth-purltext |
| 353 | + |
| 354 | +Newest Pages |
| 355 | + |
| 356 | +News |
| 357 | +optional = newsextension-unknownformat, newsextension-feednotfound |
| 358 | +optional = newsextension-feedrequest, newsextension-checkok |
| 359 | +optional = newsextension-checkok1, newsextension-gotcached, newsextension-purge |
| 360 | +optional = newsextension-loggin, newsextension-outputting, newsextension-stale |
| 361 | +optional = newsextension-nofoundonpage, newsextension-renderedfeed |
| 362 | +optional = newsextension-cachingfeed, newsextension-freshfeed |
| 363 | + |
| 364 | +Newuser Log |
| 365 | +file = Newuserlog/Newuserlog.i18n.php |
| 366 | +ignored = newuserlogentry |
| 367 | + |
| 368 | +New User Message |
| 369 | + |
| 370 | +New User Notification |
| 371 | +file = NewUserNotif/NewUserNotif.i18n.php |
| 372 | + |
| 373 | +Nuke |
| 374 | +file = Nuke/SpecialNuke.i18n.php |
| 375 | + |
| 376 | +OAI-PMH repository |
| 377 | +id = ext-oai |
| 378 | +file = OAI/OAIRepo.i18n.php |
| 379 | + |
| 380 | +Ogg Handler |
| 381 | +optional = ogg-player-cortado, ogg-player-vlc-mozilla, ogg-player-vlc-activex |
| 382 | +optional = ogg-player-quicktime-mozilla, ogg-player-quicktime-activex |
| 383 | + |
| 384 | +Online Status |
| 385 | +ignored = onlinestatus-levels |
| 386 | + |
| 387 | +OpenID |
| 388 | + |
| 389 | +Oversight |
| 390 | +file = Oversight/HideRevision.i18n.php |
| 391 | + |
| 392 | +Page By |
| 393 | + |
| 394 | +Password Reset |
| 395 | + |
| 396 | +Parser Diff Test |
| 397 | + |
| 398 | +Parser Functions |
| 399 | + |
| 400 | +Patroller |
| 401 | + |
| 402 | +Pdf Handler |
| 403 | + |
| 404 | +Piwik |
| 405 | +optional = piwik |
| 406 | + |
| 407 | +Player |
| 408 | +ignored = player-pagetext, player-imagepage-header |
| 409 | + |
| 410 | +PNG Handler |
| 411 | + |
| 412 | +Poem |
| 413 | + |
| 414 | +Post Comment |
| 415 | +file = Postcomment/SpecialPostcomment.i18n.php |
| 416 | + |
| 417 | +POV Watch |
| 418 | +file = PovWatch/PovWatch.i18n.php |
| 419 | + |
| 420 | +Preloader |
| 421 | + |
| 422 | +Profile Monitor |
| 423 | + |
| 424 | +Proofread Page |
| 425 | + |
| 426 | +Protect Section |
| 427 | + |
| 428 | +PSI NoTocNum |
| 429 | + |
| 430 | +Purge |
| 431 | + |
| 432 | +Purge Cache |
| 433 | + |
| 434 | +Quiz |
| 435 | + |
| 436 | +Random Image |
| 437 | + |
| 438 | +Random in Category |
| 439 | +file = RandomInCategory/SpecialRandomincategory.i18n.php |
| 440 | + |
| 441 | +Random Root Page |
| 442 | +file = Randomrootpage/Randomrootpage.i18n.php |
| 443 | + |
| 444 | +Regex Block |
| 445 | +file = regexBlock/regexBlock.i18n.php |
| 446 | + |
| 447 | +Rename User |
| 448 | +file = Renameuser/SpecialRenameuser.i18n.php |
| 449 | + |
| 450 | +Replace Text |
| 451 | + |
| 452 | +Review |
| 453 | + |
| 454 | +Right Functions |
| 455 | + |
| 456 | +See also |
| 457 | + |
| 458 | +Scan Set |
| 459 | + |
| 460 | +Select Category |
| 461 | + |
| 462 | +Semantic Calendar |
| 463 | +file = SemanticCalendar/languages/SC_Messages.php |
| 464 | + |
| 465 | +Semantic Drilldown |
| 466 | +file = SemanticDrilldown/languages/SD_Messages.php |
| 467 | + |
| 468 | +Semantic Forms |
| 469 | +file = SemanticForms/languages/SF_Messages.php |
| 470 | + |
| 471 | +Semantic MediaWiki |
| 472 | +file = SemanticMediaWiki/languages/SMW_Messages.php |
| 473 | +ignored = smw_ask_doculink, smw_service_online_maps, smw_uri_blacklist |
| 474 | +optional = smw_rss_link, smw_decseparator, smw_kiloseparator |
| 475 | +optional = smw_rss_description, smw_browse_more, specialpages-group-smw_group |
| 476 | + |
| 477 | +Show Processlist |
| 478 | + |
| 479 | +Sign Document |
| 480 | + |
| 481 | +Sign Document Special Create |
| 482 | +file = SignDocument/SpecialCreateSignDocument.i18n.php |
| 483 | + |
| 484 | +Sign Document Special |
| 485 | +file = SignDocument/SpecialSignDocument.i18n.php |
| 486 | + |
| 487 | +Simple Anti Spam |
| 488 | + |
| 489 | +Site Matrix |
| 490 | + |
| 491 | +Skin Per Page |
| 492 | + |
| 493 | +Smooth Gallery |
| 494 | +ignored = smoothgallery-pagetext |
| 495 | + |
| 496 | +Social Profile User Board |
| 497 | +file = SocialProfile/UserBoard/UserBoard.i18n.php |
| 498 | + |
| 499 | +Social Profile User Profile |
| 500 | +file = SocialProfile/UserProfile/UserProfile.i18n.php |
| 501 | + |
| 502 | +Social Profile User Relationship |
| 503 | +file = SocialProfile/UserRelationship/UserRelationship.i18n.php |
| 504 | + |
| 505 | +Spam Blacklist |
| 506 | + |
| 507 | +Spam Diff Tool |
| 508 | + |
| 509 | +Spam Regex |
| 510 | + |
| 511 | +Special File List |
| 512 | +file = SpecialFileList/SpecialFilelist.i18n.php |
| 513 | + |
| 514 | +Special Form |
| 515 | +ignored = formtemplatepattern |
| 516 | + |
| 517 | +Sub Page List 3 |
| 518 | + |
| 519 | +Stale Pages |
| 520 | + |
| 521 | +Syntax Highlight GeSHi |
| 522 | +file = SyntaxHighlight_GeSHi/SyntaxHighlight_GeSHi.i18n.php |
| 523 | + |
| 524 | +Tab0 |
| 525 | + |
| 526 | +Talk Here |
| 527 | +ignored = talkhere-title, talkhere-headtext, talkhere-afterinput |
| 528 | +ignored = talkhere-afterform |
| 529 | + |
| 530 | +Template Link |
| 531 | + |
| 532 | +TidyTab |
| 533 | +file = TidyTab/Tidy.i18n.php |
| 534 | + |
| 535 | +Throttle |
| 536 | +file = Throttle/UserThrottle.i18n.php |
| 537 | + |
| 538 | +Timeline |
| 539 | +file = timeline/Timeline.i18n.php |
| 540 | + |
| 541 | +Title Blacklist |
| 542 | + |
| 543 | +Title Key |
| 544 | + |
| 545 | +Todo |
| 546 | +file = Todo/SpecialTodo.i18n.php |
| 547 | + |
| 548 | +Todo Tasks |
| 549 | +file = TodoTasks/SpecialTaskList.i18n.php |
| 550 | + |
| 551 | +Tooltip |
| 552 | + |
| 553 | +Tor Block |
| 554 | + |
| 555 | +Translate |
| 556 | +optional = translate-page-paging-links |
| 557 | + |
| 558 | +Usage Statistics |
| 559 | +file = UsageStatistics/SpecialUserStats.i18n.php |
| 560 | + |
| 561 | +User Contact Links |
| 562 | +file = UserContactLinks/UserSignature.i18n.php |
| 563 | + |
| 564 | +User Images |
| 565 | + |
| 566 | +User Merge |
| 567 | + |
| 568 | +Username Blacklist |
| 569 | + |
| 570 | +User Rights Notification |
| 571 | +id = ext-userrightsnotif |
| 572 | +file = UserRightsNotif/UserRightsNotif.i18n.php |
| 573 | + |
| 574 | +Vote |
| 575 | + |
| 576 | +Watchers |
| 577 | + |
| 578 | +Watch Subpages |
| 579 | + |
| 580 | +Web Store |
| 581 | + |
| 582 | +White List |
| 583 | +var = allMessages |
| 584 | +file = WhiteList/SpecialWhitelistEdit.i18n.php |
| 585 | + |
| 586 | +Who Is Watching |
| 587 | +file = WhoIsWatching/SpecialWhoIsWatching.i18n.php |
| 588 | + |
| 589 | +Wikidata Language Manager |
| 590 | +var = wdMessages |
| 591 | +file = Wikidata/SpecialLanguages.i18n.php |
| 592 | +ignored = ow_editing_policy_url |
| 593 | + |
| 594 | +Wikihiero |
| 595 | +file = wikihiero/wikihiero.i18n.php |
| 596 | + |
| 597 | +Woopra |
| 598 | + |
| 599 | +YUI |
| 600 | +file = SocialProfile/YUI/yui.i18n.php |
| 601 | + |
| 602 | +YouTube Auth Sub |
\ No newline at end of file |
Property changes on: trunk/extensions/Translate/groups/defines.txt |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 603 | + native |
Index: trunk/extensions/Translate/_autoload.php |
— | — | @@ -39,7 +39,8 @@ |
40 | 40 | $wgAutoloadClasses['WikiFormatWriter'] = $dir . 'ffs/Wiki.php'; |
41 | 41 | $wgAutoloadClasses['WikiExtensionFormatReader'] = $dir . 'ffs/WikiExtension.php'; |
42 | 42 | $wgAutoloadClasses['WikiExtensionFormatWriter'] = $dir . 'ffs/WikiExtension.php'; |
43 | | -$wgAutoloadClasses['GettextFormatHandler'] = $dir . 'ffs/Gettext.php'; |
| 43 | +$wgAutoloadClasses['GettextFormatReader'] = $dir . 'ffs/Gettext.php'; |
| 44 | +$wgAutoloadClasses['GettextFormatWriter'] = $dir . 'ffs/Gettext.php'; |
44 | 45 | $wgAutoloadClasses['JavaFormatReader'] = $dir . 'ffs/Java.php'; |
45 | 46 | $wgAutoloadClasses['JavaFormatWriter'] = $dir . 'ffs/Java.php'; |
46 | 47 | |
— | — | @@ -57,6 +58,6 @@ |
58 | 59 | |
59 | 60 | |
60 | 61 | # predefined group |
61 | | -$wgAutoloadClasses['PremadeMediawikiExtensionGroups'] = $dir . 'mwextensions/MediaWikiExtensions.php'; |
| 62 | +$wgAutoloadClasses['PremadeMediawikiExtensionGroups'] = $dir . 'groups/MediaWikiExtensions.php'; |
62 | 63 | |
63 | 64 | |
Index: trunk/extensions/Translate/MessageGroups.php |
— | — | @@ -1,5 +1,4 @@ |
2 | 2 | <?php |
3 | | -if (!defined('MEDIAWIKI')) die(); |
4 | 3 | |
5 | 4 | abstract class MessageGroup { |
6 | 5 | /** |
— | — | @@ -65,15 +64,8 @@ |
66 | 65 | public function getMangler() { return $this->mangler; } |
67 | 66 | public function setMangler( $value ) { $this->mangler = $value; } |
68 | 67 | |
69 | | - /** |
70 | | - * All the messages for this group, by language code. |
71 | | - */ |
72 | | - private $messages = array(); |
| 68 | + public $namespaces = array( NS_MEDIAWIKI, NS_MEDIAWIKI_TALK ); |
73 | 69 | |
74 | | - public static function factory( $label, $id ) { |
75 | | - return null; |
76 | | - } |
77 | | - |
78 | 70 | public function getReader( $code ) { |
79 | 71 | return null; |
80 | 72 | } |
— | — | @@ -117,6 +109,10 @@ |
118 | 110 | } |
119 | 111 | return isset( $this->messages[$code][$key] ) ? $this->messages[$code][$key] : null; |
120 | 112 | } |
| 113 | + /** |
| 114 | + * All the messages for this group, by language code. |
| 115 | + */ |
| 116 | + private $messages = array(); |
121 | 117 | |
122 | 118 | /** |
123 | 119 | * In this function message group should add translations from the stored file |
— | — | @@ -140,10 +136,44 @@ |
141 | 137 | */ |
142 | 138 | public function getMessageFile( $code ) { return false; } |
143 | 139 | |
| 140 | + |
| 141 | + public function initCollection( $code ) { |
| 142 | + $collection = new MessageCollection( $code ); |
| 143 | + $definitions = $this->getDefinitions(); |
| 144 | + foreach ( $definitions as $key => $definition ) { |
| 145 | + $collection->add( new TMessage( $key, $definition ) ); |
| 146 | + } |
| 147 | + |
| 148 | + $bools = $this->getBools(); |
| 149 | + foreach ( $bools['optional'] as $key ) { |
| 150 | + if ( isset($collection[$key]) ) { |
| 151 | + $collection[$key]->optional = true; |
| 152 | + } |
| 153 | + } |
| 154 | + |
| 155 | + foreach ( $bools['ignored'] as $key ) { |
| 156 | + if ( isset($collection[$key]) ) { |
| 157 | + $collection[$key]->ignored = true; |
| 158 | + } |
| 159 | + } |
| 160 | + |
| 161 | + return $collection; |
| 162 | + } |
| 163 | + |
| 164 | + public function fillCollection( MessageCollection $collection ) { |
| 165 | + TranslateUtils::fillExistence( $collection, $this->namespaces ); |
| 166 | + TranslateUtils::fillContents( $collection, $this->namespaces ); |
| 167 | + $this->fill( $collection ); |
| 168 | + } |
| 169 | + |
144 | 170 | public function __construct() { |
145 | 171 | $this->mangler = StringMatcher::emptyMatcher(); |
146 | 172 | } |
147 | 173 | |
| 174 | + public static function factory( $label, $id ) { |
| 175 | + return null; |
| 176 | + } |
| 177 | + |
148 | 178 | } |
149 | 179 | |
150 | 180 | class CoreMessageGroup extends MessageGroup { |
— | — | @@ -229,11 +259,6 @@ |
230 | 260 | return $group; |
231 | 261 | } |
232 | 262 | |
233 | | - /* |
234 | | - * Append (mw ext) to extension labels. This doesn't break sorting. |
235 | | - */ |
236 | | - public function getLabel() { return $this->label . " (mw ext)"; } |
237 | | - |
238 | 263 | /** |
239 | 264 | * This function loads messages for given language for further use. |
240 | 265 | * |
— | — | @@ -278,7 +303,6 @@ |
279 | 304 | } |
280 | 305 | |
281 | 306 | class CoreMostUsedMessageGroup extends CoreMessageGroup { |
282 | | - protected $fileExporter = null; |
283 | 307 | protected $label = 'MediaWiki messages (most used)'; |
284 | 308 | protected $id = 'core-mostused'; |
285 | 309 | protected $meta = true; |
— | — | @@ -302,7 +326,6 @@ |
303 | 327 | } |
304 | 328 | |
305 | 329 | class AllMediawikiExtensionsGroup extends ExtensionMessageGroup { |
306 | | - protected $fileExporter = null; |
307 | 330 | protected $label = 'All extensions'; |
308 | 331 | protected $id = 'ext-0-all'; |
309 | 332 | protected $meta = true; |
— | — | @@ -367,7 +390,6 @@ |
368 | 391 | } |
369 | 392 | |
370 | 393 | class AllWikimediaExtensionsGroup extends AllMediawikiExtensionsGroup { |
371 | | - protected $fileExporter = null; |
372 | 394 | protected $label = 'Extensions used by Wikimedia'; |
373 | 395 | protected $id = 'ext-0-wikimedia'; |
374 | 396 | protected $meta = true; |
— | — | @@ -446,7 +468,6 @@ |
447 | 469 | } |
448 | 470 | |
449 | 471 | class AllFlaggedRevsExtensionsGroup extends AllMediawikiExtensionsGroup { |
450 | | - protected $fileExporter = null; |
451 | 472 | protected $label = 'All FlaggedRevs messages'; |
452 | 473 | protected $id = 'ext-0-flaggedrevs'; |
453 | 474 | protected $meta = true; |
— | — | @@ -485,7 +506,6 @@ |
486 | 507 | |
487 | 508 | |
488 | 509 | class FreeColMessageGroup extends MessageGroup { |
489 | | - protected $fileExporter = 'CoreExporter'; |
490 | 510 | protected $label = 'FreeCol (open source game)'; |
491 | 511 | protected $id = 'out-freecol'; |
492 | 512 | protected $prefix= 'freecol-'; |
— | — | @@ -536,6 +556,54 @@ |
537 | 557 | |
538 | 558 | } |
539 | 559 | |
| 560 | +class GettextMessageGroup extends MessageGroup { |
| 561 | + /** |
| 562 | + * Name of the array where all messages are stored, if applicable. |
| 563 | + */ |
| 564 | + protected $potFile = 'messages'; |
| 565 | + public function getPotFile() { return $this->potFile; } |
| 566 | + public function setPotFile( $value ) { $this->potFile = $value; } |
| 567 | + |
| 568 | + protected $codeMap = array(); |
| 569 | + |
| 570 | + |
| 571 | + protected $prefix = ''; |
| 572 | + public function getPrefix() { return $this->prefix; } |
| 573 | + public function setPrefix( $value ) { $this->prefix = $value; } |
| 574 | + |
| 575 | + |
| 576 | + public function getMessageFile( $code ) { |
| 577 | + if ( $code == 'en' ) { |
| 578 | + return $this->getPotFile(); |
| 579 | + } else { |
| 580 | + if ( isset($this->codeMap[$code]) ) { |
| 581 | + $code = $this->codeMap[$code]; |
| 582 | + } |
| 583 | + return "$code.po"; |
| 584 | + } |
| 585 | + } |
| 586 | + |
| 587 | + public static function factory( $label, $id ) { |
| 588 | + $group = new GettextMessageGroup; |
| 589 | + $group->setLabel( $label ); |
| 590 | + $group->setId( $id ); |
| 591 | + return $group; |
| 592 | + } |
| 593 | + |
| 594 | + |
| 595 | + public function getReader( $code ) { |
| 596 | + $reader = new GettextFormatReader( $this->getPrefix() . $this->getMessageFile( $code ) ); |
| 597 | + if ( $code === 'en' ) |
| 598 | + $reader->setPotMode( true ); |
| 599 | + return $reader; |
| 600 | + } |
| 601 | + |
| 602 | + public function getWriter() { |
| 603 | + return new GettextFormatWriter( $this ); |
| 604 | + } |
| 605 | + |
| 606 | +} |
| 607 | + |
540 | 608 | class WikiMessageGroup extends MessageGroup { |
541 | 609 | protected $source = null; |
542 | 610 | |
Index: trunk/extensions/Translate/ffs/Gettext.php |
— | — | @@ -1,190 +1,346 @@ |
2 | 2 | <?php |
3 | 3 | if (!defined('MEDIAWIKI')) die(); |
4 | | -/** |
5 | | - * Parses a po file that has been exported from Mediawiki. Other files are not |
6 | | - * supported. |
7 | | - */ |
8 | 4 | |
9 | | -class GettextFormatHandler { |
| 5 | +class GettextFormatReader extends SimpleFormatReader { |
| 6 | + public function setPotMode( $value ) { |
| 7 | + $this->pot = $value; |
| 8 | + } |
| 9 | + protected $pot = false; |
10 | 10 | |
11 | | - public function __construct( $file ) { |
12 | | - $this->file = $file; |
| 11 | + public function parseAuthors() { |
| 12 | + return array(); // Not implemented |
13 | 13 | } |
14 | 14 | |
15 | | - /** |
16 | | - * Loads translations for comparison. |
17 | | - * |
18 | | - * @param $id Id of MessageGroup. |
19 | | - * @param $code Language code. |
20 | | - * @return MessageCollection |
21 | | - */ |
22 | | - protected function initMessages( $id, $code ) { |
23 | | - $messages = new MessageCollection( $code ); |
24 | | - $group = MessageGroups::getGroup( $id ); |
25 | | - |
26 | | - $definitions = $group->getDefinitions(); |
27 | | - foreach ( $definitions as $key => $definition ) { |
28 | | - $messages->add( new TMessage( $key, $definition ) ); |
| 15 | + public function parseStaticHeader() { |
| 16 | + if ( $this->filename === false ) { |
| 17 | + return ''; |
29 | 18 | } |
30 | | - |
31 | | - $bools = $group->getBools(); |
32 | | - foreach ( $bools['optional'] as $key ) { |
33 | | - if ( isset($messages[$key]) ) { $messages[$key]->optional = true; } |
34 | | - } |
35 | | - foreach ( $bools['ignored'] as $key ) { |
36 | | - if ( isset($messages[$key]) ) { $messages[$key]->ignored = true; } |
37 | | - } |
38 | | - |
39 | | - $messages->populatePageExistence(); |
40 | | - $messages->populateTranslationsFromDatabase(); |
41 | | - $group->fill( $messages ); |
42 | | - |
43 | | - return $messages; |
| 19 | + $data = file_get_contents( $this->filename ); |
| 20 | + $length = strpos( $data, "msgid" ); |
| 21 | + return substr( $data, 0, $length ); |
44 | 22 | } |
45 | 23 | |
46 | | - /** |
47 | | - * Parses relevant stuff from the po file. |
48 | | - */ |
49 | | - public function parse() { |
50 | | - $data = file_get_contents( $this->file ); |
| 24 | + public function parseFile() { |
| 25 | + $data = file_get_contents( $this->filename ); |
51 | 26 | $data = str_replace( "\r\n", "\n", $data ); |
52 | 27 | |
53 | 28 | $matches = array(); |
54 | 29 | if ( preg_match( '/X-Language-Code:\s+([a-zA-Z-_]+)/', $data, $matches ) ) { |
55 | 30 | $code = $matches[1]; |
56 | | - echo "Detected language as $code\n"; |
57 | 31 | } else { |
58 | | - echo "Unable to determine language code\n"; |
59 | | - return false; |
60 | 32 | } |
61 | 33 | |
62 | 34 | if ( preg_match( '/X-Message-Group:\s+([a-zA-Z0-9-_]+)/', $data, $matches ) ) { |
63 | 35 | $groupId = $matches[1]; |
64 | | - echo "Detected message group as $groupId\n"; |
| 36 | + $useCtxtAsKey = true; |
65 | 37 | } else { |
66 | | - echo "Unable to determine message group\n"; |
67 | | - return false; |
| 38 | + $useCtxtAsKey = false; |
68 | 39 | } |
69 | 40 | |
70 | | - $contents = $this->initMessages( $groupId, $code ); |
71 | | - |
72 | | - echo "----\n"; |
73 | | - |
74 | 41 | $poformat = '".*"\n?(^".*"$\n?)*'; |
75 | 42 | $quotePattern = '/(^"|"$\n?)/m'; |
76 | 43 | |
77 | 44 | $sections = preg_split( '/\n{2,}/', $data ); |
| 45 | + array_shift( $sections ); // First isn't an actual message |
78 | 46 | $changes = array(); |
79 | 47 | foreach ( $sections as $section ) { |
| 48 | + if ( trim($section) === '' ) continue; |
| 49 | + |
| 50 | + $item = array( |
| 51 | + 'ctxt' => '', |
| 52 | + 'id' => '', |
| 53 | + 'str' => '', |
| 54 | + 'flags' => array(), |
| 55 | + 'comments' => array(), |
| 56 | + ); |
| 57 | + |
80 | 58 | $matches = array(); |
81 | 59 | if ( preg_match( "/^msgctxt\s($poformat)/mx", $section, $matches ) ) { |
82 | 60 | // Remove quoting |
83 | | - $key = preg_replace( $quotePattern, '', $matches[1] ); |
84 | | - // Ignore unknown keys |
85 | | - if ( !isset($contents[$key]) ) continue; |
| 61 | + $item['ctxt'] = preg_replace( $quotePattern, '', $matches[1] ); |
| 62 | + } elseif ( $useCtxtAsKey ) { |
| 63 | + // Invalid message |
| 64 | + continue; |
| 65 | + } |
| 66 | + |
| 67 | + $matches = array(); |
| 68 | + if ( preg_match( "/^msgid\s($poformat)/mx", $section, $matches ) ) { |
| 69 | + // Remove quoting |
| 70 | + $item['id'] = preg_replace( $quotePattern, '', $matches[1] ); |
| 71 | + // Restore new lines and remove quoting |
| 72 | + //$definition = stripcslashes( $definition ); |
86 | 73 | } else { |
| 74 | + #echo "Definition not found!\n$section"; |
87 | 75 | continue; |
88 | 76 | } |
| 77 | + |
89 | 78 | $matches = array(); |
90 | 79 | if ( preg_match( "/^msgstr\s($poformat)/mx", $section, $matches ) ) { |
91 | 80 | // Remove quoting |
92 | | - $translation = preg_replace( $quotePattern, '', $matches[1] ); |
| 81 | + $item['str'] = preg_replace( $quotePattern, '', $matches[1] ); |
93 | 82 | // Restore new lines and remove quoting |
94 | | - $translation = stripcslashes( $translation ); |
| 83 | + #$translation = stripcslashes( $translation ); |
95 | 84 | } else { |
| 85 | + #echo "Translation not found!\n"; |
96 | 86 | continue; |
97 | 87 | } |
98 | 88 | |
99 | | - // Fuzzy messages |
100 | | - if ( preg_match( '/^#, fuzzy$/m', $section ) ) { |
101 | | - $translation = TRANSLATE_FUZZY . $translation; |
| 89 | + // Parse flags |
| 90 | + $matches = array(); |
| 91 | + if ( preg_match( '/^#,(.*)$/m', $section, $matches ) ) { |
| 92 | + $flags = array_map( 'trim', explode( ',', $matches[1] ) ); |
| 93 | + foreach ( $flags as $key => $flag ) { |
| 94 | + if ( $flag === 'fuzzy' ) { |
| 95 | + $item['str'] = TRANSLATE_FUZZY . $item['str']; |
| 96 | + unset( $flags[$key] ); |
| 97 | + } |
| 98 | + } |
| 99 | + $item['flags'] = $flags; |
102 | 100 | } |
103 | 101 | |
104 | | - if ( $translation !== (string) $contents[$key]->translation ) { |
105 | | - echo "Translation of $key differs:\n$translation\n\n"; |
106 | | - $changes["$key/$code"] = $translation; |
| 102 | + $matches = array(); |
| 103 | + if ( preg_match_all( '/^#([^ ]) (.*)$/m', $section, $matches, PREG_SET_ORDER ) ) { |
| 104 | + foreach( $matches as $match ) { |
| 105 | + if ( $match[1] !== ',' ) { |
| 106 | + $item['comments'][$match[1]][] = $match[2]; |
| 107 | + } |
| 108 | + } |
107 | 109 | } |
108 | 110 | |
| 111 | + $lang = Language::factory( 'en' ); |
| 112 | + if ( $useCtxtAsKey ) { |
| 113 | + $key = $item['ctxt']; |
| 114 | + } else { |
| 115 | + global $wgLegalTitleChars; |
| 116 | + $hash = sha1( $item['ctxt'] . $item['id'] ); |
| 117 | + $snippet = $item['id']; |
| 118 | + $snippet = preg_replace( "/[^$wgLegalTitleChars]/", ' ', $snippet ); |
| 119 | + $snippet = preg_replace( "/[:&%]/", ' ', $snippet ); |
| 120 | + $snippet = preg_replace( "/ {2,}/", ' ', $snippet ); |
| 121 | + $snippet = str_replace( ' ', '_', $snippet ); |
| 122 | + $snippet = trim( $snippet ); |
| 123 | + $snippet = $lang->truncate( $snippet, 30 ); |
| 124 | + $key = $hash . '-' . $snippet; |
| 125 | + } |
| 126 | + |
| 127 | + $changes[$key] = $item; |
| 128 | + |
109 | 129 | } |
110 | 130 | |
111 | 131 | return $changes; |
112 | 132 | |
113 | 133 | } |
114 | 134 | |
115 | | - // Inherited: Stored objects |
116 | | - protected $info; |
| 135 | + public function parseMessages( StringMangler $mangler ) { |
| 136 | + $defs = $this->parseFile(); |
| 137 | + $messages = array(); |
| 138 | + foreach ( $defs as $key => $def ) { |
| 139 | + if ( $this->pot ) { |
| 140 | + $messages[$key] = $def['id']; |
| 141 | + } else { |
| 142 | + if ( $def['str'] !== '' ) { |
| 143 | + $messages[$key] = $def['str']; |
| 144 | + } |
| 145 | + } |
| 146 | + } |
| 147 | + return $messages; |
| 148 | + } |
117 | 149 | |
118 | | - public function makeHeaderTo( $handle ) { |
119 | | - $name = $this->info->getOption( 'languagename' ); |
120 | | - $native = $this->info->getOption( 'nativename' ); |
121 | | - $authors = $this->_formatAuthors( $this->info->getOption( 'authors' ) ); |
| 150 | +} |
122 | 151 | |
123 | | - fwrite( $handle, <<<HEADER |
124 | | -# Messages for $name ($native) |
125 | | -# Exported from XYZ |
126 | | -$authors |
| 152 | +class GettextFormatWriter extends SimpleFormatWriter { |
| 153 | + protected $data = array(); |
127 | 154 | |
128 | | -HEADER |
129 | | - ); |
| 155 | + public function fileExport( array $languages, $targetDirectory ) { |
| 156 | + foreach ( $languages as $code ) { |
| 157 | + $messages = $this->getMessagesForExport( $this->group, $code ); |
| 158 | + $filename = $this->group->getMessageFile( $code ); |
| 159 | + $target = $targetDirectory . '/' . $filename; |
| 160 | + |
| 161 | + wfMkdirParents( dirname( $target ) ); |
| 162 | + $tHandle = fopen( $target, 'wt' ); |
| 163 | + if ( $tHandle === false ) { |
| 164 | + throw new MWException( "Unable to open target for writing" ); |
| 165 | + } |
| 166 | + |
| 167 | + $this->exportLanguage( $tHandle, $code, $messages ); |
| 168 | + |
| 169 | + fclose( $tHandle ); |
| 170 | + } |
130 | 171 | } |
131 | 172 | |
132 | | - protected function _formatAuthors( array $authors ) { |
133 | | - $s = array(); |
134 | | - foreach ( $authors as $a ) { |
135 | | - $s[] = "# Author: $a"; |
| 173 | + public function webExport( MessageCollection $MG ) { |
| 174 | + global $wgTranslateExtensionDirectory; |
| 175 | + $filename = $this->group->getMessageFile( $MG->code ); |
| 176 | + |
| 177 | + $tHandle = fopen( 'php://temp', 'wt' ); |
| 178 | + |
| 179 | + $this->exportLanguage( $tHandle, $MG->code, $MG ); |
| 180 | + |
| 181 | + rewind( $tHandle ); |
| 182 | + $data = stream_get_contents( $tHandle ); |
| 183 | + fclose( $tHandle ); |
| 184 | + return $data; |
| 185 | + } |
| 186 | + |
| 187 | + public function load( $code ) { |
| 188 | + $reader = $this->group->getReader( $code ); |
| 189 | + if ( $reader ) { |
| 190 | + $this->addAuthors( $reader->parseAuthors(), $code ); |
| 191 | + $this->staticHeader = $reader->parseStaticHeader(); |
| 192 | + $this->data = $reader->parseFile(); |
136 | 193 | } |
137 | | - return "\n" . implode( "\n", $s ) . "\n"; |
138 | 194 | } |
139 | 195 | |
140 | | - protected function _exportItem( $handle, $key, $value ) { |
141 | | - $prefix = $this->info->getOption( 'exportprefix' ); |
142 | | - if ( $prefix ) fwrite( $handle, $prefix ); |
143 | 196 | |
144 | | - # Add the key name |
145 | | - fwrite( $handle, "'$key'" ); |
146 | | - # Add the appropriate block whitespace |
147 | | - fwrite( $handle, str_repeat( ' ', $this->padTo - strlen($key) ) ); |
148 | | - fwrite( $handle, ' => ' ); |
| 197 | + public function exportLanguage( $handle, $code, $messages ) { |
| 198 | + global $wgSitename, $wgServer, $wgTranslateDocumentationLanguageCode; |
149 | 199 | |
150 | | - # Check for the appropriate apostrophe and add the value |
151 | | - # Quote \ here, because it needs always escaping |
152 | | - $value = addcslashes( $value, '\\' ); |
| 200 | + $this->load( $code ); |
| 201 | + $lang = Language::factory( 'en' ); |
153 | 202 | |
154 | | - # For readability |
155 | | - $single = "'"; |
156 | | - $double = '"'; |
157 | | - $quote = $single; |
| 203 | + $out = ''; |
| 204 | + $now = wfTimestampNow(); |
| 205 | + $label = $this->group->getLabel(); |
| 206 | + $languageName = TranslateUtils::getLanguageName( $code ); |
158 | 207 | |
159 | | - # It is safe to use '-quoting, unless there is '-quote in the text |
160 | | - if( strpos( $value, $single ) !== false ) { |
| 208 | + $headers = array(); |
| 209 | + $headers['Project-Id-Version'] = $label; |
| 210 | + // TODO: make this customisable or something |
| 211 | + //$headers['Report-Msgid-Bugs-To'] = $wgServer; |
| 212 | + // TODO: sprintfDate doesn't support any time zone flags |
| 213 | + //$headers['POT-Creation-Date'] |
| 214 | + $headers['PO-Revision-Date'] = $lang->sprintfDate( 'xnY-xnm-xnd xnH:xni:xns+0000', $now ); |
| 215 | + $headers['Language-Team'] = $languageName; |
| 216 | + $headers['Content-Type'] = 'text/plain; charset=UTF-8'; |
| 217 | + $headers['Content-Transfer-Encoding'] = '8bit'; |
161 | 218 | |
162 | | - # In case there is no variables that need to be escaped, just use "-quote |
163 | | - if( strpos( $value, $double ) === false && !preg_match('/\$[^0-9]/', $value) ) { |
164 | | - $quote = $double; |
| 219 | + $headers['X-Generator'] = 'MediaWiki ' . SpecialVersion::getVersion() . |
| 220 | + "; Translate extension (" .TRANSLATE_VERSION . ")"; |
165 | 221 | |
166 | | - # Something needs quoting, pick the quote which causes less quoting |
167 | | - } else { |
168 | | - $doubleEsc = substr_count( $value, $double ) + substr_count( $value, '$' ); |
169 | | - $singleEsc = substr_count( $value, $single ); |
| 222 | + $headers['X-Translation-Project'] = "$wgSitename at $wgServer"; |
| 223 | + $headers['X-Language-Code'] = $code; |
| 224 | + $headers['X-Message-Group'] = $this->group->getId(); |
170 | 225 | |
171 | | - if ( $doubleEsc < $singleEsc ) { |
172 | | - $quote = $double; |
173 | | - $extra = '$'; |
174 | | - } else { |
175 | | - $extra = ''; |
176 | | - } |
| 226 | + $headerlines = array(''); |
| 227 | + foreach ( $headers as $key => $value ) { |
| 228 | + $headerlines[] = "$key: $value\n"; |
| 229 | + } |
177 | 230 | |
178 | | - $value = addcslashes( $value, $quote . $extra ); |
| 231 | + fwrite( $handle, "# Translation of $label to $languageName\n#\n" ); |
| 232 | + fwrite( $handle, $this->formatAuthors( "# Author@$wgSitename: ", $code ) ); |
| 233 | + fwrite( $handle, "# --\n" ); |
| 234 | + |
| 235 | + $header = preg_replace( '/^# translation of (.*) to (.*)$\n/im', '', $this->staticHeader ); |
| 236 | + |
| 237 | + fwrite( $handle, $header ); |
| 238 | + fwrite( $handle, $this->formatmsg( '', $headerlines ) ); |
| 239 | + |
| 240 | + foreach ( $messages as $key => $m) { |
| 241 | + $flags = array(); |
| 242 | + |
| 243 | + # CASE1: ignored |
| 244 | + if ( $m->ignored ) $flags[] = 'x-ignored'; |
| 245 | + |
| 246 | + $translation = $m->translation; |
| 247 | + # CASE2: no translation |
| 248 | + if ( $translation === null ) $translation = ''; |
| 249 | + |
| 250 | + # CASE3: optional messages; accept only if different |
| 251 | + if ( $m->optional ) $flags[] = 'x-optional'; |
| 252 | + |
| 253 | + # Remove fuzzy markings before export |
| 254 | + $flags = array(); |
| 255 | + $comments = array(); |
| 256 | + if ( isset($this->data[$key]['flags']) ) { |
| 257 | + $flags = $this->data[$key]['flags']; |
179 | 258 | } |
| 259 | + if ( strpos( $translation, TRANSLATE_FUZZY ) !== false ) { |
| 260 | + $translation = str_replace( TRANSLATE_FUZZY, '', $translation ); |
| 261 | + $flags[] = 'fuzzy'; |
| 262 | + } |
| 263 | + |
| 264 | + $documentation = ''; |
| 265 | + if ( $wgTranslateDocumentationLanguageCode ) { |
| 266 | + $documentation = TranslateUtils::getMessageContent( $key, $wgTranslateDocumentationLanguageCode ); |
| 267 | + } |
| 268 | + |
| 269 | + $comments = array(); |
| 270 | + if ( isset($this->data[$key]['comments']) ) { |
| 271 | + $comments = $this->data[$key]['comments']; |
| 272 | + } |
| 273 | + |
| 274 | + fwrite( $handle, $this->formatcomments( $comments, $documentation, $flags ) ); |
| 275 | + |
| 276 | + if ( isset($this->data[$key]['ctxt']) ) { |
| 277 | + $key = $this->data[$key]['ctxt']; |
| 278 | + } |
| 279 | + fwrite( $handle, $this->formatmsg( $m->definition, $translation, $key ) ); |
| 280 | + |
180 | 281 | } |
181 | 282 | |
182 | | - fwrite( $handle, $quote . $value . $quote ); |
183 | | - fwrite( $handle, ",\n" ); |
| 283 | + return $out; |
184 | 284 | } |
185 | 285 | |
| 286 | +<<<<<<< .mine |
| 287 | + protected function escape( $line ) { |
| 288 | + #$line = addcslashes( $line, '\\"' ); |
| 289 | + $line = str_replace( "\n", '\n', $line ); |
| 290 | + $line = '"' . $line . '"'; |
| 291 | + return $line; |
| 292 | +======= |
186 | 293 | public function parseMessages( $filename ) { |
187 | 294 | $messages = array(); |
188 | 295 | require( $filename ); |
189 | 296 | return $messages; |
| 297 | +>>>>>>> .r35998 |
190 | 298 | } |
191 | | -} |
| 299 | +<<<<<<< .mine |
| 300 | + |
| 301 | + protected function formatcomments( $comments, $documentation = false, $flags = false ) { |
| 302 | + if ( $documentation ) { |
| 303 | + foreach ( explode( "\n", $documentation ) as $line ) { |
| 304 | + $comments['.'][] = $line; |
| 305 | + } |
| 306 | + } |
| 307 | + |
| 308 | +======= |
| 309 | +>>>>>>> .r35998 |
| 310 | + if ( $flags ) { |
| 311 | + $comments[','][] = implode( ', ', $flags ); |
| 312 | + } |
| 313 | + |
| 314 | + // Ensure there is always something |
| 315 | + if ( !count($comments) ) $comments[':'][] = ''; |
| 316 | + |
| 317 | + $order = array( ' ', '.', ':', ',', '|' ); |
| 318 | + $output = array(); |
| 319 | + foreach ( $order as $type ) { |
| 320 | + if ( !isset($comments[$type]) ) continue; |
| 321 | + foreach ( $comments[$type] as $value ) { |
| 322 | + $output[] = "#$type $value"; |
| 323 | + } |
| 324 | + } |
| 325 | + |
| 326 | + return implode( "\n", $output ) . "\n"; |
| 327 | + } |
| 328 | + |
| 329 | + protected function formatmsg( $msgid, $msgstr, $msgctxt = false ) { |
| 330 | + $output = array(); |
| 331 | + |
| 332 | + if ( $msgctxt ) { |
| 333 | + $output[] = 'msgctxt ' . $this->escape( $msgctxt ); |
| 334 | + } |
| 335 | + |
| 336 | + if ( !is_array( $msgid ) ) { $msgid = array( $msgid ); } |
| 337 | + if ( !is_array( $msgstr ) ) { $msgstr = array( $msgstr ); } |
| 338 | + |
| 339 | + $cb = array( $this, 'escape' ); |
| 340 | + $output[] = 'msgid ' . implode( "\n", array_map( $cb, $msgid ) ); |
| 341 | + $output[] = 'msgstr ' . implode( "\n", array_map( $cb, $msgstr ) ); |
| 342 | + |
| 343 | + $out = implode( "\n", $output ) . "\n\n"; |
| 344 | + return $out; |
| 345 | + |
| 346 | + } |
| 347 | +} |
\ No newline at end of file |