Index: trunk/extensions/Translate/groups/OpenStreetMap/OpenStreetMap.yml |
— | — | @@ -19,6 +19,15 @@ |
20 | 20 | zh-cn: zh-CN |
21 | 21 | zh-tw: zh-TW |
22 | 22 | |
| 23 | +CHECKER: |
| 24 | + class: RubyMessageChecker |
| 25 | + checks: |
| 26 | + - RubyVariablesCheck |
| 27 | + |
| 28 | + |
| 29 | +AUTOLOAD: |
| 30 | + RubyMessageChecker: Checker.php |
| 31 | + |
23 | 32 | TAGS: |
24 | 33 | optional: |
25 | 34 | - browse.relation_member.entry |
Index: trunk/extensions/Translate/groups/OpenStreetMap/Checker.php |
— | — | @@ -0,0 +1,53 @@ |
| 2 | +<?php |
| 3 | + /** |
| 4 | + * @file |
| 5 | + * @copyright Copyright © 2009, Niklas Laxström |
| 6 | + * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later |
| 7 | + */ |
| 8 | +class RubyMessageChecker extends MessageChecker { |
| 9 | + |
| 10 | + /** |
| 11 | + * Checks for missing and unknown variables in translations. |
| 12 | + * |
| 13 | + * @param $messages Iterable list of TMessages. |
| 14 | + * @param $code Language code of the translations. |
| 15 | + * @param $warnings Array where warnings are appended to. |
| 16 | + */ |
| 17 | + protected function RubyVariablesCheck( $messages, $code, &$warnings ) { |
| 18 | + foreach( $messages as $message ) { |
| 19 | + $key = $message->key(); |
| 20 | + $definition = $message->definition(); |
| 21 | + $translation = $message->translation(); |
| 22 | + |
| 23 | + $varPattern = '\{\{(?!PLURAL).+\}\}|\[\[.+\]\]'; |
| 24 | + preg_match_all( "/$varPattern/U", $definition, $defVars ); |
| 25 | + preg_match_all( "/$varPattern/U", $translation, $transVars ); |
| 26 | + |
| 27 | + var_dump( $varPattern ); |
| 28 | + var_dump( $defVars ); |
| 29 | + # Check for missing variables in the translation |
| 30 | + $subcheck = 'missing'; |
| 31 | + $params = self::compareArrays( $defVars[0], $transVars[0] ); |
| 32 | + if ( count($params) ) { |
| 33 | + $warnings[$key][] = array( |
| 34 | + array( 'parameters', $subcheck, $key, $code ), |
| 35 | + 'translate-checks-parameters', |
| 36 | + array( 'PARAMS', $params ), |
| 37 | + array( 'COUNT', count($params) ), |
| 38 | + ); |
| 39 | + } |
| 40 | + |
| 41 | + # Check for unknown variables in the translation |
| 42 | + $subcheck = 'unknown'; |
| 43 | + $params = self::compareArrays( $transVars[0], $defVars[0] ); |
| 44 | + if ( count($params) ) { |
| 45 | + $warnings[$key][] = array( |
| 46 | + array( 'parameters', $subcheck, $key, $code ), |
| 47 | + 'translate-checks-parameters-unknown', |
| 48 | + array( 'PARAMS', $params ), |
| 49 | + array( 'COUNT', count($params) ), |
| 50 | + ); |
| 51 | + } |
| 52 | + } |
| 53 | + } |
| 54 | +} |
Property changes on: trunk/extensions/Translate/groups/OpenStreetMap/Checker.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 55 | + native |