Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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);
        }
        private StringLocalizerCacheItem CreateStringLocalizerCacheItem(LocalizationResource resource)
        {
            foreach (var globalContributor in RocketLocalizationOptions.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 RocketDictionaryBasedStringLocalizer(
                           resource,
                           resource.BaseResourceTypes.Select(Create).ToList()
                           )
                       ));
        }
 public RocketDictionaryBasedStringLocalizer(LocalizationResource resource, List <IStringLocalizer> baseLocalizers)
 {
     Resource       = resource;
     BaseLocalizers = baseLocalizers;
 }
 public LocalizationResourceInitializationContext(LocalizationResource resource, IServiceProvider serviceProvider)
 {
     Resource        = resource;
     ServiceProvider = serviceProvider;
 }