Exemple #1
0
        public static IServiceCollection AddGlobalization(this IServiceCollection services,
                                                          [NotNull] string connectionString,
                                                          [NotNull] string defaultCulture        = "tr-TR",
                                                          TranslationStoreProvider storeProvider = TranslationStoreProvider.Postgres)
        {
            var options = new TranslationOptionsBuilder()
                          .SetProvider(storeProvider)
                          .SetConnectionString(connectionString)
                          .SetDefaultCulture(defaultCulture)
                          .Build();

            services.AddSingleton(options);

            services.AddScoped(typeof(TranslationStore),
                               TranslationStoreMapper.MapProviderToSystemType(options.Provider));
            services.AddScoped <ITranslator, Translator>();
            services.AddMemoryCache(cacheOptions => { });
            return(services);
        }
Exemple #2
0
 public Translator(IServiceProvider serviceProvider)
 {
     _options          = serviceProvider.GetRequiredService <TranslationOptions>();
     _translationStore = TranslationStoreMapper.MapProviderToTranslationStore(_options);
     _memoryCache      = serviceProvider.GetRequiredService <IMemoryCache>();
 }