Skip to content

Commit ff7a1a8

Browse files
committed
Only use lang dirs with translations in them
Avoids using custom paths without any translations. Addresses some fallback combination issues. Follow-up to #1194 Fixes #1202
1 parent c3c4cfc commit ff7a1a8

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

inc/functions.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1235,12 +1235,29 @@ function preferred_languages_filter_lang_dir_for_domain( $path, $domain, $locale
12351235
);
12361236
}
12371237

1238+
// From WP_Textdomain_Registry::get_path_from_lang_dir().
1239+
$has_translation_in_folder = static function ( $location, $domain, $locale ) use ( $wp_textdomain_registry ) {
1240+
$location = rtrim( $location, '/' );
1241+
$files = $wp_textdomain_registry->get_language_files_from_path( $location );
1242+
1243+
$mo_path = "$location/$domain-$locale.mo";
1244+
$php_path = "$location/$domain-$locale.l10n.php";
1245+
1246+
foreach ( $files as $file_path ) {
1247+
if ( $file_path === $mo_path || $file_path === $php_path ) {
1248+
return true;
1249+
}
1250+
}
1251+
1252+
return false;
1253+
};
1254+
12381255
foreach ( $preferred_locales as $preferred_locale ) {
12391256
remove_filter( 'lang_dir_for_domain', 'preferred_languages_filter_lang_dir_for_domain' );
12401257
$new_path = $wp_textdomain_registry->get( $domain, $preferred_locale );
12411258
add_filter( 'lang_dir_for_domain', 'preferred_languages_filter_lang_dir_for_domain', 10, 3 );
12421259

1243-
if ( $new_path && $new_path !== $path ) {
1260+
if ( $new_path && $has_translation_in_folder( $new_path, $domain, $preferred_locale ) ) {
12441261
return $new_path;
12451262
}
12461263
}

0 commit comments

Comments
 (0)