示例#1
0
 /// <summary>
 /// Initialize a new instance of <see cref="XStringLocalizer{TResource}"/>
 /// </summary>
 /// <param name="cache"></param>
 /// <param name="translatorFactory"></param>
 /// <param name="provider"></param>
 /// <param name="loggerFactory"></param>
 /// <param name="localizationOptions"></param>
 /// <param name="options"></param>
 public XStringLocalizer(ExpressMemoryCache cache,
                         ITranslatorFactory translatorFactory,
                         IXResourceProvider provider,
                         IOptions <XLocalizerOptions> options,
                         IOptions <RequestLocalizationOptions> localizationOptions,
                         ILoggerFactory loggerFactory)
 {
     _cache        = cache;
     _translator   = translatorFactory.Create();
     _provider     = provider;
     _options      = options.Value;
     _transCulture = options.Value.TranslateFromCulture ?? localizationOptions.Value.DefaultRequestCulture.Culture.Name;
     _logger       = loggerFactory.CreateLogger <XStringLocalizer <TResource> >();
 }
 /// <summary>
 /// Register all XLocalization services...
 /// </summary>
 /// <typeparam name="TResource">Resource file type</typeparam>
 /// <typeparam name="TTranslator">Translation service type</typeparam>
 /// <param name="builder"></param>
 /// <returns></returns>
 public static IMvcBuilder AddXLocalizer <TResource, TTranslator>(this IMvcBuilder builder)
     where TResource : class
     where TTranslator : ITranslator
 {
     return(builder.AddXLocalizer <TResource, TTranslator>(o => o = new XLocalizerOptions()));
 }