protected TagBuilder GenerateFlag(LocalizationViewModel localization)
        {
            TagBuilder tb = new TagBuilder("div");

              tb.AddCssClass("flag");
              tb.SetInnerText(localization.Culture.Code);
              return tb;
        }
        protected TagBuilder GenerateCulture(LocalizationViewModel localization)
        {
            TagBuilder tb = new TagBuilder("div");

              tb.AddCssClass("culture");
              tb.InnerHtml = this.GenerateFlag(localization);
              return tb;
        }
        protected TagBuilder GenerateFlag(LocalizationViewModel localization)
        {
            TagBuilder tb = new TagBuilder("div");

              tb.AddCssClass("flag");
              tb.InnerHtml.Clear();
              tb.InnerHtml.AppendEncoded(localization.Culture.Code);
              return tb;
        }
        protected string GetValue(ViewContext viewContext, ModelExpression modelExpression, LocalizationViewModel localization = null)
        {
            ModelState modelState;

              if (viewContext.ModelState.TryGetValue(this.GetIdentity(modelExpression, localization), out modelState) && modelState.Value != null)
            return modelState.Value.AttemptedValue;

              if (localization != null)
            return localization.Value;

              return modelExpression.Model == null ? null : modelExpression.Model.ToString();
        }
        protected string GetIdentity(ModelExpression modelExpression, LocalizationViewModel localization = null)
        {
            string identity = string.Empty;

              if (modelExpression.Name.Length == 1)
            identity = modelExpression.Name[0].ToString().ToLower();

              identity = modelExpression.Name.Remove(1).ToLower() + modelExpression.Name.Substring(1);

              if (localization != null)
            identity += localization.Culture.Code;

              return identity;
        }
        protected TagBuilder GenerateInput(ViewContext viewContext, ModelExpression modelExpression, LocalizationViewModel localization = null, string type = "text")
        {
            TagBuilder tb = new TagBuilder("input");

              if (!this.IsValid(viewContext, modelExpression, localization))
            tb.AddCssClass("input-validation-error");

              tb.MergeAttribute("id", this.GetIdentity(modelExpression, localization));
              tb.MergeAttribute("name", this.GetIdentity(modelExpression, localization));
              tb.MergeAttribute("type", type);
              tb.MergeAttribute("value", this.GetValue(viewContext, modelExpression, localization));
              this.HandleAttributes(tb, modelExpression);
              tb.TagRenderMode = TagRenderMode.SelfClosing;
              return tb;
        }
        protected bool IsValid(ViewContext viewContext, ModelExpression modelExpression, LocalizationViewModel localization = null)
        {
            ModelState modelState;

              if (viewContext.ModelState.TryGetValue(this.GetIdentity(modelExpression, localization), out modelState))
            return modelState.ValidationState != ModelValidationState.Invalid;

              return true;
        }