public static string DescriptionFor <TModel, TValue>(this IHtmlHelper <TModel> self, Expression <Func <TModel, TValue> > expression) { MemberExpression memberExpression = (MemberExpression)expression.Body; var displayAttribute = (DisplayAttribute)memberExpression.Member.GetCustomAttributes(typeof(DisplayAttribute), false).FirstOrDefault(); string description = displayAttribute?.Description ?? memberExpression.Member?.Name; description = (_LocalizerFactory?.Create(memberExpression.Expression.Type)[description]) ?? description; return(description); }
public HomeController(IStringLocalizerFactory stringLocalizerFactory, IStringLocalizer<HomeController> T) { var stringLocalizer = stringLocalizerFactory.Create("Test", location: null); var resourceFiles = typeof(HomeController).Assembly.GetManifestResourceNames(); foreach (var resFile in resourceFiles) Console.WriteLine(resFile.ToString()); //bug 1. See the base name contruction is with capital in the ResourceManagerStringLocalizerFactory.cs Console.WriteLine("Watch the capital problem in the 2e localize"); //Make sure this is working Console.WriteLine(T["test"], T["test"].ResourceNotFound.ToString()); //bug 2 Console.WriteLine(T.WithCulture(new CultureInfo("nl-NL"))["test"] + ":" + T["test"].ResourceNotFound.ToString() + "should be false!!!"); ; Console.WriteLine(T.WithCulture(new CultureInfo("nl-NL"))["Hello"]); Console.WriteLine(T.WithCulture(new CultureInfo("nl"))["Hello"]); Console.WriteLine(T.WithCulture(new CultureInfo(""))["Hello"]); var specific = T.WithCulture(new CultureInfo("nl-NL")).GetAllStrings(true); var neutral = T.WithCulture(new CultureInfo("nl")).GetAllStrings(true); var invariant = T.WithCulture(new CultureInfo("")).GetAllStrings(true); // bug 1 will crashes because of capital problem // bug 3 this should not crash at all but the wrong execption is catched MissingManifestResourceException // But swallowed the null Exception in GetResourceNamesFromCultureHierarchy doesn't see a good idea foreach (string s in invariant) Console.WriteLine(s); Debugger.Launch(); // will 4 will crash because of missing resource file foreach (string s in specific) Console.WriteLine(s); foreach (string s in neutral) Console.WriteLine(s); }
public Func<string, string> GetLocalizerFunction(IStringLocalizerFactory factory) { if (LocalizerType != null) { var localizer = factory.Create(LocalizerType); return x => localizer[x]; } else return x => x; }
public TestController(IStringLocalizerFactory factory) { _localizer = factory.Create(typeof(SharedResource)); _localizer2 = factory.Create("SharedResource", location: null); }
public LocalizationApiController(IStringLocalizerFactory stringLocalizerFactory, IRepository <Resource> resourceRepository, IRepository <Culture> cultureRepository) { _localizer = stringLocalizerFactory.Create(null); _resourceRepository = resourceRepository; _cultureRepository = cultureRepository; }
/// <summary> /// Constructor /// </summary> /// <param name="cachedDbAccess">Cached Db Access</param> /// <param name="dailyRoutineFunctionNameGenerator">Daily routine function name generator</param> /// <param name="localizerFactory">Localizer factory</param> public LegacyDailyRoutineEventPlaceholderResolver(IExportCachedDbAccess cachedDbAccess, IDailyRoutineFunctionNameGenerator dailyRoutineFunctionNameGenerator, IStringLocalizerFactory localizerFactory) { _cachedDbAccess = cachedDbAccess; _dailyRoutineFunctionNameGenerator = dailyRoutineFunctionNameGenerator; _localizer = localizerFactory.Create(typeof(LegacyDailyRoutineEventPlaceholderResolver)); }
/// <summary> /// Constructor /// </summary> /// <param name="errorCollection">Error Collection</param> /// <param name="localizerFactory">Localizer factory</param> public LegacyActionStepRenderer(ExportPlaceholderErrorCollection errorCollection, IStringLocalizerFactory localizerFactory) : base(errorCollection, localizerFactory) { _localizer = localizerFactory.Create(typeof(LegacyActionStepRenderer)); }
public AllStringLocalizer(IStringLocalizerFactory stringLocalizerFactory) { _stringLocalizer = stringLocalizerFactory.Create("ALL", "CoreLocalization"); }
public static void Main(string[] args) { #region Snippet_1 // Create localization source var source = new List <ILine> { LineFormat.Parameters.Parse("Culture:en:Type:MyController:Key:hello").Format("Hello World!") }; // Create asset IAsset asset = new StringAsset(source); // Create culture policy ICulturePolicy culturePolicy = new CulturePolicy(); // Create root ILineRoot root = new StringLocalizerRoot(asset, culturePolicy); #endregion Snippet_1 { #region Snippet_2 // Assign as IStringLocalizer, use "MyController" as root. IStringLocalizer stringLocalizer = root.Section("MyController").AsStringLocalizer(); #endregion Snippet_2 } { #region Snippet_3 // Assign as IStringLocalizerFactory IStringLocalizerFactory stringLocalizerFactory = root as IStringLocalizerFactory; // Adapt to IStringLocalizer IStringLocalizer <MyController> stringLocalizer2 = stringLocalizerFactory.Create(typeof(MyController)) as IStringLocalizer <MyController>; #endregion Snippet_3 } { #region Snippet_4a // Assign to IStringLocalizer for the class MyController IStringLocalizer <MyController> stringLocalizer = root.Type(typeof(MyController)).AsStringLocalizer <MyController>(); #endregion Snippet_4a } { #region Snippet_4b // Assign as IStringLocalizerFactory IStringLocalizerFactory stringLocalizerFactory = root as IStringLocalizerFactory; // Create IStringLocalizer for the class MyController IStringLocalizer <MyController> stringLocalizer = stringLocalizerFactory.Create(typeof(MyController)) as IStringLocalizer <MyController>; #endregion Snippet_4b } { #region Snippet_5a // Create IStringLocalizer and assign culture IStringLocalizer stringLocalizer = root.Culture("en").Type <MyController>().AsStringLocalizer(); #endregion Snippet_5a } { #region Snippet_5b // Assign as IStringLocalizerFactory IStringLocalizerFactory stringLocalizerFactory = root as IStringLocalizerFactory; // Create IStringLocalizer and assign culture IStringLocalizer stringLocalizer = stringLocalizerFactory.Create(typeof(MyController)) .WithCulture(CultureInfo.GetCultureInfo("en")); #endregion Snippet_5b stringLocalizer = (IStringLocalizer)root.Culture("en").Type <MyController>(); // Change language stringLocalizer = stringLocalizer.WithCulture(CultureInfo.GetCultureInfo("fi")); // Keep language stringLocalizer = stringLocalizer.WithCulture(CultureInfo.GetCultureInfo("fi")); // Change language stringLocalizer = stringLocalizer.WithCulture(CultureInfo.GetCultureInfo("sv")); // Remove language stringLocalizer = stringLocalizer.WithCulture(null); } }
public IActionResult Index() { var createdlocalizer = factory.Create(typeof(DataAnnotationResource)); return(this.Ok(new { DI = this.localizer["Username"], Factory = createdlocalizer["Username"] })); }
public void Configure( IApplicationBuilder app, ILoggerFactory loggerFactory, IStringLocalizerFactory stringLocalizerFactory, IStringLocalizer<StartupResourcesInFolder> startupStringLocalizer, IStringLocalizer<Customer> custromerStringLocalizer) { loggerFactory.AddConsole(minLevel: LogLevel.Warning); var options = new RequestLocalizationOptions { SupportedCultures = new List<CultureInfo>() { new CultureInfo("fr-FR") }, SupportedUICultures = new List<CultureInfo>() { new CultureInfo("fr-FR") } }; app.UseRequestLocalization(options, defaultRequestCulture: new RequestCulture("en-US")); var stringLocalizer = stringLocalizerFactory.Create("Test", location: null); app.Run(async (context) => { await context.Response.WriteAsync(startupStringLocalizer["Hello"]); await context.Response.WriteAsync(" "); await context.Response.WriteAsync(stringLocalizer["Hello"]); await context.Response.WriteAsync(" "); await context.Response.WriteAsync(custromerStringLocalizer["Hello"]); }); }