Index: trunk/phase3/languages/Language.php |
— | — | @@ -465,12 +465,9 @@ |
466 | 466 | $names = array(); |
467 | 467 | $dir = opendir( "$IP/languages/messages" ); |
468 | 468 | while( false !== ( $file = readdir( $dir ) ) ) { |
469 | | - $m = array(); |
470 | | - if( preg_match( '/Messages([A-Z][a-z_]+)\.php$/', $file, $m ) ) { |
471 | | - $code = str_replace( '_', '-', strtolower( $m[1] ) ); |
472 | | - if ( isset( $allNames[$code] ) ) { |
473 | | - $names[$code] = $allNames[$code]; |
474 | | - } |
| 469 | + $code = self::getCodeFromFileName( $file, 'Messages' ); |
| 470 | + if ( $code && isset( $allNames[$code] ) ) { |
| 471 | + $names[$code] = $allNames[$code]; |
475 | 472 | } |
476 | 473 | } |
477 | 474 | closedir( $dir ); |
— | — | @@ -2492,9 +2489,33 @@ |
2493 | 2490 | $this->mCode = $code; |
2494 | 2491 | } |
2495 | 2492 | |
| 2493 | + /** |
| 2494 | + * Get the name of a file for a certain language code |
| 2495 | + * @param $prefix string Prepend this to the filename |
| 2496 | + * @param $code string Language code |
| 2497 | + * @param $suffix string Append this to the filename |
| 2498 | + * @return string $prefix . $mangledCode . $suffix |
| 2499 | + */ |
2496 | 2500 | static function getFileName( $prefix = 'Language', $code, $suffix = '.php' ) { |
2497 | 2501 | return $prefix . str_replace( '-', '_', ucfirst( $code ) ) . $suffix; |
2498 | 2502 | } |
| 2503 | + |
| 2504 | + /** |
| 2505 | + * Get the language code from a file name. Inverse of getFileName() |
| 2506 | + * @param $filename string $prefix . $languageCode . $suffix |
| 2507 | + * @param $prefix string Prefix before the language code |
| 2508 | + * @param $suffix string Suffix after the language code |
| 2509 | + * @return Language code, or false if $prefix or $suffix isn't found |
| 2510 | + */ |
| 2511 | + static function getCodeFromFileName( $filename, $prefix = 'Language', $suffix = '.php' ) { |
| 2512 | + $m = null; |
| 2513 | + preg_match( '/' . preg_quote( $prefix ) . '([A-Z][a-z_])' . |
| 2514 | + preg_quote( $suffix ) . '/', $filename, $m ); |
| 2515 | + if ( !count( $m ) ) { |
| 2516 | + return false; |
| 2517 | + } |
| 2518 | + return str_replace( '_', '-', strtolower( $m[1] ) ); |
| 2519 | + } |
2499 | 2520 | |
2500 | 2521 | static function getMessagesFileName( $code ) { |
2501 | 2522 | global $IP; |
Index: trunk/extensions/LocalisationUpdate/LocalisationUpdate.class.php |
— | — | @@ -190,9 +190,7 @@ |
191 | 191 | $base_messages = array(); |
192 | 192 | |
193 | 193 | // Get the languagecode |
194 | | - $m = array(); |
195 | | - preg_match( '/Messages([A-Z][a-z_]+)\.php$/', $basefile, $m ); |
196 | | - $langcode = str_replace( '_', '-', strtolower( $m[1] ) ); |
| 194 | + $langcode = Language::getCodeFromFileName( $basefile, 'Messages' ); |
197 | 195 | |
198 | 196 | $basefilecontents = self::getFileContents( $basefile ); |
199 | 197 | if ( $basefilecontents === false || $basefilecontents === "" ) return array(); // Failed |