Title: WP_Translation_Controller::unload_file
Published: April 3, 2024
Last modified: February 24, 2026

---

# WP_Translation_Controller::unload_file( WP_Translation_File|string $file, string $textdomain, string $locale = null ): bool

## In this article

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

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

Unloads a translation file for a given text domain.

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

 `$file`[WP_Translation_File](https://developer.wordpress.org/reference/classes/wp_translation_file/)
|stringrequired

Translation file instance or file name.

`$textdomain`stringoptional

Text domain. Default `'default'`.

`$locale`stringoptional

Locale. Defaults to all locales.

Default:`null`

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

 bool True on success, false otherwise.

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

    ```php
    public function unload_file( $file, string $textdomain = 'default', ?string $locale = null ): bool {
    	if ( is_string( $file ) ) {
    		$file = realpath( $file );
    	}

    	if ( null !== $locale ) {
    		if ( isset( $this->loaded_translations[ $locale ][ $textdomain ] ) ) {
    			foreach ( $this->loaded_translations[ $locale ][ $textdomain ] as $i => $moe ) {
    				if ( $file === $moe || $file === $moe->get_file() ) {
    					unset( $this->loaded_translations[ $locale ][ $textdomain ][ $i ] );
    					unset( $this->loaded_files[ $moe->get_file() ][ $locale ][ $textdomain ] );
    					return true;
    				}
    			}
    		}

    		return true;
    	}

    	foreach ( $this->loaded_translations as $l => $domains ) {
    		if ( ! isset( $domains[ $textdomain ] ) ) {
    			continue;
    		}

    		foreach ( $domains[ $textdomain ] as $i => $moe ) {
    			if ( $file === $moe || $file === $moe->get_file() ) {
    				unset( $this->loaded_translations[ $l ][ $textdomain ][ $i ] );
    				unset( $this->loaded_files[ $moe->get_file() ][ $l ][ $textdomain ] );
    				return true;
    			}
    		}
    	}

    	return false;
    }
    ```

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

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

| Used by | Description | 
| [WP_Translation_Controller::locate_translation()](https://developer.wordpress.org/reference/classes/wp_translation_controller/locate_translation/)`wp-includes/l10n/class-wp-translation-controller.php` |

Locates translation for a given string and text domain.

  |

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