Adding localization to the dashboard
Set up localization for your dashboard.
Overview
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.
The steps we will go through in second part are:
Setup Localization Files
In the
welcome-dashboard
folder create a new folder called "Localization
"Then create two new files
en.js
andda-dk.js
:
Add the following code to
en.js
export default {
welcomeDashboard: {
label: "Welcome Dashboard",
heading: "Welcome",
bodytext: "This is the Backoffice. From here, you can modify the content, media, and settings of your website.",
copyright: "© Sample Company 20XX",
}
};
Add the following code to
da-dk.js
export default {
welcomeDashboard: {
label: "Velkomst Dashboard",
heading: "Velkommen",
bodytext: "Dette er Backoffice. Herfra kan du ændre indholdet, medierne og indstillingerne på din hjemmeside.",
copyright: "© Sample Selskab 20XX",
}
};
Register Localization Files
Now let's update the umbraco-package.json
file from the welcome-dashboard
folder to register our new localization files:
{
...
"extensions": [
{...},
{
"type": "localization",
"alias": "MyPackage.Localize.En",
"name": "English",
"meta": {
"culture": "en"
},
"js": "/App_Plugins/welcome-dashboard/Localization/en.js"
},
{
"type": "localization",
"alias": "MyPackage.Localize.DaDK",
"name": "Danish",
"meta": {
"culture": "da-dk"
},
"js": "/App_Plugins/welcome-dashboard/Localization/da-dk.js"
}
]
}
Run npm run build
in the welcome-dashboard
folder and then run the project.
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"
.
We will now use the umb-localize
element to get the translations for the dashboard. Update the welcome-dashboard.element.ts
:
render() {
return html`
<h1>
<umb-localize key="welcomeDashboard_heading">Welcome</umb-localize>
Dashboard
</h1>
<div>
<p>
<umb-localize key="welcomeDashboard_bodytext">
This is the Backoffice. From here, you can modify the content,
media, and settings of your website.
</umb-localize>
</p>
<p>
<umb-localize key="welcomeDashboard_copyright">
© Sample Company 20XX
</umb-localize>
</p>
</div>
`;
}
Run npm run build
in the welcome-dashboard
folder and then run the project.
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.
This is how our dashboard should now look like:


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.
Last updated
Was this helpful?