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 translation for the resource (reference to the resource is specified as lambda expression).
        /// </summary>
        /// <param name="resource">Lambda expression for the resource.</param>
        /// <param name="attribute">
        /// Type of the custom attribute (registered in
        /// <see cref="ConfigurationContext.CustomAttributes" /> collection).
        /// </param>
        /// <param name="culture">
        /// If you want to get translation for other language as <see cref="CultureInfo.CurrentUICulture" />,
        /// then specific that language here.
        /// </param>
        /// <param name="formatArguments">
        /// If you have placeholders in translation to replace to - use this argument to specify
        /// those.
        /// </param>
        /// <returns>Translation for the resource with specific key in language specified  in <paramref name="culture" />.</returns>
        public virtual string GetStringByCulture(
            Expression <Func <object> > resource,
            Type attribute,
            CultureInfo culture,
            params object[] formatArguments)
        {
            if (resource == null)
            {
                throw new ArgumentNullException(nameof(resource));
            }

            var resourceKey = _expressionHelper.GetFullMemberName(resource);

            resourceKey = _keyBuilder.BuildResourceKey(resourceKey, attribute);

            return(GetStringByCulture(resourceKey, culture, formatArguments));
        }
        /// <summary>
        /// Translates the specified enum with some formatting arguments (if needed).
        /// </summary>
        /// <param name="target">The enum to translate.</param>
        /// <param name="culture">The culture.</param>
        /// <param name="formatArguments">The format arguments.</param>
        /// <returns>Translated enum values</returns>
        /// <exception cref="ArgumentNullException">
        /// target
        /// or
        /// culture
        /// </exception>
        public static string TranslateByCulture(this Enum target, CultureInfo culture, params object[] formatArguments)
        {
            if (target == null)
            {
                throw new ArgumentNullException(nameof(target));
            }
            if (culture == null)
            {
                throw new ArgumentNullException(nameof(culture));
            }

            var resourceKey = ResourceKeyBuilder.BuildResourceKey(target.GetType(), target.ToString());

            return(LocalizationProvider.Current.GetStringByCulture(resourceKey, culture, formatArguments));
        }
        public static MvcHtmlString TranslateForByCulture <TModel, TValue>(this HtmlHelper <TModel> html,
                                                                           Expression <Func <TModel, TValue> > expression,
                                                                           Type customAttribute,
                                                                           CultureInfo culture,
                                                                           params object[] formatArguments)
        {
            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 metadata = ModelMetadata.FromLambdaExpression(expression, html.ViewData);

            var pi = metadata.ContainerType.GetProperty(metadata.PropertyName);

            if (pi != null)
            {
                if (pi.GetCustomAttribute(customAttribute) == null)
                {
                    return(MvcHtmlString.Empty);
                }
            }

            return(new MvcHtmlString(LocalizationProvider.Current.GetStringByCulture(ResourceKeyBuilder.BuildResourceKey(metadata.ContainerType,
                                                                                                                         metadata.PropertyName,
                                                                                                                         customAttribute),
                                                                                     culture,
                                                                                     formatArguments)));
        }
        internal static string GetFullMemberName(Expression <Func <object> > memberSelector)
        {
            var memberStack = WalkExpression(memberSelector);

            return(ResourceKeyBuilder.BuildResourceKey(memberStack.Pop(), memberStack));
        }