Skip to content

Commit

Permalink
lang_ensure_loaded(): load current plugin's strings
Browse files Browse the repository at this point in the history
Move the code to load the currently active plugin's strings from
lang_get() to lang_ensure_loaded().

This is in preparation for fixing issue #21201, as this code would then
be duplicated in lang_get_defaulted().
  • Loading branch information
dregad committed Mar 3, 2020
1 parent 0cc0885 commit 8d6784e
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions core/lang_api.php
Expand Up @@ -171,7 +171,8 @@ function lang_map_auto() {
}

/**
* Ensures that a language file has been loaded
* Ensures that a language file has been loaded.
* Also load the currently active plugin's strings, if there is one.
* @param string $p_lang The language name.
* @return void
*/
Expand All @@ -181,6 +182,12 @@ function lang_ensure_loaded( $p_lang ) {
if( !isset( $g_lang_strings[$p_lang] ) ) {
lang_load( $p_lang );
}

# Load current plugin's strings
$t_plugin_current = plugin_get_current();
if( $t_plugin_current !== null ) {
lang_load( $p_lang, config_get_global( 'plugin_path' ) . $t_plugin_current . '/lang/' );
}
}

/**
Expand Down Expand Up @@ -293,14 +300,6 @@ function lang_get( $p_string, $p_lang = null ) {
if( lang_exists( $p_string, $t_lang ) ) {
return $g_lang_strings[$t_lang][$p_string];
} else {
$t_plugin_current = plugin_get_current();
if( !is_null( $t_plugin_current ) ) {
lang_load( $t_lang, config_get_global( 'plugin_path' ) . $t_plugin_current . DIRECTORY_SEPARATOR . 'lang' . DIRECTORY_SEPARATOR );
if( lang_exists( $p_string, $t_lang ) ) {
return $g_lang_strings[$t_lang][$p_string];
}
}

if( $t_lang == 'english' ) {
error_parameters( $p_string );
trigger_error( ERROR_LANG_STRING_NOT_FOUND, WARNING );
Expand Down

0 comments on commit 8d6784e

Please sign in to comment.