Esempio n. 1
0
 /// <summary>
 /// Initialize <see cref="ILocalizationManager"/> service.
 /// </summary>
 /// <param name="builder"></param>
 /// <param name="resourceManagerFullPath">Resource files location <remarks>example "HR.Clients.WPF.Properties.Resources"</remarks></param>
 /// <param name="resourceManagerAssembly">The name of the assembly containing the resources <remarks>Example "HR.Clients.WPF.exe"</remarks></param>
 /// <param name="supportedCultures">The available cultures in the resource files <remarks>Example new[] {"ar-SY", "en-US"}</remarks></param>
 /// <param name="defaultCluture">The default culture used in the application <remarks>Example "en-US"</remarks></param>
 /// <returns></returns>
 public static IApplicationBuilder UseLocalization(
     this IApplicationBuilder builder,
     string resourceManagerFullPath,
     string resourceManagerAssembly,
     string[] supportedCultures,
     string defaultCluture = "en-US")
 {
     builder.BuildActionsCoordinator.AddAction(DefaultBuildActions.LocalizationBuildAction((container) =>
     {
         var localizationManager = container.Resolve <ILocalizationManager>();
         localizationManager.SetCulture(defaultCluture);
         var values = new Dictionary <string, Dictionary <string, string> >();
         var res    = new ResourceManager(resourceManagerFullPath,
                                          Assembly.LoadFrom(Path.Combine(AppDomain.CurrentDomain
                                                                         .BaseDirectory,
                                                                         resourceManagerAssembly)));
         foreach (var culture in supportedCultures)
         {
             foreach (DictionaryEntry val in
                      res.GetResourceSet(new CultureInfo(culture), true, true))
             {
                 if (!values.ContainsKey(val.Key.ToString()))
                 {
                     values[val.Key.ToString()] = new Dictionary <string, string>();
                 }
                 values[val.Key.ToString()][culture] = val.Value.ToString();
             }
         }
         localizationManager.AddValues(values);
     }));
     return(builder);
 }
Esempio n. 2
0
 /// <summary>
 /// Configure the <see cref="ILocalizationManager"/> service.
 /// </summary>
 /// <param name="builder"></param>
 /// <param name="defaultCluture"></param>
 /// <returns></returns>
 public static IApplicationBuilder UseLocalization(
     this IApplicationBuilder builder,
     string defaultCluture = "en-US")
 {
     builder.BuildActionsCoordinator.AddAction(DefaultBuildActions.LocalizationBuildAction((container) =>
     {
         var localizationManager = container.Resolve <ILocalizationManager>();
         localizationManager.SetCulture(defaultCluture);
     }));
     return(builder);
 }