From d92b78facaf45b80177ab786c43ed83d93ee50ca Mon Sep 17 00:00:00 2001 From: Damien Regad Date: Sun, 15 Mar 2020 18:23:27 +0100 Subject: [PATCH] New plugin_lang_get_defaulted() API function Plugin API provides plugin_lang_get(), pairing with lang_get(), but there was no equivalent to lang_get_defaulted() in Plugin API. Fixes #26747 --- core/plugin_api.php | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/core/plugin_api.php b/core/plugin_api.php index 98f10bb23f..eda53f62ff 100644 --- a/core/plugin_api.php +++ b/core/plugin_api.php @@ -356,6 +356,34 @@ function plugin_lang_get( $p_name, $p_basename = null ) { return $t_string; } +/** + * Get a defaulted language string for the plugin. + * - If found, return the appropriate string. + * - If not found, no default supplied, return the supplied string as is. + * - If not found, default supplied, return default. + * Automatically prepends plugin_ to the string requested. + * @see lang_get_defaulted() + * + * @param string $p_name Language string name. + * @param string $p_default The default value to return. + * @param string $p_basename Plugin basename. + * + * @return string Language string + */ +function plugin_lang_get_defaulted( $p_name, $p_default = null, $p_basename = null ) { + if( !is_null( $p_basename ) ) { + plugin_push_current( $p_basename ); + } + $t_basename = plugin_get_current(); + $t_name = 'plugin_' . $t_basename . '_' . $p_name; + $t_string = lang_get_defaulted( $t_name, $p_default ); + + if( !is_null( $p_basename ) ) { + plugin_pop_current(); + } + return $t_string; +} + /** * log history event from plugin * @param integer $p_bug_id A bug identifier.