Translate extension for MediaWiki
 
Loading...
Searching...
No Matches
DtdFFS.php
Go to the documentation of this file.
1<?php
15
21class DtdFFS extends SimpleFFS {
22 public function getFileExtensions() {
23 return [ '.dtd' ];
24 }
25
30 public function readFromVariable( $data ) {
31 preg_match_all( ',# Author: ([^\n]+)\n,', $data, $matches );
32 $authors = $matches[1];
33
34 preg_match_all( ',<!ENTITY[ ]+([^ ]+)\s+"([^"]+)"[^>]*>,', $data, $matches );
35 list( , $keys, $messages ) = $matches;
36 $messages = array_combine(
37 $keys,
38 array_map(
39 static function ( $message ) {
40 return html_entity_decode( $message, ENT_QUOTES );
41 },
42 $messages
43 )
44 );
45
46 $messages = $this->group->getMangler()->mangleArray( $messages );
47
48 return [
49 'AUTHORS' => $authors,
50 'MESSAGES' => $messages,
51 ];
52 }
53
54 protected function writeReal( MessageCollection $collection ) {
55 $collection->loadTranslations();
56
57 $header = "<!--\n";
58 $header .= $this->doHeader( $collection );
59 $header .= $this->doAuthors( $collection );
60 $header .= "-->\n";
61
62 $output = '';
63 $mangler = $this->group->getMangler();
64
66 foreach ( $collection as $key => $m ) {
67 $key = $mangler->unmangle( $key );
68 $trans = $m->translation();
69 $trans = str_replace( TRANSLATE_FUZZY, '', $trans );
70
71 if ( $trans === '' ) {
72 continue;
73 }
74
75 $trans = str_replace( '"', '&quot;', $trans );
76 $output .= "<!ENTITY $key \"$trans\">\n";
77 }
78
79 if ( $output ) {
80 return $header . $output;
81 }
82
83 return false;
84 }
85
86 protected function doHeader( MessageCollection $collection ) {
87 global $wgSitename;
88
89 $code = $collection->code;
90 $name = Utilities::getLanguageName( $code );
91 $native = Utilities::getLanguageName( $code, $code );
92
93 $output = "# Messages for $name ($native)\n";
94 $output .= "# Exported from $wgSitename\n\n";
95
96 return $output;
97 }
98
99 protected function doAuthors( MessageCollection $collection ) {
100 $output = '';
101 $authors = $collection->getAuthors();
102 $authors = $this->filterAuthors( $authors, $collection->code );
103
104 foreach ( $authors as $author ) {
105 $output .= "# Author: $author\n";
106 }
107
108 return $output;
109 }
110}
File format support for DTD.
Definition DtdFFS.php:21
writeReal(MessageCollection $collection)
Definition DtdFFS.php:54
readFromVariable( $data)
Definition DtdFFS.php:30
getFileExtensions()
Return the commonly used file extensions for these formats.
Definition DtdFFS.php:22
This file contains the class for core message collections implementation.
getAuthors()
Lists all translators that have contributed to the latest revisions of each translation.
Essentially random collection of helper functions, similar to GlobalFunctions.php.
Definition Utilities.php:30
filterAuthors(array $authors, $code)
Remove excluded authors.