2013-10-03 13 views
6

私はすでにWeb.configに<globalization culture="de-DE" uiCulture="de-DE" />を追加しました。私は@Thread.CurrentThread.CurrentCultureをtestviewに追加し、de-DEを表示します。だから、すべてはうまくいくようだ。Windows Azure Webサイト(asp.net mvc4)で検証言語を変更するにはどうすればよいですか?

しかし、確認メッセージはまだ英語のままです(例:

入力フィールドは必須です。

私の間違いは何ですか?

+0

あなたはそれを把握しましたか? – bob

+1

いいえ現在、私はカスタム属性を使用しています。 – Harry

答えて

0

私は同じ問題を抱えています。

「Microsoft .NET Framework 4.5言語パック」がAzureの「Webサイト」にインストールされていないとします。 「Azure cloudプロジェクト」を使用することは、IISを直接設定できるオプションであるようです。

別の解決策は、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のを使用していますように私自身のローカライズ機能です)

関連する問題