Title: WP_Translation_File_MO::export
Published: April 3, 2024
Last modified: May 20, 2026

---

# WP_Translation_File_MO::export(): string

## In this article

 * [Return](https://developer.wordpress.org/reference/classes/wp_translation_file_mo/export/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/classes/wp_translation_file_mo/export/?output_format=md#source)
 * [Changelog](https://developer.wordpress.org/reference/classes/wp_translation_file_mo/export/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/classes/wp_translation_file_mo/export/?output_format=md#wp--skip-link--target)

Exports translation contents as a string.

## 󠀁[Return](https://developer.wordpress.org/reference/classes/wp_translation_file_mo/export/?output_format=md#return)󠁿

 string Translation file contents.

## 󠀁[Source](https://developer.wordpress.org/reference/classes/wp_translation_file_mo/export/?output_format=md#source)󠁿

    ```php
    public function export(): string {
    	// Prefix the headers as the first key.
    	$headers_string = '';
    	foreach ( $this->headers as $header => $value ) {
    		$headers_string .= "{$header}: $value\n";
    	}
    	$entries     = array_merge( array( '' => $headers_string ), $this->entries );
    	$entry_count = count( $entries );

    	if ( false === $this->uint32 ) {
    		$this->uint32 = 'V';
    	}

    	$bytes_for_entries = $entry_count * 4 * 2;
    	// Pair of 32bit ints per entry.
    	$originals_addr    = 28; /* header */
    	$translations_addr = $originals_addr + $bytes_for_entries;
    	$hash_addr         = $translations_addr + $bytes_for_entries;
    	$entry_offsets     = $hash_addr;

    	$file_header = pack(
    		$this->uint32 . '*',
    		// Force cast to an integer as it can be a float on x86 systems. See https://core.trac.wordpress.org/ticket/60678.
    		(int) self::MAGIC_MARKER,
    		0, /* rev */
    		$entry_count,
    		$originals_addr,
    		$translations_addr,
    		0, /* hash_length */
    		$hash_addr
    	);

    	$o_entries = '';
    	$t_entries = '';
    	$o_addr    = '';
    	$t_addr    = '';

    	foreach ( array_keys( $entries ) as $original ) {
    		$o_addr        .= pack( $this->uint32 . '*', strlen( $original ), $entry_offsets );
    		$entry_offsets += strlen( $original ) + 1;
    		$o_entries     .= $original . "\0";
    	}

    	foreach ( $entries as $translations ) {
    		$t_addr        .= pack( $this->uint32 . '*', strlen( $translations ), $entry_offsets );
    		$entry_offsets += strlen( $translations ) + 1;
    		$t_entries     .= $translations . "\0";
    	}

    	return $file_header . $o_addr . $t_addr . $o_entries . $t_entries;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/l10n/class-wp-translation-file-mo.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.0/src/wp-includes/l10n/class-wp-translation-file-mo.php#L188)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-includes/l10n/class-wp-translation-file-mo.php#L188-L238)

## 󠀁[Changelog](https://developer.wordpress.org/reference/classes/wp_translation_file_mo/export/?output_format=md#changelog)󠁿

| Version | Description | 
| [6.5.0](https://developer.wordpress.org/reference/since/6.5.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_translation_file_mo%2Fexport%2F)
before being able to contribute a note or feedback.