meta info

Best Practices To Get The Best From XLocalizer

Here are the recommended steps for developers to follow to achive the best performance and results from XLocalizer. However, depending on your setup and project you may follow different steps according to your requirements.

  1. Use XML or DB as resource provider.
  2. Register any supported online translation service.
  3. While in development mode, disable AutoTranslate, AutoAddKeys and UseExpressMemoryCache on XLocalizer options.
ops.AutoTranslate = false;
ops.AutoAddKeys = false;
ops.UseExpressMemoryCache = false;

The reasone why: during development many texts are subject to change, so you don't need to translate and add unnessary keys to the resource files.

  1. When you are sure that all the texts or most of them are fixed, enable AutoTranslate, AutoAddKeys and keep UseExpressMemoryCache disabled till all translation are done, saved and validated.
ops.AutoTranslate = true;
ops.AutoAddKeys = true;
ops.UseExpressMemoryCache = false;
  1. Run the app and switch to all available cultures till you are sure that all pages are visited. So XLocalizer can add all keys and translations to the resource files/db.
  2. (recommended) After all translations are done correctly, you can enable UseExpressMemoryCache in XLocalizer options; this will cache localized keys in memory for faster access.
  3. (highly recommended) Always review the auto translated texts, specifically the ones with html content or placeholders e.g. The field {0} is required.. It could happen that some translation engines may discard formatting placeholders and return a text without {0} or with wrong html codes, and this may cause unexpected results or errors if not fixed manually.
  4. (optional) Disable AutoTranslate and AutoAddKeys in XLocalizer options after you are sure all texts are localized.
  5. (optional) if you want to use RESX as resource files for localization in production, you can use the built-in export module to export the localized keys to .resx files.
  1. Add a star to XLocalizer in github :) GitHub Stars

Recommendation for XLocalizer.DB:

The default DbContext lifetime is Scoped, and XLocalizer.DB requires a Transient lifetime for the DbContext. So, it is better to keep localization DbContext separate than the application DbContext. In other words, use one db for XLocalizer services and another one for your application.

For more details see How to use multiple DbContexts in Asp.Net Core App.