LocalTextRegistry 类

[命名空间: Serenity.Localization, 程序集: Serenity.Core]

此类是 ILocalTextRegistry 接口可嵌入的默认实现。

  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 和 TryGet 实现了 ILocalTextRegistry 接口的相应方法。

LocalTextRegistry.SetLanguageFallback 方法

为语言回退(language fallback)设置指定的语言。

  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".

可以在有关章节中找到有关语言回退的详细信息。

注册 LocalTextRegistry 作为提供者

通常在应用程序启动方法中做此操作:

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

如果没有已注册的提供者,CommonInitialization.RunCommonInitialization.InitializeLocalTexts 方法将注册一个 LocalTextRegistry 实例作为 ILocalTextRegistry 提供者。