WP_Translation_Controller::load_file
Loads a translation file for a given text domain.
Method of the class: WP_Translation_Controller{}
No Hooks.
Returns
true|false. True on success, false otherwise.
Usage
$WP_Translation_Controller = new WP_Translation_Controller(); $WP_Translation_Controller->load_file( $translation_file, $textdomain, ?string $locale ): bool;
- $translation_file(string) (required)
- Translation file.
- $textdomain(string)
- Text domain.
Default: 'default' - ?string $locale
- .
Default: null
Changelog
| Since 6.5.0 | Introduced. |
WP_Translation_Controller::load_file() WP Translation Controller::load file code WP 6.9
public function load_file( string $translation_file, string $textdomain = 'default', ?string $locale = null ): bool {
if ( null === $locale ) {
$locale = $this->current_locale;
}
$translation_file = realpath( $translation_file );
if ( false === $translation_file ) {
return false;
}
if (
isset( $this->loaded_files[ $translation_file ][ $locale ][ $textdomain ] ) &&
false !== $this->loaded_files[ $translation_file ][ $locale ][ $textdomain ]
) {
return null === $this->loaded_files[ $translation_file ][ $locale ][ $textdomain ]->error();
}
if (
isset( $this->loaded_files[ $translation_file ][ $locale ] ) &&
array() !== $this->loaded_files[ $translation_file ][ $locale ]
) {
$moe = reset( $this->loaded_files[ $translation_file ][ $locale ] );
} else {
$moe = WP_Translation_File::create( $translation_file );
if ( false === $moe || null !== $moe->error() ) {
$moe = false;
}
}
$this->loaded_files[ $translation_file ][ $locale ][ $textdomain ] = $moe;
if ( ! $moe instanceof WP_Translation_File ) {
return false;
}
if ( ! isset( $this->loaded_translations[ $locale ][ $textdomain ] ) ) {
$this->loaded_translations[ $locale ][ $textdomain ] = array();
}
$this->loaded_translations[ $locale ][ $textdomain ][] = $moe;
return true;
}