LocalTextRegistry Class

[namespace: Serenity.Localization, assembly: Serenity.Core]

This class is the embedded, default implementation of ILocalTextRegistry interface.

  1. public class LocalTextRegistry : ILocalTextRegistry
  2. {
  3. public void Add(string languageID, string key, string text);
  4. public string TryGet(string languageID, string key);
  5. public void SetLanguageFallback(string languageID, string languageFallbackID);
  6. public void AddPending(string languageID, string key, string text);
  7. public string TryGet(string languageID, string textKey, bool isApprovalMode);
  8. public Dictionary<string, string> GetAllAvailableTextsInLanguage(
  9. string languageID, bool pending);
  10. }

Add and TryGet implements corresponding methods in ILocalTextRegistry interface.

LocalTextRegistry.SetLanguageFallback Method

Sets language fallback for specified language.

  1. var registry = (LocalTextRegistry)(Dependency.Resolve<ILocalTextRegistry>());
  2. registry.SetLanguageFallback('en-UK', 'en-US');
  3. // from now on if a translation is not found in "en-UK" language,
  4. // it will be looked up in "en-US" language first, followed by "en".

More information about language fallbacks can be found in relevant section.

Registering LocalTextRegistry as Provider

This is usually done in your application start method:

  1. var registrar = Dependency.Resolve<IDependencyRegistrar>();
  2. registrar.RegisterInstance<ILocalTextRegistry>(new LocalTextRegistry());

CommonInitialization.Run or CommonInitialization.InitializeLocalTexts methods also register a LocalTextRegistry instance as the ILocalTextRegistry provider, if none is already registered.