/// <summary> /// Gets the resource translation by language. /// </summary> /// <param name="helper">The helper.</param> /// <param name="model">The resource expression.</param> /// <param name="customAttribute">The custom attribute.</param> /// <param name="culture">The culture.</param> /// <param name="formatArguments">The format arguments.</param> /// <returns>Translation</returns> /// <exception cref="ArgumentNullException"> /// model /// or /// customAttribute /// or /// culture /// </exception> /// <exception cref="ArgumentException">Given type `{customAttribute.FullName}` is not of type `System.Attribute`</exception> public static MvcHtmlString TranslateByCulture(this HtmlHelper helper, Expression <Func <object> > model, Type customAttribute, CultureInfo culture, params object[] formatArguments) { if (model == null) { throw new ArgumentNullException(nameof(model)); } if (customAttribute == null) { throw new ArgumentNullException(nameof(customAttribute)); } if (culture == null) { throw new ArgumentNullException(nameof(culture)); } if (!typeof(Attribute).IsAssignableFrom(customAttribute)) { throw new ArgumentException($"Given type `{customAttribute.FullName}` is not of type `System.Attribute`"); } var resourceKey = ResourceKeyBuilder.BuildResourceKey(ExpressionHelper.GetFullMemberName(model), customAttribute); return(new MvcHtmlString(LocalizationProvider.Current.GetStringByCulture(resourceKey, culture, formatArguments))); }
/// <summary> /// Gets the resource translation. /// </summary> /// <typeparam name="TModel">The type of the model.</typeparam> /// <typeparam name="TValue">The type of the value.</typeparam> /// <param name="html">The helper.</param> /// <param name="expression">The resource expression.</param> /// <param name="culture">The culture.</param> /// <param name="formatArguments">The format arguments.</param> /// <returns>Translation</returns> public static MvcHtmlString TranslateForByCulture <TModel, TValue>(this HtmlHelper <TModel> html, Expression <Func <TModel, TValue> > expression, CultureInfo culture, params object[] formatArguments) { return(new MvcHtmlString(LocalizationProvider.Current.GetStringByCulture(ExpressionHelper.GetFullMemberName(expression), culture, formatArguments))); }