Changed the language for DataTables to make use of the i18n plug-in json file and added the Dutch translation file

This commit is contained in:
2026-07-21 23:04:29 +02:00
parent dbe5b03e9e
commit 3632c834ac
3 changed files with 348 additions and 2 deletions
+34 -2
View File
@@ -282,8 +282,8 @@ function wp_jdt_shortcode($atts)
'order': [<?php echo $table_order_row_number; ?>, '<?php echo esc_js($table_order_sort); ?>'],
'searching': <?php echo $table_searching; ?>,
'language': {
'search': '<?php echo esc_js(esc_html__('Searching', 'wp-jquery-datatable')); ?>:'
}
'url': '<?php echo esc_url(get_jdt_locale_json_file()); ?>',
},
});
});
</script>
@@ -313,3 +313,35 @@ function wp_jdt_uninstall()
delete_option($setting);
}
}
/**
* Get the path of the locale JSON file if it exists.
*
* @return string|null File path if valid, or null if skipped/missing.
*/
function get_jdt_locale_json_file()
{
// 1. Get the current locale (e.g., 'nl_NL', 'en_US', 'en_GB')
$locale = get_user_locale();
// 2. Exclude en_US specifically as that's the default dataTables language
// (en_GB and other English regional locales remain valid)
if ($locale === 'en_US') {
return null;
}
// 3. Format the filename ('nl_NL' -> 'nl-NL.json')
$formatted_locale = str_replace('_', '-', $locale);
$filename = "{$formatted_locale}.json";
// 4. Set relative path inside your plugin directory
$relative_path = "plug-ins/i18n/{$filename}";
// 5. Verify file existence on disk
if (!file_exists(plugin_dir_path(__FILE__) . $relative_path)) {
return null;
}
// 6. Return either the direct URL or the absolute file path
return plugin_dir_url(__FILE__) . $relative_path;
}