{
protected override string Convert(string value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return parameter == null ? Mvx.IoCProvider.Resolve<ILocalizationService>().GetLocalizableString(null, value) : Mvx.IoCProvider.Resolve<ILocalizationService>().GetLocalizableString(parameter as string, value);
//return parameter == null ? Mvx.IoCProvider.Resolve<IResxService>().GetString(value) : Mvx.IoCProvider.Resolve<IResxService>().GetString(value, parameter as string);
}
}
public class LocalizationService : ILocalizationService { public List<Type> Resources { get; } public LocalizationService(params Type[] resources) { Resources = resources.ToList(); } public void SetCurrentUICulture(CultureInfo currentUiCulture) { Resources.ForEach(resource => { var propertyInfo = resource.GetTypeInfo().GetDeclaredProperty("Culture"); propertyInfo.SetValue(resource, currentUiCulture); }); } public string GetLocalizableString(string resourceName, string propertyName) { string result = string.Empty; var resource = Resources.FirstOrDefault(x => x.Name.StartsWith(resourceName, StringComparison.OrdinalIgnoreCase)); if (resource != null) { result = resource.GetTypeInfo() .GetDeclaredProperty(propertyName) ?.GetValue(resource) as string; } return result; } }
Обсуждают сегодня