/// <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); }
/// <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))); }
/// <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); }
public I18NServiceCollection(IServiceCollection services = null, I18NOptions options = null) { _services = services ?? new ServiceCollection(); _options = options ?? new I18NOptions(); _languageManager = new LanguageManager(); AfterBuild(UpdateStaticResolver); }
/// <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))); }
/// <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))); }
/// <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))); }
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); }
/// <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(); }
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)); }
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)); }
/// <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); }
/// <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(); }
/// <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(); }