2013-10-03 5 views
6

मैंने पहले से ही अपने वेब.कॉन्फिग में <globalization culture="de-DE" uiCulture="de-DE" /> जोड़ा है। मैंने अपने टेस्टव्यू में @Thread.CurrentThread.CurrentCulture जोड़ा और यह डी-डीई दिखाता है। तो, सब ठीक लगता है।मैं Windows Azure वेब साइट (asp.net mvc4) पर सत्यापन भाषा कैसे बदल सकता हूं?

लेकिन सत्यापन संदेश अभी भी अंग्रेजी में है, उदा।

इनपुट फ़ील्ड आवश्यक है।

मेरी गलती क्या है?

+0

क्या आपने इसे समझ लिया? – bob

+1

नहीं। वर्तमान में मैं कस्टम विशेषताओं का उपयोग करता हूं। – Harry

उत्तर

0

मुझे एक ही समस्या है।

मुझे लगता है कि "माइक्रोसॉफ्ट .NET Framework 4.5 भाषा पैक" Azure "वेब साइट्स" पर स्थापित नहीं है। ऐसा लगता है कि "एज़ूर क्लाउड प्रोजेक्ट" एक विकल्प है क्योंकि आप आईआईएस को सीधे कॉन्फ़िगर कर सकते हैं।

एक अन्य समाधान माइक्रोसॉफ्ट के लिए प्रतीक्षा करने Azure में भाषा पैक समर्थन ...

Personnaly शामिल करने के लिए है, मैं मुख्य विशेषताओं ओवरराइड करने के लिए फैसला किया है। अधिकांश चालक [आवश्यक] और [रेगेक्स] हैं।

using System.ComponentModel.DataAnnotations; 
using System.Globalization; 

namespace Ic.DataAnnotations 
{ 
    public class RegularExpressionLoc : RegularExpressionAttribute 
    { 
     private readonly string _errorMessage; 

     public RegularExpressionLoc(string errorMessage, string pattern) 
      : base(pattern) 
     { 
      _errorMessage = errorMessage; 
     } 

     public override string FormatErrorMessage(string input) 
     { 
      return Localizer.Loc(_errorMessage); 
     } 
    } 
} 

और

using System.Collections.Generic; 
using System.ComponentModel.DataAnnotations; 
using System.Web.Mvc; 

namespace Ic.DataAnnotations 
{ 
    public class RegularExpressionValidator : DataAnnotationsModelValidator<RegularExpressionAttribute> 
    { 
     private readonly string _message; 
     private readonly string _pattern; 

     public RegularExpressionValidator(ModelMetadata metadata, ControllerContext context, RegularExpressionAttribute attribute) 
      : base(metadata, context, attribute) 
     { 
      _pattern = attribute.Pattern; 
      _message = attribute.FormatErrorMessage(""); 
     } 

     public override IEnumerable<ModelClientValidationRule> GetClientValidationRules() 
     { 
      var rule = new ModelClientValidationRule 
      { 
       ErrorMessage = _message, 
       ValidationType = "regex" 
      }; 

      rule.ValidationParameters.Add("pattern", _pattern); 

      return new[] { rule }; 
     } 
    } 
} 

और में Global.asax

DataAnnotationsModelValidatorProvider.RegisterAdapter(typeof(RegularExpressionLoc), typeof(RegularExpressionValidator)); 
: नीचे देखें

using System.Collections.Generic; 
using System.ComponentModel.DataAnnotations; 
using System.Globalization; 
using System.Web.Mvc; 

namespace Ic.DataAnnotations 
{ 
    public class RequiredLoc : RequiredAttribute, IClientValidatable 
    { 

     public IEnumerable<ModelClientValidationRule> GetClientValidationRules(ModelMetadata metadata, 
      ControllerContext context) 
     { 
      yield return new ModelClientValidationRule 
      { 
       ErrorMessage = FormatErrorMessage(metadata.DisplayName), 
       ValidationType = "required" 
      }; 
     } 

     public override string FormatErrorMessage(string message) 
     { 
      base.FormatErrorMessage(message); 
      return Localizer.Loc("Le champs '%1' est requis.", message); 
     } 
    } 

} 

नियमित अभिव्यक्ति के लिए (loc मेरे अपने स्थानीयकरण समारोह के रूप में मैं gettext का उपयोग कर रहा है)

संबंधित मुद्दे