Print Page | Close Window

Change property DisplayName with locatization

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2012
Forum Discription: For .NET 4.5
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=3840
Printed Date: 19-Apr-2025 at 1:00pm


Topic: Change property DisplayName with locatization
Posted By: cefernan
Subject: Change property DisplayName with locatization
Date Posted: 06-Dec-2012 at 9:29am
Hi,

I have an application that is prepared to change the language at runtime and it's working fine. Now, I'm implementing to show the DevForce error messages in different languages too. 

I did it changing ErrorsResourceManager:
entityManager.VerifierEngine.ErrorsResourceManager = MyErrorMessages.ResourceManager;

Now I have messages like that:
English - "Name is required"
Portuguese - "Name é obrigatório"

So, I also need to change the property display name, "Name" in this case need to be change to "Nome".

The perfect result would be:
English - "Name is required"
Portuguese - "Nome é obrigatório"

What is the best way to solve this case?

Regards.



Replies:
Posted By: sbelini
Date Posted: 06-Dec-2012 at 1:15pm
Hi cefernan,

Have you taken a look at http://drc.ideablade.com/xwiki/bin/view/Documentation/validate-localizing-error-messages - http://drc.ideablade.com/xwiki/bin/view/Documentation/validate-localizing-error-messages ?.

sbelini.


Posted By: cefernan
Date Posted: 07-Dec-2012 at 2:59am
Hi Silvio,

Yes, I have. I implemented it and it's working. 

Now, I want to translate the name of the properties too. Just take a look in my example that I wish.

Customer
----------
ID
Name
Phone

As I did, appears:
en-US -> "Name is required"
"Phone is required"

pt-BR -> "Name é obrigatório"
"Phone é obrigatório"

Because Name and Phone are the names of my columns in DataBase, they will appear in the same form in any language.

For the user is strange to see this names in English, so I also want to translate them:
pt-BR -> "Nome é obrigatório"
"Telefone é obrigatório"

Thanks.


Posted By: kimj
Date Posted: 07-Dec-2012 at 10:13am
There are a couple of ways you can localize the Display Name. 
 
One is to modify the code generation process to generate Display attributes with resource information.  More info here - http://www.ideablade.com/forum/forum_posts.asp?TID=2063&title=displayattribute - http://www.ideablade.com/forum/forum_posts.asp?TID=2063&title=displayattribute .
 
Another is to set the PropertyNameToDisplayNameTranslator on the VerifierEngine - http://drc.ideablade.com/ApiDocumentation/IdeaBlade.Validation~IdeaBlade.Validation.VerifierEngine~PropertyNameToDisplayNameTranslator.html - http://drc.ideablade.com/ApiDocumentation/IdeaBlade.Validation~IdeaBlade.Validation.VerifierEngine~PropertyNameToDisplayNameTranslator.html .   We don't have an example of this, but the delegate you provide will be called whenever the property/display name is needed, and you can provide your own localization logic within the delegate.
 
 


Posted By: cefernan
Date Posted: 07-Dec-2012 at 11:54am
The second approach solve perfectly my problem.

Thanks Kim.


Posted By: cypher
Date Posted: 22-May-2013 at 5:46am
hi cefeman,

could you provide you sample delegate to translate the properties with localisation


Posted By: cefernan
Date Posted: 22-May-2013 at 6:11am
Hi cypher,

It's a very simple delegate:
public UnitOfWorkBase(IEntityManagerProvider entityManagerProvider, QueryStrategy strategy = null)
    : base(entityManagerProvider)
{
    ...
    entityManagerProvider.Manager.VerifierEngine.PropertyNameToDisplayNameTranslator += PropertyNameToDisplayNameTranslator;        
    ...
}
private string PropertyNameToDisplayNameTranslator(Type pType, String pPropertyName)
{
    return i18n.Localization.ErrorMessages.ResourceManager.GetString(pPropertyName);
}

i18n is my project that I have my localized strings.


Posted By: cypher
Date Posted: 22-May-2013 at 6:12am
perfect, that helps a lot.. thanks for you super fast feedback. 



Print Page | Close Window