load_plugin_textdomain

Loads a plugin's translated strings.

Description

load_plugin_textdomain( (string) $domain, (constant) $deprecated = false, (bool) $plugin_rel_path = false ); 

If the path is not given then it will be the root of the plugin directory.

The .mo file should be named based on the text domain with a dash, and then the locale exactly.

Parameters (3)

0. $domain (string)
Unique identifier for retrieving translated strings
1. $deprecated — Optional. (constant) => false
Use the $plugin_rel_path parameter instead. Default false.
2. $plugin_rel_path — Optional. (bool) => false
Relative path to WP_PLUGIN_DIR where the .mo file resides. Default false.

Usage

  1. if ( !function_exists( 'load_plugin_textdomain' ) ) { 
  2. require_once ABSPATH . WPINC . '/l10n.php'; 
  3.  
  4. // Unique identifier for retrieving translated strings 
  5. $domain = ''; 
  6.  
  7. // Optional. Use the $plugin_rel_path parameter instead. Default false. 
  8. $deprecated = false; 
  9.  
  10. // Optional. Relative path to WP_PLUGIN_DIR where the .mo file resides. 
  11. // Default false. 
  12. $plugin_rel_path = false; 
  13.  
  14. // NOTICE! Understand what this does before running. 
  15. $result = load_plugin_textdomain($domain, $deprecated, $plugin_rel_path); 
  16.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/l10n.php  
  1. function load_plugin_textdomain( $domain, $deprecated = false, $plugin_rel_path = false ) { 
  2. /** 
  3. * Filters a plugin's locale. 
  4. * @since 3.0.0 
  5. * @param string $locale The plugin's current locale. 
  6. * @param string $domain Text domain. Unique identifier for retrieving translated strings. 
  7. */ 
  8. $locale = apply_filters( 'plugin_locale', is_admin() ? get_user_locale() : get_locale(), $domain ); 
  9.  
  10. $mofile = $domain . '-' . $locale . '.mo'; 
  11.  
  12. // Try to load from the languages directory first. 
  13. if ( load_textdomain( $domain, WP_LANG_DIR . '/plugins/' . $mofile ) ) { 
  14. return true; 
  15.  
  16. if ( false !== $plugin_rel_path ) { 
  17. $path = WP_PLUGIN_DIR . '/' . trim( $plugin_rel_path, '/' ); 
  18. } elseif ( false !== $deprecated ) { 
  19. _deprecated_argument( __FUNCTION__, '2.7.0' ); 
  20. $path = ABSPATH . trim( $deprecated, '/' ); 
  21. } else { 
  22. $path = WP_PLUGIN_DIR
  23.  
  24. return load_textdomain( $domain, $path . '/' . $mofile );