From 54f6dd3722aa497fe5db2926b7dae7ace24f4b81 Mon Sep 17 00:00:00 2001 From: Takayuki Miyoshi Date: Sun, 13 Nov 2022 18:18:01 +0900 Subject: [PATCH] Update l10n.php #525 #1053 --- includes/l10n.php | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/includes/l10n.php b/includes/l10n.php index 9adeb6f7..f5781703 100644 --- a/includes/l10n.php +++ b/includes/l10n.php @@ -1,5 +1,11 @@ 'Arabic', @@ -62,6 +78,13 @@ function wpcf7_is_rtl( $locale = '' ) { return isset( $rtl_locales[$locale] ); } + +/** + * Loads a translation file into the plugin's text domain. + * + * @param string $locale Locale code. + * @return bool True on success, false on failure. + */ function wpcf7_load_textdomain( $locale = '' ) { static $available_locales = null; @@ -84,10 +107,28 @@ function wpcf7_load_textdomain( $locale = '' ) { return load_textdomain( WPCF7_TEXT_DOMAIN, $mofile, $locale ); } + +/** + * Unloads translations for the plugin's text domain. + * + * @param bool $reloadable Whether the text domain can be loaded + * just-in-time again. + * @return bool True on success, false on failure. + */ function wpcf7_unload_textdomain( $reloadable = false ) { - unload_textdomain( WPCF7_TEXT_DOMAIN, $reloadable ); + return unload_textdomain( WPCF7_TEXT_DOMAIN, $reloadable ); } + +/** + * Switches translation locale, calls the callback, then switches back + * to the original locale. + * + * @param string $locale Locale code. + * @param callable $callback The callable to be called. + * @param mixed $args Parameters to be passed to the callback. + * @return mixed The return value of the callback. + */ function wpcf7_switch_locale( $locale, callable $callback, ...$args ) { $previous_locale = determine_locale();