wpseek.com
Bazujące na WordPress narzędzie wyszukiwania dla deweloperów i twórców motywów.



get_available_languages › WordPress Function

Od3.0.0
Przestarzałyn/a
get_available_languages ( $dir = null )
Parametry:
  • (string) $dir A directory to search for language files. Default WP_LANG_DIR.
    Wymagane: Nie
    Domyślny: null
Powrót:
  • (string[]) An array of language codes or an empty array if no languages are present. Language codes are formed by stripping the file extension from the language file names.
Zdefiniowane na:
Codex:
Dziennik zmian:
  • 4.7.0
  • 6.5.0

Gets all available languages based on the presence of *.mo and *.l10n.php files in a given directory.

The default directory is WP_LANG_DIR.


Źródło

function get_available_languages( $dir = null ) {
	global $wp_textdomain_registry;

	$languages = array();

	$path       = is_null( $dir ) ? WP_LANG_DIR : $dir;
	$lang_files = $wp_textdomain_registry->get_language_files_from_path( $path );

	if ( $lang_files ) {
		foreach ( $lang_files as $lang_file ) {
			$lang_file = basename( $lang_file, '.mo' );
			$lang_file = basename( $lang_file, '.l10n.php' );

			if ( ! str_starts_with( $lang_file, 'continents-cities' ) && ! str_starts_with( $lang_file, 'ms-' ) &&
				! str_starts_with( $lang_file, 'admin-' ) ) {
				$languages[] = $lang_file;
			}
		}
	}

	/**
	 * Filters the list of available language codes.
	 *
	 * @since 4.7.0
	 *
	 * @param string[] $languages An array of available language codes.
	 * @param string   $dir       The directory where the language files were found.
	 */
	return apply_filters( 'get_available_languages', array_unique( $languages ), $dir );
}