Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
In our increasingly globalized environment, enabling seamless multilingual support in your Qlik Sense apps is no longer a nice-to-have - it’s expected.
Many implementations require users to manually select their desired language to display labels and content. In a helpful Qlik Community post, Jennel guides users through building a multilingual Qlik Sense app using an Excel-based translation table and manual language selection via dropdowns.
While Jennel’s solution is powerful and flexible, it relies on users making that initial language choice. In this article, I’ll show how to streamline the user experience by automatically detecting a user’s preferred language - based on their Qlik Cloud profile - and dynamically adapting the app accordingly using the GetUserAttr('userLocale') function.
Jennel’s method involves:
This approach, while widely used, introduces a required step - it depends on users selecting their preferred language every time they open the app.
My solution builds on Jennel’s foundation with one key improvement: the app automatically reads the user’s preferred language from their Qlik Cloud settings via the newly added attribute to the GetUserAttr: userLocale. This eliminates manual language selection and delivers an interface that adapts instantly and seamlessly to each user.
In the Data Load script, nothing really changes from Jennel’s approach: I loaded an external file containing the required translations:
The magic happens in the front-end part of the analytics app. Everything that should be translated uses the same approach that Jennel stated in her article: a variable with a Set Analysis filter containing the ID of that specific label/title/subtitle.
={<Index={46}>} $(vLanguageString)
The magic is in the variable; $(vLanguageString), in fact, is defined as:
vLanguageString = Only({<Language={"$(vUserLanguage)"}>} Translation)
Please note the use of another variable called “vUserLanguage”: the usage of a nested variable allows to manage situations in which the user locale is not included in the translations table. Let’s say a user has Qlik Cloud set in Spanish but Spanish translations are not available: in this case the app would display everything in English despite the user locale selection.
The variable “vUserLanguage” is defined as follows:
vUserLanguage = if(count({<Lang={"$(=GetUserAttr('userLocale'))"}>} Lang) = 0, 'en', GetUserAttr('userLocale'))
As you can see, I used GetUserAttr(‘userLocale’) to fetch the preferred language set by the user in their Qlik Cloud profile. Doing this, automatically sets the translation to the user’s preference without any manual intervention.
The field “Lang” is in a dedicated table I created in the Load Script that contains all the languages available in the translations table:
To give users feedback regarding the current language, I used a flag image conditionally displayed in the app by leveraging a Layout Container. Layout Container, in fact, can conditionally display elements inside them: I then defined the conditional display rule as follows.
=$(vUserLanguage) = 'de' for German Flag
=$(vUserLanguage) = 'en' for English Flag
=$(vUserLanguage) = 'it' for Italian flag
An alternative solution could be to use a KPI with a conditional background image, using the string returned by GetUserAttr as part of the image name. Note that I used the “vUserLanguage” variable to ensure that we catch the default in case user locale is not available in the translations table.
Accessing the app with locale set to “English” displays all labels and titles in English:
Let’s go to my Qlik Cloud profile and changing locale to “Italian”:
Re-accessing the app displays labels and titles in Italian (check the flag on top right!):
Easy, without any additional effort!
Hope this article inspires you to build multilingual apps with this new feature!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.