Skip to content

Commit

Permalink
REST: enum localization fixes
Browse files Browse the repository at this point in the history
- Enum name should reflect english enum name.
- Fix php error due to referencing enum by localized name.
- Remove `mci_get_enum_element()` which is not needed.
  • Loading branch information
vboctor committed Apr 23, 2017
1 parent 36d1478 commit 7982443
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 19 deletions.
14 changes: 0 additions & 14 deletions api/soap/mc_api.php
Expand Up @@ -667,20 +667,6 @@ function mci_get_mantis_path() {
return config_get( 'path' );
}

/**
* Given a enum string and num, return the appropriate localized string
* @param string $p_enum_name Enumeration name.
* @param string $p_val Enumeration value.
* @param string $p_lang Language string.
* @return string
*/
function mci_get_enum_element( $p_enum_name, $p_val, $p_lang ) {
$t_enum_string = config_get( $p_enum_name . '_enum_string' );
$t_localized_enum_string = lang_get( $p_enum_name . '_enum_string', $p_lang );

return MantisEnum::getLocalizedLabel( $t_enum_string, $t_localized_enum_string, $p_val );
}

/**
* Gets the sub-projects that are accessible to the specified user / project.
* @param integer $p_user_id User id.
Expand Down
14 changes: 9 additions & 5 deletions api/soap/mc_enum_api.php
Expand Up @@ -280,13 +280,17 @@ function mci_validate_enum_access( $p_username, $p_password ) {
function mci_enum_get_array_by_id( $p_enum_id, $p_enum_type, $p_lang ) {
$t_result = array();
$t_result['id'] = (int)$p_enum_id;
$t_result['name'] = mci_get_enum_element( $p_enum_type, $p_enum_id, $p_lang );

if( !ApiObjectFactory::$soap ) {
$t_enum_name = $p_enum_type . '_enum_string';
$t_enum_string_value = config_get( $t_enum_name );
$t_enum_localized_value = lang_get( $t_enum_name );
$t_enum_name = $p_enum_type . '_enum_string';
$t_enum_string_value = config_get( $t_enum_name );
$t_enum_localized_value = lang_get( $t_enum_name, $p_lang );

if( ApiObjectFactory::$soap ) {
# Soap API returns the localized label as the name
$t_result['name'] = MantisEnum::getLocalizedLabel( $t_enum_string_value, $t_enum_localized_value, $p_enum_id );
} else {
$t_enum_array = MantisEnum::getAssocArrayIndexedByValues( $t_enum_string_value );
$t_result['name'] = $t_enum_array[$p_enum_id];
$t_result['label'] = MantisEnum::getLocalizedLabel( $t_enum_string_value, $t_enum_localized_value, $p_enum_id );

if( $p_enum_type == 'status' ) {
Expand Down

0 comments on commit 7982443

Please sign in to comment.