exported = '';
$this->line( '' );
$this->line( '' );
$this->add_schema_info();
$this->add_schema_declaration();
$this->res_header( 'resmimetype', 'text/microsoft-resx' );
$this->res_header( 'version', '2.0' );
$this->res_header( 'reader', 'System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' );
$this->res_header( 'writer', 'System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' );
foreach( $entries as $entry ) {
if ( !preg_match( '/^[a-zA-Z0-9_]+$/', $entry->context ) ) {
error_log( 'ResX Export: Bad Entry: '. $entry->context );
continue;
}
if ( empty( $entry->translations ) || ! array_filter( $entry->translations ) )
continue;
$this->line( '', 1 );
$this->line( '' . $this->escape( $entry->translations[0] ) . '', 2 );
if ( isset( $entry->extracted_comments ) && $entry->extracted_comments ) {
$this->line( '' . $this->escape( $entry->extracted_comments ) . '', 2 );
}
$this->line( '', 1 );
}
$this->line( '' );
return $this->exported;
}
public function read_originals_from_file( $file_name ) {
$errors = libxml_use_internal_errors( true );
$data = simplexml_load_string( file_get_contents( $file_name ) );
libxml_use_internal_errors( $errors );
if ( ! is_object( $data ) ) {
return false;
}
$entries = new Translations;
foreach( $data->data as $string ) {
$entry = new Translation_Entry();
if ( isset( $string['type'] ) && gp_in( 'System.Resources.ResXFileRef', (string)$string['type'] ) ) {
continue;
}
$entry->context = (string)$string['name'];
$entry->singular = $this->unescape( (string)$string->value );
if ( isset( $string->comment ) && $string->comment ) {
$entry->extracted_comments = (string)$string->comment;
}
$entry->translations = array();
$entries->add_entry( $entry );
}
return $entries;
}
private function line( $string, $prepend_tabs = 0 ) {
$this->exported .= str_repeat( "\t", $prepend_tabs ) . "$string\n";
}
private function res_header( $name, $value ) {
$this->line( '', 1 );
$this->line( ''.$value.'', 2 );
$this->line( '', 1 );
}
private function unescape( $string ) {
return $string;
}
private function escape( $string ) {
$string = str_replace( array( '&', '<' ), array( '&', '<' ), $string );
return $string;
}
function add_schema_info() {
$this->line('', 1 );
}
function add_schema_declaration() {
$this->line( '', 1 );
$this->line( '', 2 );
$this->line( '', 2 );
$this->line( '', 3 );
$this->line( '', 4 );
$this->line( '', 5 );
$this->line( '', 6 );
$this->line( '', 7 );
$this->line( '', 8 );
$this->line( '', 7 );
$this->line( '', 7 );
$this->line( '', 7 );
$this->line( '', 7 );
$this->line( '', 7 );
$this->line( '', 6 );
$this->line( '', 5 );
$this->line( '', 5 );
$this->line( '', 6 );
$this->line( '', 7 );
$this->line( '', 7 );
$this->line( '', 6 );
$this->line( '', 5 );
$this->line( '', 5 );
$this->line( '', 6 );
$this->line( '', 7 );
$this->line( '', 8 );
$this->line( '', 8 );
$this->line( '', 7 );
$this->line( '', 7 );
$this->line( '', 7 );
$this->line( '', 7 );
$this->line( '', 7 );
$this->line( '', 6 );
$this->line( '', 5 );
$this->line( '', 5 );
$this->line( '', 6 );
$this->line( '', 7 );
$this->line( '', 8 );
$this->line( '', 7 );
$this->line( '', 7 );
$this->line( '', 6 );
$this->line( '', 5 );
$this->line( '', 4 );
$this->line( '', 3 );
$this->line( '', 2 );
$this->line( '', 1 );
}
}
GP::$formats['resx'] = new GP_Format_ResX;