Esempio n. 1
0
 /// <summary>
 /// Localizes all properties on each <see cref="ILocalizable"/> item in a collection with current language and depth=<see cref="LocalizationDepth.Shallow"/> and getOriginalValueIfNotFound=true
 /// </summary>
 /// <typeparam name="TEntity"></typeparam>
 /// <param name="entities"></param>
 /// <param name="cancellationToken">A System.Threading.CancellationToken to observe while waiting for the task to complete.</param>
 /// <returns>Return localized entitis</returns>
 public static async Task <IEnumerable <TEntity> > LocalizeAsync <TEntity>(this IEnumerable <TEntity> entities,
                                                                           CancellationToken cancellationToken = default)
     where TEntity : class, ILocalizable
 {
     using (var serviceScope = ApplicationServiceProvider.CreateServiceScope())
     {
         return(await serviceScope.ServiceProvider.GetRequiredService <IEntityLocalizer>()
                .LocalizeAsync(entities, cancellationToken));
     }
 }
Esempio n. 2
0
 /// <summary>
 /// Save localized entity with depth=<see cref="LocalizationDepth.Shallow"/>
 /// </summary>
 /// <typeparam name="TEntity">Type</typeparam>
 /// <param name="entity">Entity</param>
 /// <param name="languageId">Language identifier</param>
 public static async Task SaveLocalizedAsync <TEntity>(this TEntity entity,
                                                       int languageId,
                                                       CancellationToken cancellationToken = default)
     where TEntity : class, ILocalizable
 {
     using (var serviceScope = ApplicationServiceProvider.CreateServiceScope())
     {
         await serviceScope.ServiceProvider.GetRequiredService <IEntityLocalizer>()
         .SaveLocalizedAsync(entity, languageId, cancellationToken);
     }
 }
Esempio n. 3
0
 /// <summary>
 /// Find localized value with getOriginalValueIfNotFound=true
 /// </summary>
 /// <typeparam name="TEntity">Type</typeparam>
 /// <typeparam name="TPropType">TPropType</typeparam>
 /// <param name="entity">Entity</param>
 /// <param name="keySelector">Key selector</param>
 /// <returns>return localized value as TPropType</returns>
 public static async Task <TPropType> GetLocalizedValueAsync <TEntity, TPropType>(this TEntity entity,
                                                                                  Expression <Func <TEntity, TPropType> > keySelector,
                                                                                  CancellationToken cancellationToken = default)
     where TEntity : class, ILocalizable
 {
     using (var serviceScope = ApplicationServiceProvider.CreateServiceScope())
     {
         return(await serviceScope.ServiceProvider.GetRequiredService <IEntityLocalizer>()
                .GetLocalizedValueAsync(entity, keySelector, cancellationToken));
     }
 }
Esempio n. 4
0
 /// <summary>
 /// Localizes all properties on an <see cref="ILocalizable"/> item with current language and depth=<see cref="LocalizationDepth.Shallow"/>
 /// </summary>
 /// <typeparam name="TEntity"></typeparam>
 /// <param name="entity"></param>
 /// <param name="getOriginalValueIfNotFound">A value indicating whether to return default value (if localized is not found)</param>
 /// <param name="cancellationToken">A System.Threading.CancellationToken to observe while waiting for the task to complete.</param>
 /// <returns>Return localized entity</returns>
 public static async Task <TEntity> LocalizeAsync <TEntity>(this TEntity entity,
                                                            bool getOriginalValueIfNotFound,
                                                            CancellationToken cancellationToken = default)
     where TEntity : class, ILocalizable
 {
     using (var serviceScope = ApplicationServiceProvider.CreateServiceScope())
     {
         return(await serviceScope.ServiceProvider.GetRequiredService <IEntityLocalizer>()
                .LocalizeAsync(entity, getOriginalValueIfNotFound, cancellationToken));
     }
 }
 /// <summary>
 /// Localizes all properties on an <see cref="ILocalizedModel{TModel, TEntity}"/> item with current language
 /// and depth=<see cref="LocalizationDepth.Shallow"/> and getOriginalValueIfNotFound=true
 /// </summary>
 /// <typeparam name="TModel"></typeparam>
 /// <typeparam name="TEntity"></typeparam>
 /// <param name="model"></param>
 /// <param name="cancellationToken">A System.Threading.CancellationToken to observe while waiting for the task to complete.</param>
 /// <returns>Return localized model</returns>
 public static async Task <TModel> LocalizeAsync <TModel, TEntity>(this ILocalizedModel <TModel, TEntity> model,
                                                                   CancellationToken cancellationToken = default)
     where TModel : class, ILocalizedModel <TModel, TEntity>
     where TEntity : class, ILocalizable
 {
     using (var serviceScope = ApplicationServiceProvider.CreateServiceScope())
     {
         return(await serviceScope.ServiceProvider.GetRequiredService <IModelLocalizer>()
                .LocalizeAsync(model, cancellationToken));
     }
 }
Esempio n. 6
0
 /// <summary>
 /// Localizes all properties on an <see cref="ILocalizable"/> item with specified language id and with getOriginalValueIfNotFound=true
 /// </summary>
 /// <typeparam name="TEntity"></typeparam>
 /// <param name="entity"></param>
 /// <param name="languageId">Language identifier</param>
 /// <param name="depth">Depth of localization</param>
 /// <param name="cancellationToken">A System.Threading.CancellationToken to observe while waiting for the task to complete.</param>
 /// <returns>Return localized entity</returns>
 public static async Task <TEntity> LocalizeAsync <TEntity>(this TEntity entity,
                                                            int languageId,
                                                            LocalizationDepth depth,
                                                            CancellationToken cancellationToken = default)
     where TEntity : class, ILocalizable
 {
     using (var serviceScope = ApplicationServiceProvider.CreateServiceScope())
     {
         return(await serviceScope.ServiceProvider.GetRequiredService <IEntityLocalizer>()
                .LocalizeAsync(entity, languageId, depth, cancellationToken));
     }
 }
 /// <summary>
 /// Localizes all properties on each <see cref="ILocalizedModel{TModel, TEntity}"/> item in a collection with current language
 /// and depth=<see cref="LocalizationDepth.Shallow"/>
 /// </summary>
 /// <typeparam name="TModel"></typeparam>
 /// <typeparam name="TEntity"></typeparam>
 /// <param name="models"></param>
 /// <param name="getOriginalValueIfNotFound">A value indicating whether to return default value (if localized is not found)</param>
 /// <param name="cancellationToken">A System.Threading.CancellationToken to observe while waiting for the task to complete.</param>
 /// <returns>Return localized models</returns>
 public static async Task <IEnumerable <TModel> > LocalizeAsync <TModel, TEntity>(IEnumerable <ILocalizedModel <TModel, TEntity> > models,
                                                                                  bool getOriginalValueIfNotFound,
                                                                                  CancellationToken cancellationToken = default)
     where TModel : class, ILocalizedModel <TModel, TEntity>
     where TEntity : class, ILocalizable
 {
     using (var serviceScope = ApplicationServiceProvider.CreateServiceScope())
     {
         return(await serviceScope.ServiceProvider.GetRequiredService <IModelLocalizer>()
                .LocalizeAsync(models, getOriginalValueIfNotFound, cancellationToken));
     }
 }
Esempio n. 8
0
 /// <summary>
 /// Save localized value
 /// </summary>
 /// <typeparam name="TEntity">Type</typeparam>
 /// <typeparam name="TPropType">TPropType</typeparam>
 /// <param name="entity">Entity</param>
 /// <param name="keySelector">Key selector</param>
 /// <param name="localeValue">Locale value</param>
 /// <param name="languageId">Language ID</param>
 public static async Task SaveLocalizedValueAsync <TEntity, TPropType>(this TEntity entity,
                                                                       Expression <Func <TEntity, TPropType> > keySelector,
                                                                       TPropType localeValue,
                                                                       int languageId,
                                                                       CancellationToken cancellationToken = default)
     where TEntity : class, ILocalizable
 {
     using (var serviceScope = ApplicationServiceProvider.CreateServiceScope())
     {
         await serviceScope.ServiceProvider.GetRequiredService <IEntityLocalizer>()
         .SaveLocalizedValueAsync(entity, keySelector, localeValue, languageId, cancellationToken);
     }
 }
Esempio n. 9
0
 /// <summary>
 /// Localizes all properties on each <see cref="ILocalizable"/> item in a collection with specified language id
 /// </summary>
 /// <typeparam name="TEntity"></typeparam>
 /// <param name="entities"></param>
 /// <param name="languageId">Language identifier</param>
 /// <param name="getOriginalValueIfNotFound">A value indicating whether to return default value (if localized is not found)</param>
 /// <param name="depth">Depth of localization</param>
 /// <param name="cancellationToken">A System.Threading.CancellationToken to observe while waiting for the task to complete.</param>
 /// <returns>Return localized entitis</returns>
 public static async Task <IEnumerable <TEntity> > LocalizeAsync <TEntity>(this IEnumerable <TEntity> entities,
                                                                           int languageId,
                                                                           bool getOriginalValueIfNotFound,
                                                                           LocalizationDepth depth,
                                                                           CancellationToken cancellationToken = default)
     where TEntity : class, ILocalizable
 {
     using (var serviceScope = ApplicationServiceProvider.CreateServiceScope())
     {
         return(await serviceScope.ServiceProvider.GetRequiredService <IEntityLocalizer>()
                .LocalizeAsync(entities, languageId, getOriginalValueIfNotFound, depth, cancellationToken));
     }
 }
 /// <summary>
 /// Save all localized properties of each LocalizedModel item in Locales collection property of model
 /// </summary>
 /// <typeparam name="TModel"></typeparam>
 /// <typeparam name="TEntity"></typeparam>
 /// <typeparam name="TLocalizedModel"></typeparam>
 /// <param name="entity"></param>
 /// <param name="model"></param>
 /// <param name="cancellationToken">A System.Threading.CancellationToken to observe while waiting for the task to complete.</param>
 /// <returns></returns>
 public static async Task SaveLocalesAsync <TModel, TEntity, TLocalizedModel>(this TEntity entity,
                                                                              ILocalizedModelForEdit <TModel, TEntity, TLocalizedModel> model,
                                                                              CancellationToken cancellationToken = default)
     where TModel : class, ILocalizedModelForEdit <TModel, TEntity, TLocalizedModel>
     where TEntity : class, ILocalizable
     where TLocalizedModel : class, ILocalizedLocaleModel
 {
     using (var serviceScope = ApplicationServiceProvider.CreateServiceScope())
     {
         await serviceScope.ServiceProvider.GetRequiredService <IModelLocalizer>()
         .SaveLocalesAsync(entity, model, cancellationToken);
     }
 }
 /// <summary>
 /// Localizes all properties on each <see cref="ILocalizedModel{TModel, TEntity}"/> item in a collection with specified language id and
 /// getOriginalValueIfNotFound=true
 /// </summary>
 /// <typeparam name="TModel"></typeparam>
 /// <typeparam name="TEntity"></typeparam>
 /// <param name="models"></param>
 /// <param name="languageId">Language identifier</param>
 /// <param name="depth">Depth of localization</param>
 /// <param name="cancellationToken">A System.Threading.CancellationToken to observe while waiting for the task to complete.</param>
 /// <returns>Return localized models</returns>
 public static async Task <IEnumerable <TModel> > LocalizeAsync <TModel, TEntity>(this IEnumerable <ILocalizedModel <TModel, TEntity> > models,
                                                                                  int languageId,
                                                                                  LocalizationDepth depth,
                                                                                  CancellationToken cancellationToken = default)
     where TModel : class, ILocalizedModel <TModel, TEntity>
     where TEntity : class, ILocalizable
 {
     using (var serviceScope = ApplicationServiceProvider.CreateServiceScope())
     {
         return(await serviceScope.ServiceProvider.GetRequiredService <IModelLocalizer>()
                .LocalizeAsync(models, languageId, depth, cancellationToken));
     }
 }