Loads a translation file for a given text domain.
Parameters
$translation_file
stringrequired- Translation file.
$textdomain
stringoptional- Text domain. Default
'default'
.Default:
'default'
$locale
stringoptional- Locale. Default current locale.
Default:
null
Source
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;
}
Changelog
Version | Description |
---|---|
6.5.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.