/// <summary>
        /// Initializes a new instance of the <see cref="TemplateEngineLanguageGenerator"/> class.
        /// </summary>
        /// <param name="lgText">lg template text.</param>
        /// <param name="id">optional label for the source of the templates (used for labeling source of template errors).</param>
        /// <param name="resourceMapping">template resource loader delegate (locale) -> <see cref="ImportResolverDelegate"/>.</param>
        public TemplateEngineLanguageGenerator(string lgText, string id, Dictionary <string, IList <IResource> > resourceMapping)
        {
            this.Id        = id ?? DEFAULTLABEL;
            var(_, locale) = LGResourceLoader.ParseLGFileName(id);
            var importResolver = LanguageGeneratorManager.ResourceExplorerResolver(locale, resourceMapping);

            this.lg = LanguageGeneration.Templates.ParseText(lgText ?? string.Empty, Id, importResolver);
        }
コード例 #2
0
        public TemplateEngineLanguageGenerator(string lgText, string id, Dictionary <string, IList <Resource> > resourceMapping)
        {
            Id             = id ?? DEFAULTLABEL;
            var(_, locale) = LGResourceLoader.ParseLGFileName(id);
            var importResolver = LanguageGeneratorManager.ResourceExplorerResolver(locale, resourceMapping);
            var lgResource     = new LGResource(Id, Id, lgText ?? string.Empty);

            _lg = new Lazy <Task <LanguageGeneration.Templates> >(() => Task.FromResult(LanguageGeneration.Templates.ParseResource(lgResource, importResolver)));
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="TemplateEngineLanguageGenerator"/> class.
        /// </summary>
        /// <param name="filePath">lg template file absolute path.</param>
        /// <param name="resourceMapping">template resource loader delegate (locale) -> <see cref="ImportResolverDelegate"/>.</param>
        public TemplateEngineLanguageGenerator(string filePath, Dictionary <string, IList <IResource> > resourceMapping)
        {
            filePath = PathUtils.NormalizePath(filePath);
            this.Id  = Path.GetFileName(filePath);

            var(_, locale) = LGResourceLoader.ParseLGFileName(Id);
            var importResolver = LanguageGeneratorManager.ResourceExplorerResolver(locale, resourceMapping);

            this.lg = LanguageGeneration.Templates.ParseFile(filePath, importResolver);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="TemplateEngineLanguageGenerator"/> class.
        /// </summary>
        /// <param name="resource">Resource.</param>
        /// <param name="resourceMapping">template resource loader delegate (locale) -> <see cref="ImportResolverDelegate"/>.</param>
        public TemplateEngineLanguageGenerator(Resource resource, Dictionary <string, IList <Resource> > resourceMapping)
        {
            this.Id = resource.Id;

            var(_, locale) = LGResourceLoader.ParseLGFileName(Id);
            var importResolver = LanguageGeneratorManager.ResourceExplorerResolver(locale, resourceMapping);
            var content        = resource.ReadTextAsync().GetAwaiter().GetResult();
            var lgResource     = new LGResource(Id, resource.FullName, content);

            this.lg = LanguageGeneration.Templates.ParseResource(lgResource, importResolver);
        }
コード例 #5
0
        public TemplateEngineLanguageGenerator(string filePath, Dictionary <string, IList <Resource> > resourceMapping)
        {
            filePath = PathUtils.NormalizePath(filePath);
            Id       = Path.GetFileName(filePath);

            var(_, locale) = LGResourceLoader.ParseLGFileName(Id);
            var importResolver = LanguageGeneratorManager.ResourceExplorerResolver(locale, resourceMapping);
            var resource       = new LGResource(Id, filePath, File.ReadAllText(filePath));

            _lg = new Lazy <Task <LanguageGeneration.Templates> >(() => Task.FromResult(LanguageGeneration.Templates.ParseResource(resource, importResolver)));
        }
コード例 #6
0
        /// <summary>
        /// Loads language generation templates asynchronously.
        /// </summary>
        /// <param name="resource">Resource.</param>
        /// <param name="resourceMapping">template resource loader delegate (locale) -> <see cref="ImportResolverDelegate"/>.</param>
        /// <returns>The loaded language generation templates.</returns>
        private async Task <LanguageGeneration.Templates> CreateTemplatesAsync(Resource resource, Dictionary <string, IList <Resource> > resourceMapping)
        {
            var(_, locale) = LGResourceLoader.ParseLGFileName(Id);
            var importResolver = LanguageGeneratorManager.ResourceExplorerResolver(locale, resourceMapping);
            var content        = await resource.ReadTextAsync().ConfigureAwait(false);

            var lgResource = new LGResource(Id, resource.FullName, content);
            var lg         = LanguageGeneration.Templates.ParseResource(lgResource, importResolver);

            RegisterSourcemap(lg, resource);
            return(lg);
        }
コード例 #7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TemplateEngineLanguageGenerator"/> class.
        /// </summary>
        /// <param name="filePath">lg template file absolute path.</param>
        /// <param name="resourceMapping">template resource loader delegate (locale) -> <see cref="ImportResolverDelegate"/>.</param>
        public TemplateEngineLanguageGenerator(string filePath, Dictionary <string, IList <IResource> > resourceMapping)
        {
            filePath = PathUtils.NormalizePath(filePath);
            this.Id  = Path.GetFileName(filePath);

            var(_, locale) = MultiLanguageResourceLoader.ParseLGFileName(Id);
            var fallbackLocale = MultiLanguageResourceLoader.FallbackLocale(locale, resourceMapping.Keys.ToList());

            foreach (var mapping in resourceMapping)
            {
                // if no locale present in id, enumarate every locale found
                // if locale is present, use that one
                if (string.Equals(fallbackLocale, string.Empty) || string.Equals(fallbackLocale, mapping.Key))
                {
                    var engine = new TemplateEngine().AddFile(filePath, LanguageGeneratorManager.ResourceExplorerResolver(mapping.Key, resourceMapping));
                    multiLangEngines.Add(mapping.Key, engine);
                }
            }
        }
コード例 #8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TemplateEngineLanguageGenerator"/> class.
        /// </summary>
        /// <param name="lgText">lg template text.</param>
        /// <param name="id">optional label for the source of the templates (used for labeling source of template errors).</param>
        /// <param name="resourceMapping">template resource loader delegate (locale) -> <see cref="ImportResolverDelegate"/>.</param>
        public TemplateEngineLanguageGenerator(string lgText, string id, Dictionary <string, IList <IResource> > resourceMapping)
        {
            this.Id        = id ?? DEFAULTLABEL;
            var(_, locale) = MultiLanguageResourceLoader.ParseLGFileName(id);
            var fallbackLocale = MultiLanguageResourceLoader.FallbackLocale(locale, resourceMapping.Keys.ToList());

            foreach (var mapping in resourceMapping)
            {
                // if no locale present in id, enumarate every locale found
                // if locale is present, use that one
                if (string.Equals(fallbackLocale, string.Empty) || string.Equals(fallbackLocale, mapping.Key))
                {
                    var engine = new TemplateEngine().AddText(lgText ?? string.Empty, Id, LanguageGeneratorManager.ResourceExplorerResolver(mapping.Key, resourceMapping));
                    multiLangEngines.Add(mapping.Key, engine);
                }
            }
        }
コード例 #9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TemplateEngineLanguageGenerator"/> class.
 /// </summary>
 /// <param name="lgText">lg template text.</param>
 /// <param name="id">optional label for the source of the templates (used for labeling source of template errors).</param>
 /// <param name="resourceMapping">template resource loader delegate (locale) -> <see cref="ImportResolverDelegate"/>.</param>
 public TemplateEngineLanguageGenerator(string lgText, string id, Dictionary <string, IList <IResource> > resourceMapping)
 {
     this.Id = id ?? DEFAULTLABEL;
     foreach (var mappingItem in resourceMapping)
     {
         var engine = new TemplateEngine().AddText(lgText ?? string.Empty, Id, LanguageGeneratorManager.ResourceExplorerResolver(mappingItem.Key, resourceMapping));
         multiLangEngines.Add(mappingItem.Key, engine);
     }
 }