Index: trunk/extensions/Translate/groups/Toolserver/ToolserverTextdomains.php |
— | — | @@ -29,119 +29,31 @@ |
30 | 30 | $this->path = "$wgTranslateGroupRoot/ToolserverI18N/language/messages/"; |
31 | 31 | } |
32 | 32 | |
33 | | - /// Initialisation function |
34 | | - public function init() { |
35 | | - if ( $this->groups !== null ) return; |
36 | | - |
37 | | - global $wgAutoloadClasses, $IP, $wgTranslateExtensionDirectory; |
38 | | - |
39 | | - $postfix = 'Configure/load_txt_def/TxtDef.php'; |
40 | | - if ( file_exists( "$IP/extensions/$postfix" ) ) { |
41 | | - $prefix = "$IP/extensions"; |
42 | | - } elseif( file_exists( "$wgTranslateExtensionDirectory/$postfix" ) ) { |
43 | | - $prefix = $wgTranslateExtensionDirectory; |
44 | | - } else { |
45 | | - $prefix = false; |
46 | | - } |
47 | | - |
48 | | - if ( $this->useConfigure && $prefix ) { |
49 | | - $wgAutoloadClasses['TxtDef'] = "$prefix/$postfix"; |
50 | | - $tmp = TxtDef::loadFromFile( "$prefix/Configure/settings/Settings-ext.txt" ); |
51 | | - $configureData = array_combine( array_map( array( __CLASS__, 'foldId' ), array_keys( $tmp ) ), array_values( $tmp ) ); |
52 | | - } else { |
53 | | - $configureData = array(); |
54 | | - } |
55 | | - |
56 | | - $defines = file_get_contents( $this->definitionFile ); |
57 | | - |
58 | | - $linefeed = '(\r\n|\n)'; |
59 | | - |
60 | | - $sections = array_map( 'trim', preg_split( "/$linefeed{2,}/", $defines, - 1, PREG_SPLIT_NO_EMPTY ) ); |
61 | | - |
62 | | - $groups = $fixedGroups = array(); |
63 | | - |
64 | | - foreach ( $sections as $section ) { |
65 | | - $lines = array_map( 'trim', preg_split( "/$linefeed/", $section ) ); |
66 | | - $newgroup = array(); |
67 | | - |
68 | | - foreach ( $lines as $line ) { |
69 | | - if ( $line === '' || $line[0] === '#' ) continue; |
70 | | - |
71 | | - if ( strpos( $line, '=' ) === false ) { |
72 | | - if ( empty( $newgroup['name'] ) ) { |
73 | | - $newgroup['name'] = $line; |
74 | | - } else { |
75 | | - throw new MWException( "Trying to define name twice: " . $line ); |
76 | | - } |
77 | | - } else { |
78 | | - list( $key, $value ) = array_map( 'trim', explode( '=', $line, 2 ) ); |
79 | | - switch ( $key ) { |
80 | | - case 'file': |
81 | | - case 'var': |
82 | | - case 'id': |
83 | | - case 'descmsg': |
84 | | - case 'desc': |
85 | | - case 'magicfile': |
86 | | - case 'aliasfile': |
87 | | - $newgroup[$key] = $value; |
88 | | - break; |
89 | | - case 'optional': |
90 | | - case 'ignored': |
91 | | - $values = array_map( 'trim', explode( ',', $value ) ); |
92 | | - if ( !isset( $newgroup[$key] ) ) { |
93 | | - $newgroup[$key] = array(); |
94 | | - } |
95 | | - $newgroup[$key] = array_merge( $newgroup[$key], $values ); |
96 | | - break; |
97 | | - case 'prefix': |
98 | | - list( $prefix, $messages ) = array_map( 'trim', explode( '|', $value, 2 ) ); |
99 | | - if ( isset( $newgroup['prefix'] ) && $newgroup['prefix'] !== $prefix ) { |
100 | | - throw new MWException( "Only one prefix supported: {$newgroup['prefix']} !== $prefix" ); |
101 | | - } |
102 | | - $newgroup['prefix'] = $prefix; |
103 | | - |
104 | | - if ( !isset( $newgroup['mangle'] ) ) $newgroup['mangle'] = array(); |
105 | | - |
106 | | - $messages = array_map( 'trim', explode( ',', $messages ) ); |
107 | | - $newgroup['mangle'] = array_merge( $newgroup['mangle'], $messages ); |
108 | | - break; |
109 | | - default: |
110 | | - throw new MWException( "Unknown key:" . $key ); |
111 | | - } |
112 | | - } |
113 | | - } |
114 | | - |
115 | | - if ( count( $newgroup ) ) { |
116 | | - if ( empty( $newgroup['name'] ) ) { |
117 | | - throw new MWException( "Name missing\n" . print_r( $newgroup, true ) ); |
118 | | - } |
119 | | - $groups[] = $newgroup; |
120 | | - } |
121 | | - } |
122 | | - |
123 | | - |
| 33 | + protected function processGroups( $groups ) { |
| 34 | + $configureData = $this->loadConfigureExtensionData(); |
| 35 | + $fixedGroups = array(); |
124 | 36 | foreach ( $groups as $g ) { |
125 | 37 | if ( !is_array( $g ) ) { |
126 | 38 | $g = array( $g ); |
127 | 39 | } |
128 | 40 | |
129 | 41 | $name = $g['name']; |
130 | | - $sanatizedName = preg_replace( '/\s+/', '', strtolower( $name ) ); |
| 42 | + $sanitizedName = preg_replace( '/\s+/', '', strtolower( $name ) ); |
131 | 43 | |
132 | 44 | if ( isset( $g['id'] ) ) { |
133 | 45 | $id = $g['id']; |
134 | 46 | } else { |
135 | | - $id = $this->idPrefix . $sanatizedName; |
| 47 | + $id = $this->idPrefix . $sanitizedName; |
136 | 48 | } |
137 | 49 | |
138 | 50 | if ( isset( $g['file'] ) ) { |
139 | 51 | $file = $g['file']; |
140 | 52 | } else { |
141 | | - // TsIntuition text-domains are case-insensitive and internally |
| 53 | + // Toolserver Intuition text-domains are case-insensitive and internally |
142 | 54 | // converts to lowercase names starting with a capital letter. |
143 | | - // eg. "My Tool" -> "Mytool.i18n.php" |
| 55 | + // eg. "MyTool" -> "Mytool.i18n.php" |
144 | 56 | // No subdirectories! |
145 | | - $file = ucfirst( $sanatizedName ) . '.i18n.php'; |
| 57 | + $file = ucfirst( $sanitizedName ) . '.i18n.php'; |
146 | 58 | } |
147 | 59 | |
148 | 60 | if ( isset( $g['descmsg'] ) ) { |
— | — | @@ -163,10 +75,11 @@ |
164 | 76 | 'url' => $url, |
165 | 77 | ); |
166 | 78 | |
167 | | - // Allow a custom prefix if needed |
| 79 | + // Prefix is required, if not customized use the sanitized name |
168 | 80 | if ( !isset( $g['prefix'] ) ) { |
169 | | - $g['prefix'] = "$sanatizedName-"; |
| 81 | + $g['prefix'] = "$sanitizedName-"; |
170 | 82 | } |
| 83 | + |
171 | 84 | // All messages are prefixed with their groupname |
172 | 85 | $g['mangle'] = array( '*' ); |
173 | 86 | |
— | — | @@ -184,7 +97,6 @@ |
185 | 98 | |
186 | 99 | $fixedGroups[$id] = $newgroup; |
187 | 100 | } |
188 | | - |
189 | | - $this->groups = $fixedGroups; |
| 101 | + return $fixedGroups; |
190 | 102 | } |
191 | 103 | } |
Index: trunk/extensions/Translate/groups/Toolserver/README |
— | — | @@ -3,7 +3,7 @@ |
4 | 4 | svn co http://svn.wikimedia.org/svnroot/mediawiki/trunk/tools/ToolserverI18N/ ToolserverI18N |
5 | 5 | |
6 | 6 | # Add following code to LocalSettings.php or a file included by it: |
7 | | -$wgHooks['TranslatePostInitGroups'] = array( 'setupToolserverI18N' ); |
| 7 | +$wgHooks['TranslatePostInitGroups'][] = array( 'setupToolserverI18N' ); |
8 | 8 | function setupToolserverI18N() { |
9 | 9 | $foo = new PremadeToolserverTextdomains(); |
10 | 10 | $foo->addAll(); |