Expand Minimize Picture-in-picture Power Device Status Voice Recognition Skip Back Skip Forward Minus Plus Play Search
Internet Explorer alert
This browser is not recommended for use with smartdevicelink.com, and may not function properly. Upgrade to a different browser to guarantee support of all features.
close alert
To Top Created with Sketch. To Top
To Bottom Created with Sketch. To Bottom
JavaScript Suite Guides
Adapting to the Head Unit Language

Adapting to the Head Unit Language

Since a head unit can support multiple languages, you may want to add support for more than one language to your SDL app. The SDL library allows you to check which language is currently used by the head unit. If desired, the app's name and the app's text-to-speech (TTS) name can be customized to reflect the head unit's current language. If your app name is not part of the current lexicon, you should tell the VR system how a native speaker will pronounce your app name by setting the TTS name using phonemes from either the Microsoft SAPI phoneme set or from the LHPLUS phoneme set.

Setting the Default Language

The initial configuration of the SdlManager requires a default language when setting the SDL.manager.LifecycleConfig. If not set, the SDL library uses American English (EN_US) as the default language. The connection will fail if the head unit does not support the language set in the SDL.manager.LifecycleConfig. The RegisterAppInterface response RPC will return INVALID_DATA as the reason for rejecting the request.

What if My App Does Not Support the Head Unit Language?

If your app does not support the current head unit language, you should decide on a default language to use in your app. All text should be created using this default language. Unfortunately, your VR commands will probably not work as the VR system will not recognize your users' pronunciation.

Checking the Current Head Unit Language

After starting the SDLManager you can check the sdlManager.getRegisterAppInterfaceResponse() property for the head unit's language and hmiDisplayLanguage. The language property gives you the current VR system language; hmiDisplayLanguage the current display text language.

const headUnitLanguage = sdlManager.getRegisterAppInterfaceResponse().getLanguage();
const headUnitHMILanguage = sdlManager.getRegisterAppInterfaceResponse().getHmiDisplayLanguage();

Updating the SDL App Name

To customize the app name for the head unit's current language, implement the following steps:

  1. Set the default language in the LifecyleConfig.

  2. Implement the sdlManagerListener's managerShouldUpdateLifecycle(language, hmiLanguage) method. If the module's current HMI language or voice recognition (VR) language is different from the app's default language, the listener will be called with the module's current HMI and/or VR language. Return a LifecycleConfigurationUpdate with the new appName and/or ttsName.

managerShouldUpdateLifecycle(language, hmiLanguage) {
    let isUpdateNeeded = false;
    let appName = APP_NAME;
    let ttsName = APP_NAME;
    switch (language) {
        case SDL.rpc.enums.Language.ES_MX:
            isUpdateNeeded = true;
            ttsName = APP_NAME_ES;
            break;
        case SDL.rpc.enums.Language.FR_CA:
            isUpdateNeeded = true;
            ttsName = APP_NAME_FR;
            break;
        default:
            break;
    }
    switch (hmiLanguage) {
        case SDL.rpc.enums.Language.ES_MX:
            isUpdateNeeded = true;
            appName = APP_NAME_ES;
            break;
        case SDL.rpc.enums.Language.FR_CA:
            isUpdateNeeded = true;
            appName = APP_NAME_FR;
            break;
        default:
            break;
    }
    if (isUpdateNeeded) {
        const chunks = [new SDL.rpc.structs.TTSChunk().setText(ttsName).setType(SDL.rpc.enums.SpeechCapabilities.SC_TEXT))];
        return new SDL.manager.lifecycle.LifecycleConfigurationUpdate(appName, null, chunks, null);
    } else {
        return null;
    }
}
View on GitHub.com
Previous Section Next Section