public static LocalizationResource AddVirtualJson <TResource>(
            [NotNull] this LocalizationResourceDictionary resourceDictionary,
            [NotNull] string defaultCultureName,
            [NotNull] string virtualPath)
        {
            Check.NotNull(resourceDictionary, nameof(resourceDictionary));
            Check.NotNull(defaultCultureName, nameof(defaultCultureName));
            Check.NotNull(virtualPath, nameof(virtualPath));

            virtualPath = virtualPath.EnsureStartsWith('/');

            var resourceType = typeof(TResource);

            if (resourceDictionary.ContainsKey(resourceType))
            {
                throw new AbpException("There is already a resource with given type: " + resourceType.AssemblyQualifiedName);
            }

            return(resourceDictionary[resourceType] = new LocalizationResource(
                       resourceType,
                       defaultCultureName,
                       new JsonEmbeddedFileLocalizationDictionaryProvider(
                           virtualPath
                           )
                       ));
        }
Пример #2
0
        private AbpDictionaryBasedStringLocalizer CreateAbpStringLocalizer(LocalizationResource resource)
        {
            resource.Initialize(_serviceProvider); //TODO: Use CreateScope?

            return(new AbpDictionaryBasedStringLocalizer(
                       resource,
                       resource.BaseResourceTypes.Select(Create).ToList()
                       ));
        }
        public static LocalizationResource InheritFrom([NotNull] this LocalizationResource resource, [NotNull] params Type[] baseResourceTypes)
        {
            Check.NotNull(resource, nameof(resource));
            Check.NotNull(baseResourceTypes, nameof(baseResourceTypes));

            resource.BaseResourceTypes.AddRange(baseResourceTypes);

            return(resource);
        }
Пример #4
0
        public static LocalizationResource AddDynamic(
            [NotNull] this LocalizationResource localizationResource)
        {
            Check.NotNull(localizationResource, nameof(localizationResource));

            localizationResource.Contributors.Add(
                new DynamicLocalizationResourceContributor(
                    localizationResource.ResourceName));

            return(localizationResource);
        }
        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);
        }
Пример #7
0
        private StringLocalizerCacheItem CreateStringLocalizerCacheItem(LocalizationResource resource)
        {
            foreach (var globalContributor in AbpLocalizationOptions.GlobalContributors)
            {
                resource.Contributors.Add((ILocalizationResourceContributor)Activator.CreateInstance(globalContributor));
            }

            var context = new LocalizationResourceInitializationContext(resource, ServiceProvider);

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

            return(new StringLocalizerCacheItem(
                       new AbpDictionaryBasedStringLocalizer(
                           resource,
                           resource.BaseResourceTypes.Select(Create).ToList()
                           )
                       ));
        }
 public AbpDictionaryBasedStringLocalizer(LocalizationResource resource, List <IStringLocalizer> baseLocalizers)
 {
     Resource       = resource;
     BaseLocalizers = baseLocalizers;
 }
 public LocalizationResourceInitializationContext(LocalizationResource resource, IServiceProvider serviceProvider)
 {
     Resource        = resource;
     ServiceProvider = serviceProvider;
 }
 private static bool ShouldIgnoreType(LocalizationResource resource)
 {
     return(resource.Contributors.Exists(x => x is DynamicLocalizationResourceContributor));
 }