Localization¶
IMPORTANT¶
By default the language to use is picked from the current thread culture. This means its very important to ensure that whats in the current thread culture matches the language that should be use. This is not the case for event handlers, jobs or calls from Hydra!**
Translation scopes¶
All translations are saved in json files in the app-locales folder. Translations have a global and a local scope.
The global scope is shared between all services and the local scope is specific to one service or area, e.g. minority-transactions.
Adding localization to a service¶
Follow these steps to localize an area.
Configure Startup¶
- Initialize localization by setting
UseLocalization = truein theApiConfigurationused in Program.cs for you Api project.
public static void Main(string[] args)
=> CreateWebHostBuilder(args)
.ConfigureServices(
services => services.AddSingleton<IApiConfiguration>(
new ApiConfiguration { AllowedUserType = UserType.Any, UseLocalization = true }))
.Build()
.Run();
- Initialize localization by loading the
LocalizedServiceStartupinstead ofServiceStartupinProgram.csfor you Service project.
WebHost.CreateDefaultBuilder(args).UseStartup<LocalizedServiceStartup>().UseStartupModule<TransactionsServiceModule>();
This will initialize our custom localization functionality for selected area.
App locale files¶
- Add global locale files to your Api and Service projects.
Link app-locales folder from your Api and Service *.csproj
<ItemGroup>
<Content Include="..\..\app-locales\*" CopyToPublishDirectory="PreserveNewest" Link="app-locales\%(Filename)%(Extension)" />
</ItemGroup>
This adds the global scope of translations to your project(s) and you will notice that a new folder has appeared in your project.
Minority.Transactions.Api
# - Connected Services
# - Dependencies
# - Properties
- app-locales
- en.json
- es.json
# - charts
# - wwwroot
# - Program.cs
# - web.config
- Add the local scope to your to your Api and Service projects if it exists. Not all areas will have a local scope.
<ItemGroup>
<Content Include="..\..\app-locales\minority-transactions\*" CopyToPublishDirectory="PreserveNewest" Link="app-locales\minority-transactions\%(Filename)%(Extension)" />
</ItemGroup>
This adds the local scope of translations to your project(s).
Minority.Transactions.Api
# - Connected Services
# - Dependencies
# - Properties
- app-locales
# - en.json
# - es.json
- minority-transactions
- minority-transactions.en.json
- minority-transactions.es.json
# - charts
# - wwwroot
# - Program.cs
# - web.config
Translation files are included in your project files as Content. When the build pipeline in Azure publish projects, the required files will be automatically included in the deploy package.
Locales folder structure¶
On the file system of your local computer you will see the following file structure for our app-locales.
Minority
# - app-config
- app-locales
# global scope
- en.json
- es.json
# local scope
- minority-transactions
- minority-transactions.en.json
- minority-transactions.es.json
Crowdin translations¶
Minority Bank translations are integrated with Crowdin. The project configuration can be found in the crowdin.yml file.
English is master language and is added directly to the project. The English source files are then uploaded to Crowdin for translation. Once translated, we download the translated files to the project.
You can use the CLI tool to upload and download translations from Crowdin.
Install the Crowdin CLI tool from here.
Open Powershell in the following location: C:\Projects\RebtelNetCore\Minority\
Upload Sources¶
> crowdin upload sources
Download Translations¶
> crowdin download translations
Note: Don't edit translated files locally as they will be overwritten once we download translations.