daniel
daniel

Reputation: 35703

Xml serialization and different languages (internationalization)

What is a good solution to do XML serialization in different languages (internationalization) so that tags and attributes are serialized to the same object with different language?

I save configuration in xml and want to support german and english for the xml.

I don't really know how a good approach for this issue looks like.

Best solution would be but doesn´t exist:

[XmlRoot("MyEnglishConfig,MeineDeuscheKonfiguration")]
public class Test
{
    [XmlElement(ElementName="Setting1,Einstellung1")]
    public String value1;
}

so that both xml versions are parsed correct:

<MyEnglishConfig>
    <Setting1>English value</Setting1>
<MyEnglishConfig>

<MeineDeuscheKonfiguration>
    <Einstellung1>deutscher Wert</Einstellung1>
</MeineDeuscheKonfiguration>

Upvotes: 1

Views: 375

Answers (1)

Marc Gravell
Marc Gravell

Reputation: 1062905

What is a good solution to do XML serialization in different languages (internationalization) so that tags and attributes are serialized to the same object with different language?

Don't! That simply isn't a good thing to do, and virtually no libraries will help you do it. By all means localize and internationalize a maintenance UI; but leave the xml in a single culture. This is just asking for extreme pain. The type of people who are going to be manually editing an xml file probably aren't going to mind if they need to read tags in a different language.

If you needed to do that, XmlAttributeOverrides can be used to make a per-language serializer, but... yeuch.

Upvotes: 2

Related Questions