load_textdomain

Load a .mo file into the text domain $domain.

Description

load_textdomain( (string) $domain, (string) $mofile ); 

If the text domain already exists, the translations will be merged. If both sets have the same string, the translation from the original value will be taken.

On success, the .mo file will be placed in the $l10n global by $domain and will be a MO object.

Parameters (2)

0. $domain (string)
Text domain. Unique identifier for retrieving translated strings.
1. $mofile (string)
Path to the .mo file.

Usage

  1. if ( !function_exists( 'load_textdomain' ) ) { 
  2. require_once ABSPATH . WPINC . '/l10n.php'; 
  3.  
  4. // Text domain. Unique identifier for retrieving translated strings. 
  5. $domain = ''; 
  6.  
  7. // Path to the .mo file. 
  8. $mofile = ''; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = load_textdomain($domain, $mofile); 
  12.  

Defined (1)

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

/wp-includes/l10n.php  
  1. function load_textdomain( $domain, $mofile ) { 
  2. global $l10n, $l10n_unloaded; 
  3.  
  4. $l10n_unloaded = (array) $l10n_unloaded; 
  5.  
  6. /** 
  7. * Filters whether to override the .mo file loading. 
  8. * @since 2.9.0 
  9. * @param bool $override Whether to override the .mo file loading. Default false. 
  10. * @param string $domain Text domain. Unique identifier for retrieving translated strings. 
  11. * @param string $mofile Path to the MO file. 
  12. */ 
  13. $plugin_override = apply_filters( 'override_load_textdomain', false, $domain, $mofile ); 
  14.  
  15. if ( true == $plugin_override ) { 
  16. unset( $l10n_unloaded[ $domain ] ); 
  17.  
  18. return true; 
  19.  
  20. /** 
  21. * Fires before the MO translation file is loaded. 
  22. * @since 2.9.0 
  23. * @param string $domain Text domain. Unique identifier for retrieving translated strings. 
  24. * @param string $mofile Path to the .mo file. 
  25. */ 
  26. do_action( 'load_textdomain', $domain, $mofile ); 
  27.  
  28. /** 
  29. * Filters MO file path for loadingtranslationsfor a specific text domain. 
  30. * @since 2.9.0 
  31. * @param string $mofile Path to the MO file. 
  32. * @param string $domain Text domain. Unique identifier for retrieving translated strings. 
  33. */ 
  34. $mofile = apply_filters( 'load_textdomain_mofile', $mofile, $domain ); 
  35.  
  36. if ( !is_readable( $mofile ) ) return false; 
  37.  
  38. $mo = new MO(); 
  39. if ( !$mo->import_from_file( $mofile ) ) return false; 
  40.  
  41. if ( isset( $l10n[$domain] ) ) 
  42. $mo->merge_with( $l10n[$domain] ); 
  43.  
  44. unset( $l10n_unloaded[ $domain ] ); 
  45.  
  46. $l10n[$domain] = &$mo; 
  47.  
  48. return true;