Пример #1
0
 public PostgresTranslationStore(TranslationOptions options) : base(options)
 {
     GetByKeyQuery =
         @$ "SELECT * FROM {SchemeName}." "{TableName}" " WHERE " "Key" " = @Key AND " "Culture" " = @Culture ";
     InsertQuery =
         @$ "INSERT INTO {SchemeName}." "{TableName}" " (" "Key" "," "Value" "," "Culture" ") VALUES (@Key,@Value,@Culture)";
 }
 public static TranslationStore MapProviderToTranslationStore(TranslationOptions options)
 {
     return(options.Provider switch
     {
         TranslationStoreProvider.Postgres => new PostgresTranslationStore(options),
         _ => throw new ArgumentOutOfRangeException()
     });
Пример #3
0
        protected TranslationStore(TranslationOptions options)
        {
            TranslationOptions = options;
            if (TranslationOptions == null)
            {
                throw new ArgumentNullException(nameof(TranslationOptions),
                                                "To Use Translation, You need to register TranslationOptions");
            }

            var tableAttribute =
                (TableAttribute)typeof(Translation).GetCustomAttribute(typeof(TableAttribute));

            SchemeName = tableAttribute?.Schema;
            TableName  = tableAttribute?.Name;
            InitializeAsync().GetAwaiter().GetResult();
        }
Пример #4
0
 public Translator(IServiceProvider serviceProvider)
 {
     _options          = serviceProvider.GetRequiredService <TranslationOptions>();
     _translationStore = TranslationStoreMapper.MapProviderToTranslationStore(_options);
     _memoryCache      = serviceProvider.GetRequiredService <IMemoryCache>();
 }
Пример #5
0
 public TranslationOptionsBuilder()
 {
     _translationOptions = new TranslationOptions();
 }