This is the second part of our guide to building a Custom Dashboard. This part continues work on the dashboard we built in part one: Creating a Custom Dashboard. It further shows how to handle localization in a custom dashboard.
We can use the umb-localize element to get the localizations out, which takes a key property in.
Using the Localization Files
Let's start using the localizations. In the umbraco-package.json file, we will already be using the #welcomeDashboard_label key for the dashboard label. Go ahead and replace "label": "Welcome Dashboard" with "label": "#welcomeDashboard_label".
The # is used to indicate that the value is a key and not a string.
We will now use the umb-localize element to get the translations for the dashboard. Update the welcome-dashboard.element.ts:
The dashboard's text will appear depending on the user's language.
If the user's language is Danish, the dashboard will use the text from our da-dk file.
If the user's language is English, the dashboard will use the text from our en file.
If the key is not found in the current language, the fallback language (en) will be used.
The text between the open and close tags of umb-localize is the fallback value. This is used in case the key can't be found at all.
This is how our dashboard should now look like:
Tip: If you do not have many translations, you can also choose to include the localizations directly in the meta-object. Read more about translations in the Localization article.
Going Further
With the part completed, you should have a dashboard welcoming your users' language.
In the next part, we will look into how to add more functionality to the dashboard using some of the Contexts that Umbraco offers.