Translate in another language than the current language

I have tricky a use case, where I need to create a custom entity from an opportunity plus some external data. In the opportunity, there's a custom dropdown, whose value will be transferred as text to a textfield in the custom entity. This text value (from the dropdown) has to be in the language of the custom entity, which may or may not be the language of the current user.

So, let's say I am connected and my preferred language is english. I need to convert an opportunity to a custom entity, but in french. How do I translate the dropdown value in french?

$opportunity = new Opportunity();
$opportunity->retrieve($args['id']);

// How do I translate this?
$value = $GLOBALS['app_list_strings']['custom_dropdown'][$opportunity->custom_dropdown];
Parents Reply Children
  • Alright, I was able do the translation with the link from your last post. I wish there was a less convoluted way to do this though, this code smells really bad!

    $opportunity = new Opportunity();
    $opportunity->retrieve($args['id']);
    
    $app_list_strings = [];
    if ($contentLocale == 'fr') {
        include __DIR__ . '/../../../../../Extension/application/Ext/Language/fr_FR.sugar_custom_dropdown.php';
    } else {
        include __DIR__ . '/../../../../../Extension/application/Ext/Language/en_us.sugar_custom_dropdown.php';
    }
    
    $entity = new CustomEntity();
    $entity->localized_value = $app_list_strings['custom_dropdown'][$opportunity->custom_dropdown];
    
  • Yes, it is not very pretty.  Though why do you store localized value at all?  I feel like it is better practice to have localization handled within client as part of the representation of the data because then it is easier to handle a user's language preferences.

    App Ecosystem @ SugarCRM