Translations
How to translate texts in the administration UI.
Litium uses ASP.NET standard localization with translations kept in resource files for display texts in administration UI. To use custom resource file in a project, create a new file under \Src\Litium.Accelerator\Resources folder. Create the folder if it is not available.
Note that when there are multiple resource files containing the same key, the last one will be used.
When working with resource files, the naming is important. It is specified by different parts, Name[.culture].resx. Name can be whatever you prefer, something that connects it to your add-on. Culture is the culture code for the language, which can be skipped if it is the default/fallback language.
- Common.resx is the default fallback values. This file probably contains the English translation.
- Common.sv-se.resx is the Swedish translation. If this file does not contain any value, the fallback file is used.
Then add LitiumLocalization tag into Litium.Accelerator.csproj file to include all resource files under Resources folder:
<ItemGroup>
<LitiumLocalization Include="Resources\*.resx" />
</ItemGroup>
The assembly attribute Litium.Localization.UseAdministrationResource should be added in project file to include all resource strings defined by the LitiumLocalization-tag when creating a IStringLocalizer for any class in the project.
<ItemGroup>
<AssemblyAttribute Include="Litium.Localization.UseAdministrationResource" />
</ItemGroup>
The Accelerator is distributed with all strings for the different areas in a single .resx file in the \Src\Litium.Accelerator\Resources folder.
Using resource files in your add-ons makes the installation easier, since no XML files need to be imported into back office. Make sure to use unique names for your strings, for example SpecialWidgetName, if you are building a special widget for the dashboard.
Usage
- In the back bffice, there are two options to get a translation:
- Use AsAngularResourceString() string extension from Litium.Web.LocalizationExtensions. For example: "your.resource.key".AsAngularResourceString()
- Inject IStringLocalizer in constructor then use _localizer.GetString("your.resource.key")
- Angular components use ngx-translate to handle translation. Please read more about ngx-translate here.