We use Localization to return the equivalents of string values, for example exception messages, in the region and language of the user's choice.
We register the localization with .AddLocalization and use it with
.UseRequestLocalization.
We provide support for cultures like en-US, tr-TR which we often use in
configurations and we use culture providers by default.
Warning
For localization to work correctly in api requests, SupportedUICultures must
be given next to SupportedCultures.
See Program.cs to see sample configurations and how to add a custom provider.
We use IStringLocalizerFactory to inject localization with 2 different
methods. Since we use similar resource files with the project name, we need to
use IStringLocalizerFactory.Create().
See Using Localization Factory for example usage.
We are not using custom provider for now, but if needed, we can write our own
provider and make region selection according to the data we want via
HttpContext.
See Custom Provider for a sample custom provider.
We use .restext files as resource files for ease of writing and updating.
Such files need to be recognized by the system in order to be used, so they
should be added as EmbeddedResource from .csproj. See
Localization.csproj here for
an example.