AndroidXmlFFS.php
Go to the documentation of this file.00001 <?php
00015 class AndroidXmlFFS extends SimpleFFS {
00016 public function supportsFuzzy() {
00017 return 'yes';
00018 }
00019
00020 public function getFileExtensions() {
00021 return array( '.xml' );
00022 }
00023
00024 public function readFromVariable( $data ) {
00025 $reader = new SimpleXMLElement( $data );
00026
00027 $messages = array();
00028 $mangler = $this->group->getMangler();
00029
00030 foreach ( $reader->string as $string ) {
00031 $key = (string)$string['name'];
00032 $value = stripcslashes( (string)$string );
00033
00034 if ( isset( $string['fuzzy'] ) && (string)$string['fuzzy'] === 'true' ) {
00035 $value = TRANSLATE_FUZZY . $value;
00036 }
00037
00038 $messages[$key] = $value;
00039 }
00040
00041 return array(
00042 'AUTHORS' => array(),
00043 'MESSAGES' => $mangler->mangle( $messages ),
00044 );
00045 }
00046
00047 protected function writeReal( MessageCollection $collection ) {
00048 $template = <<<XML
00049 <?xml version="1.0" encoding="utf-8"?>
00050 <resources></resources>
00051 XML;
00052
00053 $writer = new SimpleXMLElement( $template );
00054 $mangler = $this->group->getMangler();
00055
00056 $collection->filter( 'hastranslation', false );
00057 if ( count( $collection ) === 0 ) {
00058 return '';
00059 }
00060
00064 foreach ( $collection as $key => $m ) {
00065 $key = $mangler->unmangle( $key );
00066
00067 $value = $m->translation();
00068 $value = str_replace( TRANSLATE_FUZZY, '', $value );
00069
00070
00071 $string = $writer->addChild( 'string', addcslashes( $value, '"\'' ) );
00072 $string->addAttribute( 'name', $key );
00073
00074
00075 if ( $m->hasTag( 'fuzzy' ) ) {
00076 $string->addAttribute( 'fuzzy', 'true' );
00077 }
00078 }
00079
00080
00081 $dom = new DOMDocument( '1.0' );
00082 $dom->formatOutput = true;
00083 $dom->loadXML( $writer->asXML() );
00084
00085 return $dom->saveXML();
00086 }
00087 }