| | 1 | <?php |
| | 2 | |
| | 3 | class GP_Format_MO { |
| | 4 | |
| | 5 | var $extension = 'mo'; |
| | 6 | |
| | 7 | function print_exported_file( $project, $locale, $translation_set, $entries ) { |
| | 8 | $mo = new MO(); |
| | 9 | // TODO: add more meta data in the project: language team, report URL |
| | 10 | // TODO: last updated for a translation set |
| | 11 | $mo->set_header( 'PO-Revision-Date', gmdate( 'Y-m-d H:i:s+0000' ) ); |
| | 12 | $mo->set_header( 'MIME-Version', '1.0' ); |
| | 13 | $mo->set_header( 'Content-Type', 'text/plain; charset=UTF-8' ); |
| | 14 | $mo->set_header( 'Content-Transfer-Encoding', '8bit' ); |
| | 15 | $mo->set_header( 'Plural-Forms', "nplurals=$locale->nplurals; plural=$locale->plural_expression;" ); |
| | 16 | $mo->set_header( 'X-Generator', 'GlotPress/' . gp_get_option('version') ); |
| | 17 | |
| | 18 | // force export only current translations |
| | 19 | $filters['status'] = 'current'; |
| | 20 | |
| | 21 | foreach( $entries as $entry ) { |
| | 22 | $mo->add_entry( $entry ); |
| | 23 | } |
| | 24 | $mo->set_header( 'Project-Id-Version', $project->name ); |
| | 25 | |
| | 26 | $temp_file = tempnam( sys_get_temp_dir(), 'GlotPress-MO' ); |
| | 27 | |
| | 28 | $mo->export_to_file( $temp_file ); |
| | 29 | |
| | 30 | echo file_get_contents( $temp_file ); |
| | 31 | |
| | 32 | unlink( $temp_file ); |
| | 33 | } |
| | 34 | |
| | 35 | function read_translations_from_file( $file_name, $project = null ) { |
| | 36 | $mo = new MO(); |
| | 37 | $result = $mo->import_from_file( $file_name ); |
| | 38 | return $result ? $mo : $result; |
| | 39 | } |
| | 40 | |
| | 41 | function read_originals_from_file( $file_name ) { |
| | 42 | return $this->read_translations_from_file( $file_name ); |
| | 43 | } |
| | 44 | |
| | 45 | } |
| | 46 | |
| | 47 | GP::$formats['mo'] = new GP_Format_MO; |
| | 48 | No newline at end of file |