Skip to content

Commit 8163d2b

Browse files
committedSep 22, 2011
Fallback to English when string is not defined
MantisBT generally falls back correctly to default English when a string is not defined in the current language. However, when the admin wants to restrict the available languages ($g_language_choices_arr) and remove 'english' from the list (see issue #13315), an error 300 is displayed when strings are missing from the translated strings_xxx.txt file (as can be the case for strings defined as "optional" in TranslateWiki, such as $s_directionality). Commit also removes obsolete comment about not falling back to English.
1 parent 8cc56ce commit 8163d2b

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed
 

‎core/lang_api.php

+8-8
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ function lang_load( $p_lang, $p_dir = null ) {
8585
$t_custom_strings = config_get( 'custom_strings_file' ) ;
8686
if( file_exists( $t_custom_strings ) ) {
8787
# this may be loaded multiple times, once per language
88-
require( $t_custom_strings );
88+
require( $t_custom_strings );
8989
}
90-
90+
9191
// Step 3 - New Language file format
9292
// Language file consists of an array
9393
if( isset( $s_messages ) ) {
@@ -96,7 +96,7 @@ function lang_load( $p_lang, $p_dir = null ) {
9696
if( isset( $s_custom_messages[$p_lang] ) ) {
9797
// Step 4 - handle merging in custom strings:
9898
// Possible states:
99-
// 4.a - new string format + new custom string format
99+
// 4.a - new string format + new custom string format
100100
$g_lang_strings[$p_lang] = array_replace( ((array)$g_lang_strings[$p_lang]), (array)$s_messages, (array)$s_custom_messages[$p_lang]);
101101
return;
102102
} else {
@@ -106,7 +106,7 @@ function lang_load( $p_lang, $p_dir = null ) {
106106
// new language loaded
107107
$g_lang_strings[$p_lang] = $s_messages;
108108
if( isset( $s_custom_messages[$p_lang] ) ) {
109-
// 4.a - new string format + new custom string format
109+
// 4.a - new string format + new custom string format
110110
$g_lang_strings[$p_lang] = array_replace( ((array)$g_lang_strings[$p_lang]), (array)$s_custom_messages[$p_lang]);
111111
return;
112112
}
@@ -231,7 +231,7 @@ function lang_ensure_loaded( $p_lang ) {
231231
*/
232232
function lang_language_exists( $p_lang ) {
233233
$t_valid_langs = config_get( 'language_choices_arr' );
234-
$t_valid = in_array( $p_lang, $t_valid_langs, true );
234+
$t_valid = ( 'english' == $p_lang || in_array( $p_lang, $t_valid_langs, true ) );
235235
return $t_valid;
236236
}
237237

@@ -329,7 +329,7 @@ function lang_get( $p_string, $p_lang = null, $p_error = true ) {
329329
return $g_lang_strings[$t_lang][$p_string];
330330
} else {
331331
// Language string doesn't exist in requested language
332-
332+
333333
// Step 2 - See if language string exists in current plugin
334334
$t_plugin_current = plugin_get_current();
335335
if( !is_null( $t_plugin_current ) ) {
@@ -338,12 +338,12 @@ function lang_get( $p_string, $p_lang = null, $p_error = true ) {
338338
if( lang_exists( $p_string, $t_lang ) ) {
339339
return $g_lang_strings[$t_lang][$p_string];
340340
}
341-
341+
342342
// Step 4 - Localised language entry didn't exist - fallback to english for plugin
343343
lang_load( 'english', config_get( 'plugin_path' ) . $t_plugin_current . DIRECTORY_SEPARATOR . 'lang' . DIRECTORY_SEPARATOR );
344344
if( lang_exists( $p_string, $t_lang ) ) {
345345
return $g_lang_strings[$t_lang][$p_string];
346-
}
346+
}
347347
}
348348

349349
// Step 5 - string didn't exist, try fall back to english:

0 commit comments

Comments
 (0)
Please sign in to comment.