wp_load_translations_early

Attempt an early load of translations.

Description

wp_load_translations_early(); 

Used for errors encountered during the initial loading process, before the locale has been properly detected and loaded.

Designed for unusual load sequences (like setup-config.php) or for when the script will then terminate with an error, otherwise there is a risk that a file can be double-included.


Usage

  1. if ( !function_exists( 'wp_load_translations_early' ) ) { 
  2. require_once ABSPATH . WPINC . '/load.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = wp_load_translations_early(); 
  7.  

Defined (1)

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

/wp-includes/load.php  
  1. function wp_load_translations_early() { 
  2. global $wp_locale; 
  3.  
  4. static $loaded = false; 
  5. if ( $loaded ) 
  6. return; 
  7. $loaded = true; 
  8.  
  9. if ( function_exists( 'did_action' ) && did_action( 'init' ) ) 
  10. return; 
  11.  
  12. // We need $wp_local_package 
  13. require ABSPATH . WPINC . '/version.php'; 
  14.  
  15. // Translation and localization 
  16. require_once ABSPATH . WPINC . '/pomo/mo.php'; 
  17. require_once ABSPATH . WPINC . '/l10n.php'; 
  18. require_once ABSPATH . WPINC . '/class-wp-locale.php'; 
  19. require_once ABSPATH . WPINC . '/class-wp-locale-switcher.php'; 
  20.  
  21. // General libraries 
  22. require_once ABSPATH . WPINC . '/plugin.php'; 
  23.  
  24. $locales = $locations = array(); 
  25.  
  26. while ( true ) { 
  27. if ( defined( 'WPLANG' ) ) { 
  28. if ( '' == WPLANG ) 
  29. break; 
  30. $locales[] = WPLANG; 
  31.  
  32. if ( isset( $wp_local_package ) ) 
  33. $locales[] = $wp_local_package; 
  34.  
  35. if ( ! $locales ) 
  36. break; 
  37.  
  38. if ( defined( 'WP_LANG_DIR' ) && @is_dir( WP_LANG_DIR ) ) 
  39. $locations[] = WP_LANG_DIR
  40.  
  41. if ( defined( 'WP_CONTENT_DIR' ) && @is_dir( WP_CONTENT_DIR . '/languages' ) ) 
  42. $locations[] = WP_CONTENT_DIR . '/languages'; 
  43.  
  44. if ( @is_dir( ABSPATH . 'wp-content/languages' ) ) 
  45. $locations[] = ABSPATH . 'wp-content/languages'; 
  46.  
  47. if ( @is_dir( ABSPATH . WPINC . '/languages' ) ) 
  48. $locations[] = ABSPATH . WPINC . '/languages'; 
  49.  
  50. if ( ! $locations ) 
  51. break; 
  52.  
  53. $locations = array_unique( $locations ); 
  54.  
  55. foreach ( $locales as $locale ) { 
  56. foreach ( $locations as $location ) { 
  57. if ( file_exists( $location . '/' . $locale . '.mo' ) ) { 
  58. load_textdomain( 'default', $location . '/' . $locale . '.mo' ); 
  59. if ( defined( 'WP_SETUP_CONFIG' ) && file_exists( $location . '/admin-' . $locale . '.mo' ) ) 
  60. load_textdomain( 'default', $location . '/admin-' . $locale . '.mo' ); 
  61. break 2; 
  62.  
  63. break; 
  64.  
  65. $wp_locale = new WP_Locale();