Application and Internationalization Block

Scenario

The .NET / WPF desktop application must be localized (or in terms of MS globalized) in a language other than English. That is, the user interface must be fully accepted (labels, badges, ...).

The log file entries, audit records, and other outputs of the application, however, must remain in English to allow English-speaking maintenance staff / its staff to review it. They do not speak French or Chinese.

The application uses .resx files to perform localization.

The corporate library validation block is used to validate the business rules of the object model.

Now suppose that there is a service that checks its object model arguments before executing real business logic. In some cases, it receives invalid object model arguments, but continues execution with the best efforts. However, data about invalid object models must be recorded in the audit log and in the log file.

An example of a service using a validation block.

public class Service : IService
{
    public void MyMethod(MyObjectModelObject obj)
    {
        Validator validator = ValidationFactory.CreateValidator(typeof(MyObjectModelObject));
        ValidationResults results = validator.Validate(this);

        // !!! The messages in the validation results are now already localized to CurrentCulture.

        // ... build a log message: msg
        if (results.Count > 0)
        {
            Logger.Log(msg);
        }
    }
}

As indicated in the code comment, when you called Validate () on the EnterpriseLibrary validator, the verification messages are already localized in French, and you cannot write them to eg the English log file.

, , , . .

, Enterprise Library? :

  • CurrentCulture ( , )
  • ( )

!

+5
1

, MessageTemplateResourceName MessageTemplate. .

id : RULESET_RULESETQUALIFIER_OPERATION_OBJECT_PROPERTY_VALIDATIONTYPE. RULESET_BMW_INSERT_CAR_YEAR_RANGE RULESET_BMW_UPDATE_CAR_COLOR_LENGTH ..

VAB :

<property name="Color">
   <validator lowerBound="0" lowerBoundType="Ignore" upperBound="50"
    upperBoundType="Inclusive" negated="false" messageTemplate="RULESET_BMW_INSERT_CAR_COLOR_LENGTH"
    messageTemplateResourceName="" messageTemplateResourceType=""
    tag="" type="Microsoft.Practices.EnterpriseLibrary.Validation.Validators.StringLengthValidator, Microsoft.Practices.EnterpriseLibrary.Validation, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    name="String Length Validator" />
                    </property>

, , . , - (, ), , .

, . , . , UserMessages.resources, UserMessages.fr-BE.resources . (LogMessages.resources). , . .

ResourceManager:

ResourceManager userResourceManager = 
    new ResourceManager("UserMessages", Assembly.GetExecutingAssembly());

string userMessage = userResourceManager.GetString(resourceId);

ResourceManager logResourceManager = 
    new ResourceManager("LogMessages", Assembly.GetExecutingAssembly());

// Can also try to use InvariantCulture instead of "en"
string messageToLog = logResourceManager.GetString(resourceId,  new CultureInfo("en"));
//alternative to ensure you get the english user message value:
//    string messageToLog = userResourceManager.GetString(resourceId,  new CultureInfo("en"));


. ValidationResults .

+4

All Articles