_get_path_to_translation_from_lang_dir

Gets the path to a translation file in the languages directory for the current locale.

Description

(string|false) _get_path_to_translation_from_lang_dir( (string) $domain ); 

Holds a cached list of available .mo files to improve performance.

Returns (string|false)

The path to the translation file or false if no translation file was found.

Parameters (1)

0. $domain (string)
Text domain. Unique identifier for retrieving translated strings.

Usage

  1. if ( !function_exists( '_get_path_to_translation_from_lang_dir' ) ) { 
  2. require_once ABSPATH . WPINC . '/l10n.php'; 
  3.  
  4. // Text domain. Unique identifier for retrieving translated strings. 
  5. $domain = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = _get_path_to_translation_from_lang_dir($domain); 
  9.  

Defined (1)

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

/wp-includes/l10n.php  
  1. function _get_path_to_translation_from_lang_dir( $domain ) { 
  2. static $cached_mofiles = null; 
  3.  
  4. if ( null === $cached_mofiles ) { 
  5. $cached_mofiles = array(); 
  6.  
  7. $locations = array( 
  8. WP_LANG_DIR . '/plugins',  
  9. WP_LANG_DIR . '/themes',  
  10. ); 
  11.  
  12. foreach ( $locations as $location ) { 
  13. $mofiles = glob( $location . '/*.mo' ); 
  14. if ( $mofiles ) { 
  15. $cached_mofiles = array_merge( $cached_mofiles, $mofiles ); 
  16.  
  17. $locale = is_admin() ? get_user_locale() : get_locale(); 
  18. $mofile = "{$domain}-{$locale}.mo"; 
  19.  
  20. $path = WP_LANG_DIR . '/plugins/' . $mofile; 
  21. if ( in_array( $path, $cached_mofiles ) ) { 
  22. return $path; 
  23.  
  24. $path = WP_LANG_DIR . '/themes/' . $mofile; 
  25. if ( in_array( $path, $cached_mofiles ) ) { 
  26. return $path; 
  27.  
  28. return false;