Index: trunk/extensions/Translate/groups/Okawix/Okawix-dtd.php |
— | — | @@ -1,100 +0,0 @@ |
2 | | -<?php |
3 | | -/** |
4 | | - * Implements FFS for Okawix DTD file format. |
5 | | - * |
6 | | - * @file |
7 | | - * @author Guillaume Duhamel |
8 | | - * @author Niklas Laxström |
9 | | - * @author Siebrand Mazeland |
10 | | - * @copyright Copyright © 2009, Guillaume Duhamel |
11 | | - * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later |
12 | | - */ |
13 | | - |
14 | | -/** |
15 | | - * File format support for Okawix DTD. |
16 | | - * |
17 | | - * @ingroup FFS |
18 | | - */ |
19 | | -class OkawixDtdFFS extends SimpleFFS { |
20 | | - public function readFromVariable( $data ) { |
21 | | - preg_match_all( ',AUTHOR: ([^\n]+)\n,', $data, $matches ); |
22 | | - $authors = array(); |
23 | | - |
24 | | - for ( $i = 0; $i < count( $matches[1] ); $i++ ) { |
25 | | - $authors[] = $matches[1][$i]; |
26 | | - } |
27 | | - |
28 | | - preg_match_all( ',<!ENTITY[ ]+([^ ]+)[ ]+"([^"]+)"[^>]*>,', $data, $matches ); |
29 | | - |
30 | | - $keys = $matches[1]; |
31 | | - $values = $matches[2]; |
32 | | - |
33 | | - $messages = array(); |
34 | | - |
35 | | - for ( $i = 0; $i < count( $matches[1] ); $i++ ) { |
36 | | - $messages[$keys[$i]] = str_replace( |
37 | | - array( '"', '"', ''' ), |
38 | | - array( '"', '"', "'" ), |
39 | | - $values[$i] ); |
40 | | - } |
41 | | - |
42 | | - $messages = $this->group->getMangler()->mangle( $messages ); |
43 | | - |
44 | | - return array( |
45 | | - 'AUTHORS' => $authors, |
46 | | - 'MESSAGES' => $messages, |
47 | | - ); |
48 | | - } |
49 | | - |
50 | | - protected function writeReal( MessageCollection $collection ) { |
51 | | - $collection->loadTranslations(); |
52 | | - |
53 | | - $header = "<!--\n"; |
54 | | - $header .= $this->doHeader( $collection ); |
55 | | - $header .= $this->doAuthors( $collection ); |
56 | | - $header .= "-->\n"; |
57 | | - |
58 | | - $output = ''; |
59 | | - $mangler = $this->group->getMangler(); |
60 | | - |
61 | | - foreach ( $collection as $key => $m ) { |
62 | | - $key = $mangler->unmangle( $key ); |
63 | | - $trans = $m->translation(); |
64 | | - $trans = str_replace( TRANSLATE_FUZZY, '', $trans ); |
65 | | - |
66 | | - if ( $trans === '' ) { |
67 | | - continue; |
68 | | - } |
69 | | - |
70 | | - $trans = str_replace( '"', '"', $trans ); |
71 | | - $output .= "<!ENTITY $key \"$trans\">\n"; |
72 | | - } |
73 | | - |
74 | | - return $output ? $header . $output : false; |
75 | | - } |
76 | | - |
77 | | - protected function doHeader( MessageCollection $collection ) { |
78 | | - global $wgSitename; |
79 | | - |
80 | | - $code = $collection->code; |
81 | | - $name = TranslateUtils::getLanguageName( $code ); |
82 | | - $native = TranslateUtils::getLanguageName( $code, true ); |
83 | | - |
84 | | - $output = "# Messages for $name ($native)\n"; |
85 | | - $output .= "# Exported from $wgSitename\n\n"; |
86 | | - |
87 | | - return $output; |
88 | | - } |
89 | | - |
90 | | - protected function doAuthors( MessageCollection $collection ) { |
91 | | - $output = ''; |
92 | | - $authors = $collection->getAuthors(); |
93 | | - $authors = $this->filterAuthors( $authors, $collection->code ); |
94 | | - |
95 | | - foreach ( $authors as $author ) { |
96 | | - $output .= "# Author: $author\n"; |
97 | | - } |
98 | | - |
99 | | - return $output; |
100 | | - } |
101 | | -} |
Index: trunk/extensions/Translate/groups/Okawix/Okawix.yml |
— | — | @@ -43,7 +43,7 @@ |
44 | 44 | display: out/okawix/dtd |
45 | 45 | |
46 | 46 | FILES: |
47 | | - class: OkawixDtdFFS |
| 47 | + class: DtdFFS |
48 | 48 | sourcePattern: %GROUPROOT%/okawix/locale/%CODE%/interfacewiki/okawix.dtd |
49 | 49 | targetPattern: okawix/%CODE%/interfacewiki/okawix.dtd |
50 | 50 | |
Index: trunk/extensions/Translate/_autoload.php |
— | — | @@ -168,6 +168,7 @@ |
169 | 169 | $wgAutoloadClasses['ShapadoJsFFS'] = $dir . 'FFS.php'; |
170 | 170 | $wgAutoloadClasses['GettextFFS'] = $dir . '/ffs/Gettext.php'; |
171 | 171 | $wgAutoloadClasses['FlatPhpFFS'] = $dir . 'ffs/PhpVariables.php'; |
| 172 | +$wgAutoloadClasses['DtdFFS'] = $dir . 'ffs/DTD.php'; |
172 | 173 | /**@}*/ |
173 | 174 | |
174 | 175 | /** |
Index: trunk/extensions/Translate/ffs/DTD.php |
— | — | @@ -0,0 +1,100 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Implements FFS for DTD file format. |
| 5 | + * |
| 6 | + * @file |
| 7 | + * @author Guillaume Duhamel |
| 8 | + * @author Niklas Laxström |
| 9 | + * @author Siebrand Mazeland |
| 10 | + * @copyright Copyright © 2009-2010, Guillaume Duhamel, Niklas Laxström, Siebrand Mazeland |
| 11 | + * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later |
| 12 | + */ |
| 13 | + |
| 14 | +/** |
| 15 | + * File format support for DTD. |
| 16 | + * |
| 17 | + * @ingroup FFS |
| 18 | + */ |
| 19 | +class DtdFFS extends SimpleFFS { |
| 20 | + public function readFromVariable( $data ) { |
| 21 | + preg_match_all( ',AUTHOR: ([^\n]+)\n,', $data, $matches ); |
| 22 | + $authors = array(); |
| 23 | + |
| 24 | + for ( $i = 0; $i < count( $matches[1] ); $i++ ) { |
| 25 | + $authors[] = $matches[1][$i]; |
| 26 | + } |
| 27 | + |
| 28 | + preg_match_all( ',<!ENTITY[ ]+([^ ]+)[ ]+"([^"]+)"[^>]*>,', $data, $matches ); |
| 29 | + |
| 30 | + $keys = $matches[1]; |
| 31 | + $values = $matches[2]; |
| 32 | + |
| 33 | + $messages = array(); |
| 34 | + |
| 35 | + for ( $i = 0; $i < count( $matches[1] ); $i++ ) { |
| 36 | + $messages[$keys[$i]] = str_replace( |
| 37 | + array( '"', '"', ''' ), |
| 38 | + array( '"', '"', "'" ), |
| 39 | + $values[$i] ); |
| 40 | + } |
| 41 | + |
| 42 | + $messages = $this->group->getMangler()->mangle( $messages ); |
| 43 | + |
| 44 | + return array( |
| 45 | + 'AUTHORS' => $authors, |
| 46 | + 'MESSAGES' => $messages, |
| 47 | + ); |
| 48 | + } |
| 49 | + |
| 50 | + protected function writeReal( MessageCollection $collection ) { |
| 51 | + $collection->loadTranslations(); |
| 52 | + |
| 53 | + $header = "<!--\n"; |
| 54 | + $header .= $this->doHeader( $collection ); |
| 55 | + $header .= $this->doAuthors( $collection ); |
| 56 | + $header .= "-->\n"; |
| 57 | + |
| 58 | + $output = ''; |
| 59 | + $mangler = $this->group->getMangler(); |
| 60 | + |
| 61 | + foreach ( $collection as $key => $m ) { |
| 62 | + $key = $mangler->unmangle( $key ); |
| 63 | + $trans = $m->translation(); |
| 64 | + $trans = str_replace( TRANSLATE_FUZZY, '', $trans ); |
| 65 | + |
| 66 | + if ( $trans === '' ) { |
| 67 | + continue; |
| 68 | + } |
| 69 | + |
| 70 | + $trans = str_replace( '"', '"', $trans ); |
| 71 | + $output .= "<!ENTITY $key \"$trans\">\n"; |
| 72 | + } |
| 73 | + |
| 74 | + return $output ? $header . $output : false; |
| 75 | + } |
| 76 | + |
| 77 | + protected function doHeader( MessageCollection $collection ) { |
| 78 | + global $wgSitename; |
| 79 | + |
| 80 | + $code = $collection->code; |
| 81 | + $name = TranslateUtils::getLanguageName( $code ); |
| 82 | + $native = TranslateUtils::getLanguageName( $code, true ); |
| 83 | + |
| 84 | + $output = "# Messages for $name ($native)\n"; |
| 85 | + $output .= "# Exported from $wgSitename\n\n"; |
| 86 | + |
| 87 | + return $output; |
| 88 | + } |
| 89 | + |
| 90 | + protected function doAuthors( MessageCollection $collection ) { |
| 91 | + $output = ''; |
| 92 | + $authors = $collection->getAuthors(); |
| 93 | + $authors = $this->filterAuthors( $authors, $collection->code ); |
| 94 | + |
| 95 | + foreach ( $authors as $author ) { |
| 96 | + $output .= "# Author: $author\n"; |
| 97 | + } |
| 98 | + |
| 99 | + return $output; |
| 100 | + } |
| 101 | +} |
Property changes on: trunk/extensions/Translate/ffs/DTD.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 102 | + native |