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' ); $this->res_header( 'translation_revision_date', GP::$translation->last_modified( $translation_set ) . '+0000' ); $this->res_header( 'plural_forms', "nplurals={$locale->nplurals}; plural={$locale->plural_expression};" ); $this->res_header( 'generator', 'GlotPress/' . GP_VERSION ); $language_code = $this->get_language_code( $locale ); if ( false !== $language_code ) { $this->res_header( 'language', $language_code ); } foreach ( $entries as $entry ) { if ( empty( $entry->translations ) || ! array_filter( $entry->translations ) ) { continue; } if ( empty( $entry->context ) ) { $entry->context = $entry->singular; } $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; } private function add_schema_info() { $this->line( '', 1 ); } private 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();