public static IStringLocalizer GetInternalLocalizer( [NotNull] this IStringLocalizer stringLocalizer) { Check.NotNull(stringLocalizer, nameof(stringLocalizer)); var localizerType = stringLocalizer.GetType(); if (!ReflectionHelper.IsAssignableToGenericType(localizerType, typeof(StringLocalizer <>))) { return(stringLocalizer); } var localizerField = localizerType .GetField( "_localizer", BindingFlags.Instance | BindingFlags.NonPublic ); if (localizerField == null) { throw new AbpException($"Could not find the _localizer field inside the {typeof(StringLocalizer<>).FullName} class. Probably its name has changed. Please report this issue to the ABP framework."); } return(localizerField.GetValue(stringLocalizer) as IStringLocalizer); }
public virtual IDictionary <string, object> GetStringLocalizerInformation(IStringLocalizer stringLocalizer) { if (stringLocalizer == null) { throw new ArgumentNullException(nameof(stringLocalizer)); } var information = new SortedDictionary <string, object> { { "Type", stringLocalizer.GetType() } }; // ReSharper disable ConvertIfStatementToSwitchStatement if (stringLocalizer is StringLocalizer concreteStringLocalizer) { foreach (var property in this.StringLocalizerProperties) { information.Add(property.Name, property.GetValue(concreteStringLocalizer)); } } else if (stringLocalizer is ResourceManagerStringLocalizer resourceManagerStringLocalizer) { foreach (var field in this.ResourceManagerStringLocalizerFields) { information.Add(field.Name, field.GetValue(resourceManagerStringLocalizer)); } } // ReSharper restore ConvertIfStatementToSwitchStatement return(information); }
//public static IStringLocalizer LoadCulture(this IStringLocalizer localizer, string culture, ILogger logger) public static StringLocalizerWithCache LoadCulture(this IStringLocalizer localizer, string culture, bool fromLib, ILogger logger) { try { var cultureInfo = new CultureInfo(culture); var l = localizer.WithCulture(cultureInfo); // проверим культуру // если такой кульутры нет, то в этом месте будет эксепшен (при вызове GetAllStrings). // причем как я понял это единственный способ узнать есть ли такая культура в ресурсах или нет /*var str = string.Join("\n", l.GetAllStrings().Select(i => i.Name + "->" + i.Value).Take(2).ToList()); * if (logger != null) * { * logger.LogTrace("LoadCulture for {0} strings:\n{1}", localizer.GetType().FullName, str); * } * return l;*/ return(StringLocalizerWithCache.Get(l, culture + "." + (fromLib ? "lib" : "contr"))); } catch (Exception e) { logger.LogTrace("LoadCulture for {0} fail. {1}", localizer.GetType().FullName, e); return(null); } }
public AboutService(IStringLocalizer <AboutService> localizer) { _localizer = localizer; Debug.WriteLine(_localizer.GetType()); }