A WordPress-centric search engine for devs and theme authors



_get_path_to_translation_from_lang_dir ›

Since4.7.0
Deprecatedn/a
_get_path_to_translation_from_lang_dir ( $domain )
Access:
  • private
Parameters:
  • (string) $domain Text domain. Unique identifier for retrieving translated strings.
    Required: Yes
See:
Returns:
  • (string|false) The path to the translation file or false if no translation file was found.
Defined at:
Codex:

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

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



Source

function _get_path_to_translation_from_lang_dir( $domain ) {
	static $cached_mofiles = null;

	if ( null === $cached_mofiles ) {
		$cached_mofiles = array();

		$locations = array(
			WP_LANG_DIR . '/plugins',
			WP_LANG_DIR . '/themes',
		);

		foreach ( $locations as $location ) {
			$mofiles = glob( $location . '/*.mo' );
			if ( $mofiles ) {
				$cached_mofiles = array_merge( $cached_mofiles, $mofiles );
			}
		}
	}

	$locale = is_admin() ? get_user_locale() : get_locale();
	$mofile = "{$domain}-{$locale}.mo";

	$path = WP_LANG_DIR . '/plugins/' . $mofile;
	if ( in_array( $path, $cached_mofiles ) ) {
		return $path;
	}

	$path = WP_LANG_DIR . '/themes/' . $mofile;
	if ( in_array( $path, $cached_mofiles ) ) {
		return $path;
	}

	return false;
}