WP_Translation_Controller
- Since
- 6.5.0
- Source
wp-includes/l10n/class-wp-translation-controller.php:15
Class WP_Translation_Controller.
Compatibility
- WordPress
- since 6.5.0
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0).
Properties · 4
$current_localestringprotected- Current locale.
$loaded_translationsarray<string,protected- Map of loaded translations per locale and text domain.
$loaded_filesarray<string,protected- List of loaded translation files.
$instanceWP_Translation_Controller|nullprivate static- Container for the main instance of the class.
Methods · 15
- get_instance()Utility method to retrieve the main instance of the class.
- get_locale()Returns the current locale.
- set_locale()Sets the current locale.
- load_file()Loads a translation file for a given text domain.
- unload_file()Unloads a translation file for a given text domain.
- unload_textdomain()Unloads all translation files for a given text domain.
- is_textdomain_loaded()Determines whether translations are loaded for a given text domain.
- translate()Translates a singular string.
- translate_plural()Translates plurals.
- get_headers()Returns all existing headers for a given text domain.
- normalize_header()Normalizes header names to be capitalized.
- get_entries()Returns all entries for a given text domain.
- locate_translation()Locates translation for a given string and text domain.
- get_files()Returns all translation files for a given text domain.
- has_translation()Returns a boolean to indicate whether a translation exists for a given string with optional text domain and locale.
Source code
final class WP_Translation_Controller { /** * Current locale. * * @since 6.5.0 * @var string */ protected $current_locale = 'en_US'; /** * Map of loaded translations per locale and text domain. * * [ Locale => [ Textdomain => [ ..., ... ] ] ] * * @since 6.5.0 * @var array<string, array<string, WP_Translation_File[]>> */ protected $loaded_translations = array(); /** * List of loaded translation files. * * [ Filename => [ Locale => [ Textdomain => WP_Translation_File ] ] ] * * @since 6.5.0 * @var array<string, array<string, array<string, WP_Translation_File|false>>> */ protected $loaded_files = array(); /** * Container for the main instance of the class. * * @since 6.5.0 * @var WP_Translation_Controller|null */ private static $instance = null; /** * Utility method to retrieve the main instance of the class. * * The instance will be created if it does not exist yet. * * @since 6.5.0 * * @return WP_Translation_Controller */ public static function get_instance(): WP_Translation_Controller { if ( null === self::$instance ) { self::$instance = new self(); } return self::$instance; } /** * Returns the current locale. * * @since 6.5.0 * * @return string Locale. */ public function get_locale(): string { return $this->current_locale; } /** * Sets the current locale. * * @since 6.5.0 * * @param string $locale Locale. */ public function set_locale( string $locale ) { $this->current_locale = $locale; } /** * Loads a translation file for a given text domain. * * @since 6.5.0Changelog
Introduced in 6.5.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-includes/l10n/class-wp-translation-controller.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.