View Issue Details

IDProjectCategoryView StatusLast Update
0010118mantisbtdocumentationpublic2014-09-23 18:05
Reporterphu Assigned Todregad  
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
PlatformPC/XAMPPOSWinNT 
Product Version1.2.0a3 
Target Version1.2.15Fixed in Version1.2.15 
Summary0010118: lang_get_current() returns wrong language if $g_default_language overwritten
Description

having the configuration in config_inc.php:

$g_default_language = 'german';

and set the personal language of my account to 'english' still causes the function

lang_get_current()

to return 'german' while evaluated in custom_strings_inc.php

when uncommented $g_default_language = 'german'; in config_inc.php it works fine.

TagsNo tags attached.

Relationships

related to 0015721 closedgrangeway Functionality to consider porting to master-2.0.x 

Activities

siebrand

siebrand

2009-06-11 12:23

developer   ~0022094

Can you please describe a scenario in more detail? I am having trouble following the actual consequences of the bug you are reporting.

chladc

chladc

2009-08-03 11:05

reporter   ~0022650

Last edited: 2009-08-03 11:05

I'm experiencing the same issue.

Here's a (lengthy) account of what happened for me:

  • At first, the default language for my Mantis instance was set to 'english'. I had created a custom_strings_inc.php file, with both English and French translations. As I intended French to eventually be the default language, my custom_strings_inc.php looked like this :

<?php
if ( lang_get_current() == 'english' ) {
$s_call_type = 'Call type';
...
} else {
// Default (French is set as the default language)
$s_call_type = 'Type d\'appel';
...
}
?>

Everything worked fine under this setup.

  • Then I changed the default language to 'french' in config_inc.php.
    For users that use French, everything works still fine. Custom field labels (and everything else) are displayed in French.
    However, for users that have chosen English as their language, custom field labels are still displayed in French, even though the rest of the page is displayed in English.

I have tried to locate where the error lies, and it seems that when lang_get_current() is evaluated in custom_strings_inc.php, it returns 'french' instead of 'english' for English-speaking users (just as phu reported).
Investigating a bit further, I narrowed down the problem to lang_get_default() in lang_api.php, on line 98:

if( function_exists( 'auth_is_user_authenticated' ) && auth_is_user_authenticated() ) {
    $t_lang = user_pref_get_language( auth_get_current_user_id() );
}

This snipped returns the correct language most of the time, but in this particular issue, it fails to return 'english' when evaluating the current language in custom_strings_inc.php. The default language ('french') is then chosen as a fallback, causing the custom fields to be translated into the wrong language.

JeromyK

JeromyK

2012-04-05 12:34

reporter   ~0031603

I have the same problem with 1.2.8 I think. Will test the issue with 1.2.10 and post again, if problem still exists.

dregad

dregad

2013-02-06 11:51

developer   ~0035058

The problem is caused by using an incorrect method to determine the current language in custom_strings_inc.php.

The example in the MantisBT documentation advised to use lang_get_current() to determine the current language, but this function resets the active language, and therefore returns an incorrect value when the default language ($g_default_language) is different from English.

The proper method is to use the global variable $g_active_language, as per the example below:


<?php
switch( $g_active_language ) {
case 'french':
$s_my_start_date = 'Date de début';
break;

default:
    # Default language, as defined in config_inc.php
    # ($g_default_language, English in this case)
    $s_my_start_date = 'Start Date';
    break;

}

The documentation has been updated accordingly.

grangeway

grangeway

2013-04-05 17:56

reporter   ~0036099

Marking as 'acknowledged' not resolved/closed to track that change gets ported to master-2.0.x branch

Related Changesets

MantisBT: master-1.2.x 4490a54b

2013-02-06 11:24

dregad


Details Diff
Documentation: custom fields localization

The indications in the Custom Fields localization section contained an
incorrect reference to lang_get_current() to determine the current
language in custom_strings_inc.php. Using this function will cause the
code to return incorrect translations if the default language is
different from English.

Fixes 0010118
Affected Issues
0010118
mod - docbook/administration_guide/en/customizing_mantis.sgml Diff File

MantisBT: master da3362de

2013-02-06 11:24

dregad


Details Diff
Documentation: custom fields localization

The indications in the Custom Fields localization section contained an
incorrect reference to lang_get_current() to determine the current
language in custom_strings_inc.php. Using this function will cause the
code to return incorrect translations if the default language is
different from English.

Fixes 0010118
Affected Issues
0010118
mod - docbook/Admin_Guide/en-US/Customizing.xml Diff File