New Posts New Posts RSS Feed: Change property DisplayName with locatization
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Change property DisplayName with locatization

 Post Reply Post Reply
Author
cefernan View Drop Down
Groupie
Groupie


Joined: 13-Jul-2012
Posts: 70
Post Options Post Options   Quote cefernan Quote  Post ReplyReply Direct Link To This Post Topic: Change property DisplayName with locatization
    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.
Back to Top
sbelini View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 13-Aug-2010
Location: Oakland
Posts: 786
Post Options Post Options   Quote sbelini Quote  Post ReplyReply Direct Link To This Post Posted: 06-Dec-2012 at 1:15pm
Back to Top
cefernan View Drop Down
Groupie
Groupie


Joined: 13-Jul-2012
Posts: 70
Post Options Post Options   Quote cefernan Quote  Post ReplyReply Direct Link To This Post 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.


Edited by cefernan - 07-Dec-2012 at 3:17am
Back to Top
kimj View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 1391
Post Options Post Options   Quote kimj Quote  Post ReplyReply Direct Link To This Post 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.
 
Another is to set the PropertyNameToDisplayNameTranslator on the VerifierEngine - 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.
 
 
Back to Top
cefernan View Drop Down
Groupie
Groupie


Joined: 13-Jul-2012
Posts: 70
Post Options Post Options   Quote cefernan Quote  Post ReplyReply Direct Link To This Post Posted: 07-Dec-2012 at 11:54am
The second approach solve perfectly my problem.

Thanks Kim.
Back to Top
cypher View Drop Down
Newbie
Newbie
Avatar

Joined: 26-Nov-2012
Location: Deutschland
Posts: 20
Post Options Post Options   Quote cypher Quote  Post ReplyReply Direct Link To This Post Posted: 22-May-2013 at 5:46am
hi cefeman,

could you provide you sample delegate to translate the properties with localisation
Back to Top
cefernan View Drop Down
Groupie
Groupie


Joined: 13-Jul-2012
Posts: 70
Post Options Post Options   Quote cefernan Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
cypher View Drop Down
Newbie
Newbie
Avatar

Joined: 26-Nov-2012
Location: Deutschland
Posts: 20
Post Options Post Options   Quote cypher Quote  Post ReplyReply Direct Link To This Post Posted: 22-May-2013 at 6:12am
perfect, that helps a lot.. thanks for you super fast feedback. 
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down