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 & quot;]. 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. In a future version, we will have a mechanism to allow the user to choose the language manually.

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.

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 🗙