Title: WP_Translation_File::transform
Published: April 3, 2024
Last modified: May 20, 2026

---

# WP_Translation_File::transform( string $file, string $filetype ): string|false

## In this article

 * [Parameters](https://developer.wordpress.org/reference/classes/wp_translation_file/transform/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/classes/wp_translation_file/transform/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/classes/wp_translation_file/transform/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/classes/wp_translation_file/transform/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/classes/wp_translation_file/transform/?output_format=md#changelog)

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

Creates a new [WP_Translation_File](https://developer.wordpress.org/reference/classes/wp_translation_file/)
instance for a given file.

## 󠀁[Parameters](https://developer.wordpress.org/reference/classes/wp_translation_file/transform/?output_format=md#parameters)󠁿

 `$file`stringrequired

Source file name.

`$filetype`stringrequired

Desired target file type.

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

 string|false Transformed translation file contents on success, false otherwise.

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

    ```php
    public static function transform( string $file, string $filetype ) {
    	$source = self::create( $file );

    	if ( false === $source ) {
    		return false;
    	}

    	switch ( $filetype ) {
    		case 'mo':
    			$destination = new WP_Translation_File_MO( '' );
    			break;
    		case 'php':
    			$destination = new WP_Translation_File_PHP( '' );
    			break;
    		default:
    			return false;
    	}

    	$success = $destination->import( $source );

    	if ( ! $success ) {
    		return false;
    	}

    	return $destination->export();
    }
    ```

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

## 󠀁[Related](https://developer.wordpress.org/reference/classes/wp_translation_file/transform/?output_format=md#related)󠁿

| Uses | Description | 
| [WP_Translation_File::create()](https://developer.wordpress.org/reference/classes/wp_translation_file/create/)`wp-includes/l10n/class-wp-translation-file.php` |

Creates a new [WP_Translation_File](https://developer.wordpress.org/reference/classes/wp_translation_file/) instance for a given file.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/classes/wp_translation_file/transform/?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%2Ftransform%2F)
before being able to contribute a note or feedback.