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

In this article

Creates a new WP_Translation_File instance for a given file.

Parameters

$filestringrequired
Source file name.
$filetypestringrequired
Desired target file type.

Return

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

Source

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();
}

Changelog

VersionDescription
6.5.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.