public static LocalizationResource AddVirtualJson(
            [NotNull] this LocalizationResource localizationResource,
            [NotNull] string virtualPath)
        {
            Check.NotNull(localizationResource, nameof(localizationResource));
            Check.NotNull(virtualPath, nameof(virtualPath));

            localizationResource.Contributors.Add(new JsonVirtualFileLocalizationResourceContributor(
                                                      virtualPath.EnsureStartsWith('/')
                                                      ));

            return(localizationResource);
        }
        public static LocalizationResource AddBaseTypes(
            [NotNull] this LocalizationResource localizationResource,
            [NotNull] params Type[] types)
        {
            Check.NotNull(localizationResource, nameof(localizationResource));
            Check.NotNull(types, nameof(types));

            foreach (var type in types)
            {
                localizationResource.BaseResourceTypes.AddIfNotContains(type);
            }

            return(localizationResource);
        }
예제 #3
0
        private StringLocalizerCacheItem CreateStringLocalizerCacheItem(LocalizationResource resource)
        {
            foreach (var globalContributor in PlusLocalizationOptions.GlobalContributors)
            {
                resource.Contributors.Add((ILocalizationResourceContributor)Activator.CreateInstance(globalContributor));
            }

            using (var scope = ServiceProvider.CreateScope())
            {
                var context = new LocalizationResourceInitializationContext(resource, scope.ServiceProvider);

                foreach (var contributor in resource.Contributors)
                {
                    contributor.Initialize(context);
                }
            }

            return(new StringLocalizerCacheItem(
                       new PlusDictionaryBasedStringLocalizer(
                           resource,
                           resource.BaseResourceTypes.Select(Create).ToList()
                           )
                       ));
        }
 public PlusDictionaryBasedStringLocalizer(LocalizationResource resource, List <IStringLocalizer> baseLocalizers)
 {
     Resource       = resource;
     BaseLocalizers = baseLocalizers;
 }
 public LocalizationResourceInitializationContext(LocalizationResource resource, IServiceProvider serviceProvider)
 {
     Resource        = resource;
     ServiceProvider = serviceProvider;
 }