コード例 #1
0
 /// <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));
     }
 }
コード例 #2
0
 /// <summary>
 /// Localizes all properties an <see cref="ILocalizedModel{TModel, TEntity}"/> item with specified language id
 /// </summary>
 /// <typeparam name="TModel"></typeparam>
 /// <typeparam name="TEntity"></typeparam>
 /// <param name="model"></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 model</returns>
 public static async Task <TModel> LocalizeAsync <TModel, TEntity>(this ILocalizedModel <TModel, TEntity> model,
                                                                   int languageId,
                                                                   bool getOriginalValueIfNotFound,
                                                                   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(model, languageId, getOriginalValueIfNotFound, depth, cancellationToken));
     }
 }