plugin_locale
Filter to adjust the Uncanny Automator locale to use for translations. Note: the first-loaded translation file overrides any following ones if the same translation is present. Locales found in: - WP_LANG_DIR/uncanny-automator/uncanny-automator-LOCALE.mo - WP_LANG_DIR/plugins/uncanny-automator-LOCALE.mo Filters the locale used for Uncanny Automator translations, allowing custom overrides.
add_filter( 'plugin_locale', $callback, 10, 1 );
Description
Allows developers to dynamically change the locale used for Uncanny Automator translations. This filter is applied when Uncanny Automator loads its translation files. Be aware that earlier loaded translation files will override later ones if the same translation key exists.
Usage
add_filter( 'plugin_locale', 'your_function_name', 10, 1 );
Parameters
-
$locale(mixed) - - **'uncanny-automator'** `mixed`
Return Value
The filtered value.
Examples
<?php
/**
* Filters the locale for the Uncanny Automator plugin.
*
* This function demonstrates how to hook into the 'plugin_locale' filter
* to potentially change the locale used for Uncanny Automator's translations.
* In this example, we're just logging the current locale and returning it unchanged,
* but you could implement logic here to dynamically set a locale based on
* user preferences, browser settings, or other criteria.
*
* @param string $locale The current locale string.
* @param string $plugin_text_domain The text domain of the plugin.
* @return string The modified or original locale string.
*/
function my_custom_automator_locale( $locale, $plugin_text_domain ) {
// Ensure this filter only applies to Uncanny Automator.
if ( 'uncanny-automator' === $plugin_text_domain ) {
// Log the current locale for debugging purposes.
error_log( "Uncanny Automator current locale: " . $locale );
// Example: If you wanted to force a specific locale, you could do:
// $new_locale = 'es_ES'; // For Spanish
// error_log( "Uncanny Automator forcing locale to: " . $new_locale );
// return $new_locale;
// For this example, we'll just return the original locale.
return $locale;
}
// If it's not our plugin's text domain, return the original locale.
return $locale;
}
// Add the filter to WordPress.
// The 'plugin_locale' hook expects 2 arguments: $locale and $plugin_text_domain.
add_filter( 'plugin_locale', 'my_custom_automator_locale', 10, 2 );
?>
Placement
This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.
Source Code
src/core/lib/class-automator-functions.php:2224
public function automator_load_textdomain() {
$locale = determine_locale();
/**
* Filter to adjust the Uncanny Automator locale to use for translations.
*
* Note: the first-loaded translation file overrides any following ones if the same translation is present.
*
* Locales found in:
* - WP_LANG_DIR/uncanny-automator/uncanny-automator-LOCALE.mo
* - WP_LANG_DIR/plugins/uncanny-automator-LOCALE.mo
*/
$locale = apply_filters( 'plugin_locale', $locale, 'uncanny-automator' );
unload_textdomain( 'uncanny-automator', true );
load_textdomain( 'uncanny-automator', WP_LANG_DIR . '/uncanny-automator/uncanny-automator-' . $locale . '.mo' );
load_plugin_textdomain( 'uncanny-automator', false, plugin_basename( dirname( AUTOMATOR_BASE_FILE ) ) . '/languages' );
}