Localization

Localization is another zero-configuration aspect of Start Blazoring. In today's global economy, correctly localizing your application is very important. While you still have to write your own translation files, we have made consuming them very easy.

Localization services are initialized in Startup.InitializeLocalization. If you are interested in more details, please refer to the documentation in the code. In a nutshell, we have configured the application to discover any .resx files an use them as localization resources.

The way Blazor localization works is by injecting a localization service into your Blazor pages, like this: @inject IStringLocalizer<PageName> L, where PageName is the name of your Blazor page. Then, you can look up any localization resource like this: @L["LocalizedKey"]. To create new localization resources for PageName, go to the Resources\Pages\ folder and create a new PageName.resx file specifying your default language translations (configured in ServiceConfiguration.Application.DefaultLanguage). Then, for each of your supported languages, create a new PageName.<language-code>.resc file. The naming here is very important, so make sure you use the same name as your page. Additionally, the folder structure of the Resources\ folder is very important. If you end up placing your new page in another folder, the relative location of the resource file in Resources\ must mirror the location of the new page. The same applies to Razor components.

The mechanism by which a given language file is used depends on the language set in the browser. This mechanism is made possible by app.UseRequestLocalization(localizationOptions) in Startup.Configure. A user can also choose the language manually on the Settings page. That is stored in the user's settings. See MainLayout.razor to see how that is retrieved and applied when the page loads. As usual, due to he nature of Blazor, we must through some hoops to make this happen.

Managing Translations

Managing translation resource files can be a daunting task, especially if your website has a lot of pages and components. For this reason, we have included a file called Translation.filenesting.json that you can use to help with grouping related translation files. For more information on how to use it, see Microsoft's documentation.

All the pages that come with Start Blazoring have been automatically translated in a number of languages using Microsoft's translation service. There is a generous Free tier that you can use to automatically translate the new pages you will add. Please note that each Blazor page and component will need its own set of resx files for each language. We have developed scripts to help automate this process. Please reach out if you need them, as they are not part of the template.

We have also partnered with Soluling, a popular localization application. With Soluling, you can easily manage your translations using their application, as we well as generate translation files in different languages automatically. That is how we translated the pages in the template using Microsoft Translation services. They are offering our customers a discount on their Products. Visit the Downloads page for more information.

Table of Contents



An error has occurred. This application may no longer respond until reloaded. Reload 🗙