Skip to content

Changing Language

If you wish to programmatically change the language of the CMP, after the Language Hierarchy has already been executed. You may use this method to reload the data provided via our API, just make sure you are requesting a language that is supported in your configuration:

// Example taking first language available
let languageAvailable = UsercentricsCore.shared.getCMPData().settings.languagesAvailable
let language = languageAvailable.first! 

UsercentricsCore.shared.changeLanguage(language: language) {
    // Content provided in the Data Source methods will now be available in the new language.
    // Update your own UI or create and show the UsercentricsUI
} onFailure: { error in
    // Handle non-localized error
}
// Example taking first language available
val languagesAvailable = Usercentrics.instance.getCMPData().settings.languagesAvailable
val language = languagesAvailable.first() 

Usercentrics.instance.changeLanguage(language, {
    // Content provided in the Data Source methods will now be available in the new language.
    // Update your UI or create and show the UsercentricsUI
}, { error ->
    // Handle non-localized error
})

Always change language before rendering your UI

If you call this method after the UsercentricsUI has already been created, the new language will not be applied.