wp_get_installed_translations

The timeline below displays how wordpress function wp_get_installed_translations has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.3

/**
 * Gets installed translations.
 *
 * Looks in the wp-content/languages directory for translations of
 * plugins or themes.
 *
 * @since 3.7.0
 *
 * @param string $type What to search for. Accepts 'plugins', 'themes', 'core'.
 * @return array Array of language data.
 */
function wp_get_installed_translations($type)
{
    if ('themes' !== $type && 'plugins' !== $type && 'core' !== $type) {
        return array();
    }
    $dir = ('core' === $type) ? '' : "/{$type}";
    if (!is_dir(WP_LANG_DIR)) {
        return array();
    }
    if ($dir && !is_dir(WP_LANG_DIR . $dir)) {
        return array();
    }
    $files = scandir(WP_LANG_DIR . $dir);
    if (!$files) {
        return array();
    }
    $language_data = array();
    foreach ($files as $file) {
        if ('.' === $file[0] || is_dir(WP_LANG_DIR . "{$dir}/{$file}")) {
            continue;
        }
        if (!str_ends_with($file, '.po')) {
            continue;
        }
        if (!preg_match('/(?:(.+)-)?([a-z]{2,3}(?:_[A-Z]{2})?(?:_[a-z0-9]+)?).po/', $file, $match)) {
            continue;
        }
        if (!in_array(substr($file, 0, -3) . '.mo', $files, true)) {
            continue;
        }
        list(, $textdomain, $language) = $match;
        if ('' === $textdomain) {
            $textdomain = 'default';
        }
        $language_data[$textdomain][$language] = wp_get_pomo_file_data(WP_LANG_DIR . "{$dir}/{$file}");
    }
    return $language_data;
}

WordPress Version: 6.1

/**
 * Gets installed translations.
 *
 * Looks in the wp-content/languages directory for translations of
 * plugins or themes.
 *
 * @since 3.7.0
 *
 * @param string $type What to search for. Accepts 'plugins', 'themes', 'core'.
 * @return array Array of language data.
 */
function wp_get_installed_translations($type)
{
    if ('themes' !== $type && 'plugins' !== $type && 'core' !== $type) {
        return array();
    }
    $dir = ('core' === $type) ? '' : "/{$type}";
    if (!is_dir(WP_LANG_DIR)) {
        return array();
    }
    if ($dir && !is_dir(WP_LANG_DIR . $dir)) {
        return array();
    }
    $files = scandir(WP_LANG_DIR . $dir);
    if (!$files) {
        return array();
    }
    $language_data = array();
    foreach ($files as $file) {
        if ('.' === $file[0] || is_dir(WP_LANG_DIR . "{$dir}/{$file}")) {
            continue;
        }
        if (substr($file, -3) !== '.po') {
            continue;
        }
        if (!preg_match('/(?:(.+)-)?([a-z]{2,3}(?:_[A-Z]{2})?(?:_[a-z0-9]+)?).po/', $file, $match)) {
            continue;
        }
        if (!in_array(substr($file, 0, -3) . '.mo', $files, true)) {
            continue;
        }
        list(, $textdomain, $language) = $match;
        if ('' === $textdomain) {
            $textdomain = 'default';
        }
        $language_data[$textdomain][$language] = wp_get_pomo_file_data(WP_LANG_DIR . "{$dir}/{$file}");
    }
    return $language_data;
}

WordPress Version: 5.5

/**
 * Get installed translations.
 *
 * Looks in the wp-content/languages directory for translations of
 * plugins or themes.
 *
 * @since 3.7.0
 *
 * @param string $type What to search for. Accepts 'plugins', 'themes', 'core'.
 * @return array Array of language data.
 */
function wp_get_installed_translations($type)
{
    if ('themes' !== $type && 'plugins' !== $type && 'core' !== $type) {
        return array();
    }
    $dir = ('core' === $type) ? '' : "/{$type}";
    if (!is_dir(WP_LANG_DIR)) {
        return array();
    }
    if ($dir && !is_dir(WP_LANG_DIR . $dir)) {
        return array();
    }
    $files = scandir(WP_LANG_DIR . $dir);
    if (!$files) {
        return array();
    }
    $language_data = array();
    foreach ($files as $file) {
        if ('.' === $file[0] || is_dir(WP_LANG_DIR . "{$dir}/{$file}")) {
            continue;
        }
        if (substr($file, -3) !== '.po') {
            continue;
        }
        if (!preg_match('/(?:(.+)-)?([a-z]{2,3}(?:_[A-Z]{2})?(?:_[a-z0-9]+)?).po/', $file, $match)) {
            continue;
        }
        if (!in_array(substr($file, 0, -3) . '.mo', $files, true)) {
            continue;
        }
        list(, $textdomain, $language) = $match;
        if ('' === $textdomain) {
            $textdomain = 'default';
        }
        $language_data[$textdomain][$language] = wp_get_pomo_file_data(WP_LANG_DIR . "{$dir}/{$file}");
    }
    return $language_data;
}

WordPress Version: 5.4

/**
 * Get installed translations.
 *
 * Looks in the wp-content/languages directory for translations of
 * plugins or themes.
 *
 * @since 3.7.0
 *
 * @param string $type What to search for. Accepts 'plugins', 'themes', 'core'.
 * @return array Array of language data.
 */
function wp_get_installed_translations($type)
{
    if ('themes' !== $type && 'plugins' !== $type && 'core' !== $type) {
        return array();
    }
    $dir = ('core' === $type) ? '' : "/{$type}";
    if (!is_dir(WP_LANG_DIR)) {
        return array();
    }
    if ($dir && !is_dir(WP_LANG_DIR . $dir)) {
        return array();
    }
    $files = scandir(WP_LANG_DIR . $dir);
    if (!$files) {
        return array();
    }
    $language_data = array();
    foreach ($files as $file) {
        if ('.' === $file[0] || is_dir(WP_LANG_DIR . "{$dir}/{$file}")) {
            continue;
        }
        if (substr($file, -3) !== '.po') {
            continue;
        }
        if (!preg_match('/(?:(.+)-)?([a-z]{2,3}(?:_[A-Z]{2})?(?:_[a-z0-9]+)?).po/', $file, $match)) {
            continue;
        }
        if (!in_array(substr($file, 0, -3) . '.mo', $files)) {
            continue;
        }
        list(, $textdomain, $language) = $match;
        if ('' === $textdomain) {
            $textdomain = 'default';
        }
        $language_data[$textdomain][$language] = wp_get_pomo_file_data(WP_LANG_DIR . "{$dir}/{$file}");
    }
    return $language_data;
}

WordPress Version: 4.5

/**
 * Get installed translations.
 *
 * Looks in the wp-content/languages directory for translations of
 * plugins or themes.
 *
 * @since 3.7.0
 *
 * @param string $type What to search for. Accepts 'plugins', 'themes', 'core'.
 * @return array Array of language data.
 */
function wp_get_installed_translations($type)
{
    if ($type !== 'themes' && $type !== 'plugins' && $type !== 'core') {
        return array();
    }
    $dir = ('core' === $type) ? '' : "/{$type}";
    if (!is_dir(WP_LANG_DIR)) {
        return array();
    }
    if ($dir && !is_dir(WP_LANG_DIR . $dir)) {
        return array();
    }
    $files = scandir(WP_LANG_DIR . $dir);
    if (!$files) {
        return array();
    }
    $language_data = array();
    foreach ($files as $file) {
        if ('.' === $file[0] || is_dir(WP_LANG_DIR . "{$dir}/{$file}")) {
            continue;
        }
        if (substr($file, -3) !== '.po') {
            continue;
        }
        if (!preg_match('/(?:(.+)-)?([a-z]{2,3}(?:_[A-Z]{2})?(?:_[a-z0-9]+)?).po/', $file, $match)) {
            continue;
        }
        if (!in_array(substr($file, 0, -3) . '.mo', $files)) {
            continue;
        }
        list(, $textdomain, $language) = $match;
        if ('' === $textdomain) {
            $textdomain = 'default';
        }
        $language_data[$textdomain][$language] = wp_get_pomo_file_data(WP_LANG_DIR . "{$dir}/{$file}");
    }
    return $language_data;
}

WordPress Version: 4.3

/**
 * Get installed translations.
 *
 * Looks in the wp-content/languages directory for translations of
 * plugins or themes.
 *
 * @since 3.7.0
 *
 * @param string $type What to search for. Accepts 'plugins', 'themes', 'core'.
 * @return array Array of language data.
 */
function wp_get_installed_translations($type)
{
    if ($type !== 'themes' && $type !== 'plugins' && $type !== 'core') {
        return array();
    }
    $dir = ('core' === $type) ? '' : "/{$type}";
    if (!is_dir(WP_LANG_DIR)) {
        return array();
    }
    if ($dir && !is_dir(WP_LANG_DIR . $dir)) {
        return array();
    }
    $files = scandir(WP_LANG_DIR . $dir);
    if (!$files) {
        return array();
    }
    $language_data = array();
    foreach ($files as $file) {
        if ('.' === $file[0] || is_dir($file)) {
            continue;
        }
        if (substr($file, -3) !== '.po') {
            continue;
        }
        if (!preg_match('/(?:(.+)-)?([a-z]{2,3}(?:_[A-Z]{2})?(?:_[a-z0-9]+)?).po/', $file, $match)) {
            continue;
        }
        if (!in_array(substr($file, 0, -3) . '.mo', $files)) {
            continue;
        }
        list(, $textdomain, $language) = $match;
        if ('' === $textdomain) {
            $textdomain = 'default';
        }
        $language_data[$textdomain][$language] = wp_get_pomo_file_data(WP_LANG_DIR . "{$dir}/{$file}");
    }
    return $language_data;
}

WordPress Version: 4.1

/**
 * Get installed translations.
 *
 * Looks in the wp-content/languages directory for translations of
 * plugins or themes.
 *
 * @since 3.7.0
 *
 * @param string $type What to search for. Accepts 'plugins', 'themes', 'core'.
 * @return array Array of language data.
 */
function wp_get_installed_translations($type)
{
    if ($type !== 'themes' && $type !== 'plugins' && $type !== 'core') {
        return array();
    }
    $dir = ('core' === $type) ? '' : "/{$type}";
    if (!is_dir(WP_LANG_DIR)) {
        return array();
    }
    if ($dir && !is_dir(WP_LANG_DIR . $dir)) {
        return array();
    }
    $files = scandir(WP_LANG_DIR . $dir);
    if (!$files) {
        return array();
    }
    $language_data = array();
    foreach ($files as $file) {
        if ('.' === $file[0] || is_dir($file)) {
            continue;
        }
        if (substr($file, -3) !== '.po') {
            continue;
        }
        if (!preg_match('/(?:(.+)-)?([A-Za-z_]{2,6}).po/', $file, $match)) {
            continue;
        }
        if (!in_array(substr($file, 0, -3) . '.mo', $files)) {
            continue;
        }
        list(, $textdomain, $language) = $match;
        if ('' === $textdomain) {
            $textdomain = 'default';
        }
        $language_data[$textdomain][$language] = wp_get_pomo_file_data(WP_LANG_DIR . "{$dir}/{$file}");
    }
    return $language_data;
}

WordPress Version: 3.7

/**
 * Get installed translations.
 *
 * Looks in the wp-content/languages directory for translations of
 * plugins or themes.
 *
 * @since 3.7.0
 *
 * @param string $type What to search for. Accepts 'plugins', 'themes', 'core'.
 * @return array Array of language data.
 */
function wp_get_installed_translations($type)
{
    if ($type !== 'themes' && $type !== 'plugins' && $type !== 'core') {
        return array();
    }
    $dir = ('core' === $type) ? '' : "/{$type}";
    if (!is_dir(WP_LANG_DIR)) {
        return array();
    }
    if ($dir && !is_dir(WP_LANG_DIR . $dir)) {
        return array();
    }
    $files = scandir(WP_LANG_DIR . $dir);
    if (!$files) {
        return array();
    }
    $language_data = array();
    foreach ($files as $file) {
        if ('.' === $file[0] || is_dir($file)) {
            continue;
        }
        if (substr($file, -3) !== '.po') {
            continue;
        }
        if (!preg_match('/(?:(.+)-)?([A-Za-z_]{2,6}).po/', $file, $match)) {
            continue;
        }
        list(, $textdomain, $language) = $match;
        if ('' === $textdomain) {
            $textdomain = 'default';
        }
        $language_data[$textdomain][$language] = wp_get_pomo_file_data(WP_LANG_DIR . "{$dir}/{$file}");
    }
    return $language_data;
}