1

Im trying to implement multi-language support in my system, the other systems at work uses xmlfiles for this generated from a database that they have used for some time now so they want me to use this aswell.

I have managed to translate everything except the displaynames in my formmodels, these values can apperantly only be constant values so i can't use a method that gets the correct translation.

This is how the code is now:

[System.ComponentModel.DisplayName("Kontraktnamn")]
public string Name { get; set; }

And i want to do something like this:

[System.ComponentModel.DisplayName(GetTextByKey("Contract_Name"))]
public string Name { get; set; }

Is it possible to work around this? Or maybe there is a better way to do it and still use the xmlfiles?

Marcus
  • 1,197
  • 1
  • 7
  • 14

1 Answers1

4

You'll need to create your own custom attribute that can read the xml values:

public class CustomDisplayName : DisplayNameAttribute
{
    public CustomDisplayName()
    {
        this.DisplayName = MyXmlReader.Read(DisplayName);
    }
}
John Farrell
  • 24,673
  • 10
  • 77
  • 110
  • Did not compile on my system, because setting DisplayName was not possible. But you can do this `public CustomDisplayName(aDisplayName) : base(aDisplayName) {} override string DisplayName { get { return MyXmlReader.Read(base.DisplayName); } }` – Simon D. Jul 29 '15 at 14:06