/// <summary>
        /// Register Cosmos.I18N for autofac
        /// </summary>
        /// <param name="services"></param>
        /// <param name="optionAct"></param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException"></exception>
        public static ContainerBuilder RegisterCosmosLocalization(this ContainerBuilder services, Action <I18NOptions> optionAct)
        {
            if (services is null)
            {
                throw new ArgumentNullException(nameof(services));
            }

            var options = new I18NOptions();

            optionAct?.Invoke(options);

            var translationManager = new TranslationManager();
            var translationSetter  = (ITranslationManSetter)translationManager;

            foreach (var package in options.TranslationPackages)
            {
                var translationPackage = package.Value;
                translationSetter.RegisterPackage(translationPackage);
                services.RegisterInstance(translationPackage).SingleInstance();
            }

            services.RegisterInstance(translationManager).SingleInstance();
            services.RegisterInstance(translationManager).As <ITranslationManager>().SingleInstance();
            services.RegisterType <TextProvider>().As <ITextProvider>().SingleInstance();
            services.RegisterType <AutofacLanguageServiceProvider>().As <ILanguageServiceProvider>().SingleInstance();
            services.Register(provider => new TranslationProcessor(
                                  provider.Resolve <IEnumerable <ITranslatePackage> >()
                                  .ToDictionary(package => package.PackageKey.GetHashCode())))
            .SingleInstance();
            services.Register(StaticProviderHack.New).SingleInstance();

            return(services);
        }
예제 #2
0
 /// <summary>
 /// Add Cosmos.I18N
 /// </summary>
 /// <param name="services"></param>
 /// <param name="optionAct"></param>
 /// <returns></returns>
 /// <exception cref="ArgumentNullException"></exception>
 public static II18NServiceCollection AddCosmosLocalization(this IServiceCollection services, Action <I18NOptions> optionAct = null)
 {
     if (services is null)
     {
         throw new ArgumentNullException(nameof(services));
     }
     return(new StandardI18NServiceCollection(services, I18NOptions.Create(optionAct)));
 }
예제 #3
0
        /// <summary>
        /// I18N service collection
        /// </summary>
        /// <param name="services"></param>
        /// <param name="options"></param>
        public I18NServiceCollection(IServiceCollection services = null, I18NOptions options = null)
        {
            _services           = services ?? new ServiceCollection();
            _options            = I18NOptions.Create(options);
            _translationManager = new TranslationManager();

            AfterBuild(UpdateStaticResolver);
        }
예제 #4
0
        public I18NServiceCollection(IServiceCollection services = null, I18NOptions options = null)
        {
            _services        = services ?? new ServiceCollection();
            _options         = options ?? new I18NOptions();
            _languageManager = new LanguageManager();

            AfterBuild(UpdateStaticResolver);
        }
예제 #5
0
        /// <summary>
        /// Register Cosmos.I18N for Autofac
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="optionAct"></param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException"></exception>
        public static II18NServiceCollection RegisterCosmosLocalization(this ContainerBuilder builder, Action <I18NOptions> optionAct = null)
        {
            if (builder is null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            return(new AutofacServiceCollection(builder, I18NOptions.Create(optionAct)));
        }
예제 #6
0
        /// <summary>
        /// Register Cosmos.I18N for NCC AspectCore
        /// </summary>
        /// <param name="services"></param>
        /// <param name="optionAct"></param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException"></exception>
        public static II18NServiceCollection RegisterCosmosLocalization(this IServiceContext services, Action <I18NOptions> optionAct = null)
        {
            if (services is null)
            {
                throw new ArgumentNullException(nameof(services));
            }

            return(new AspectCoreI18NServiceCollection(services, I18NOptions.Create(optionAct)));
        }
예제 #7
0
        /// <summary>
        /// Add Cosmos.I18N, and start to config the i18n service.
        /// </summary>
        /// <param name="register"></param>
        /// <param name="optionAct"></param>
        /// <typeparam name="TRegister"></typeparam>
        /// <typeparam name="TService"></typeparam>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException"></exception>
        public static II18NServiceCollection AddInternationalizationService <TRegister, TService>(this TRegister register, Action <I18NOptions> optionAct = null)
            where TRegister : DependencyProxyRegister <TService>
        {
            if (register is null)
            {
                throw new ArgumentNullException(nameof(register));
            }

            return(new DefaultI18NServiceCollection <TRegister, TService>(register, I18NOptions.Create(optionAct)));
        }
예제 #8
0
 public static string Combine(I18NOptions options, string path, bool referenceToBasePath)
 {
     if (options == null)
     {
         throw new ArgumentNullException(nameof(options));
     }
     if (string.IsNullOrWhiteSpace(path))
     {
         throw new ArgumentNullException(nameof(path));
     }
     return(referenceToBasePath
         ? Path.Combine(options.PathBase, options.PathSegment, path)
         : path);
 }
        public static IServiceCollection AddCosmosLocalization(this IServiceCollection services, Action <I18NOptions> optionAct)
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

            var options = new I18NOptions();

            optionAct?.Invoke(options);

//            var languageManager = new LanguageManager();
//            foreach (var lang in options.RegisteredLanguages) languageManager.RegisterUsedLangage(lang);
//            foreach (var package in options.LanguagePackages) services.AddSingleton(package.Value);

//            services.AddSingleton(languageManager);
            services.AddSingleton <ILanguageServiceProvider, AspNetCoreLanguageServiceProvider>();
            services.AddSingleton(provider => new TranslationProcessor(provider.GetServices <ILanguagePackage>().ToDictionary(package => package.Language)));
            services.AddSingleton(provider => new StaticProviderHack(provider.GetRequiredService <ILanguageServiceProvider>()));

            return(services);
        }
예제 #10
0
 /// <summary>
 /// I18N service collection
 /// </summary>
 /// <param name="register"></param>
 /// <param name="options"></param>
 public DefaultI18NServiceCollection(TRegister register, I18NOptions options = null)
 {
     _register           = register ?? throw new ArgumentNullException(nameof(register));
     _options            = I18NOptions.Create(options);
     _translationManager = new TranslationManager();
 }
예제 #11
0
        public static IEnumerable <string> GetSeveralPathList(I18NOptions options, string path)
        {
            var di = new DirectoryInfo(Path.Combine(options.PathBase, options.PathSegment));

            return(di.GetFiles(path, SearchOption.AllDirectories).Select(x => x.FullName));
        }
예제 #12
0
        private static void RegisterAllPackages(this II18NServiceCollection services, I18NOptions options)
        {
            var translationManager = new TranslationManager();
            var translationSetter  = (ITranslationManSetter)translationManager;

            foreach (var package in options.TranslationPackages)
            {
                var translationPackage = package.Value;
                translationSetter.RegisterPackage(translationPackage);
                services.AddDependency(register => register.AddSingleton(translationPackage));
            }


            services.AddDependency(register => register.AddSingleton(translationManager));
            services.AddDependency(register => register.AddSingleton <ITranslationManager>(translationManager));
        }
예제 #13
0
 /// <summary>
 /// I18N service collection
 /// </summary>
 /// <param name="services"></param>
 /// <param name="options"></param>
 public ConsoleI18NServiceCollection(IServiceContext services = null, I18NOptions options = null)
     : base(new AspectCoreProxyRegister(services ?? new ServiceContext()), options)
 {
     AfterBuild(UpdateStaticResolver);
 }
예제 #14
0
 /// <summary>
 /// I18N service collection
 /// </summary>
 /// <param name="services"></param>
 /// <param name="options"></param>
 public I18NServiceCollection(IServiceContext services = null, I18NOptions options = null)
     : base(services ?? new ServiceContext(), options)
 {
     AfterBuild(UpdateStaticResolver);
 }
 /// <summary>
 /// I18N service collection
 /// </summary>
 /// <param name="services"></param>
 /// <param name="options"></param>
 public AutofacServiceCollection(ContainerBuilder services = null, I18NOptions options = null)
 {
     _services           = new AutofacProxyRegister(services);
     _options            = I18NOptions.Create(options);
     _translationManager = new TranslationManager();
 }
예제 #16
0
 /// <summary>
 /// I18N service collection
 /// </summary>
 /// <param name="services"></param>
 /// <param name="options"></param>
 public StandardI18NServiceCollection(IServiceCollection services = null, I18NOptions options = null)
 {
     _services           = new MicrosoftProxyRegister(services ?? new ServiceCollection());
     _options            = I18NOptions.Create(options);
     _translationManager = new TranslationManager();
 }
 /// <summary>
 /// I18N service collection
 /// </summary>
 /// <param name="services"></param>
 /// <param name="options"></param>
 public AspectCoreI18NServiceCollection(IServiceContext services = null, I18NOptions options = null)
 {
     _services           = new AspectCoreProxyRegister(services);
     _options            = I18NOptions.Create(options);
     _translationManager = new TranslationManager();
 }