0

I have to make a program which translates a word from a language to another. Example, if I do translate("Hello","FR") the method must return "Bonjour".

The data is contained in a .NET dictionnary which is in a cache memory zone.

At first, I have to write the translations in a XML file but I don't know how to organize it and how to read it.

I'll have one dictionnary by langage, for example, i'll have

EN which contains 3 keys which are "Bonjour" - "Ola" - "Gutentag" with the same value, which is "Hello".

So, when i'll receive ("Bonjour", "EN"), i'll go in the dictionnary EN and return the value of the key Bonjour.

Bur I really don't see how to organize it in a XML at first to be able to set up all this sytem.

Is this a possibility?

<dico>
<en>
    <traduction id ="bonjour" name="hello"/>
    <traduction id ="hola" name="hello"/>
    <traduction id ="dormir" name="to sleep"/>
    <traduction id ="geld" name="argent"/>
    <traduction id ="por favor" name="please"/>
</en>
<fr>
    ...
</fr>

Can you help me please?

Ben
  • 3
  • 2
  • Use Google Translate. Here an example in VBA: http://www.analystcave.com/excel-google-translate-functionality/ – AnalystCave.com May 07 '15 at 09:23
  • To me, your model doesn't really work. I think you need a concept of start language and target language, otherwise when you have words that are the same in multiple languages, your key is no longer unique. Consider how your model would handle "no". It gets even worse when the same spelling means different things in different languages. For example "ape" in Italian means "bee" in English, and "sensible" in German means (if memory serves correctly) "sensitive" in English. – cf_en May 07 '15 at 09:31
  • Any way of organizing the XML is ok as long as it is convenient for you. I would only replace "name" param with something more obvious like "value". Here a link of reading XML in C#: https://support.microsoft.com/en-us/kb/307548 – AnalystCave.com May 07 '15 at 09:33
  • You have one key hello with 3 values : "Bonjour" - "Ola" - "Gutentag". So your dictionary is Dictionary> where first parameter is the key hello and the values in the List is the languages French, Spanish, German. – jdweng May 07 '15 at 09:37

2 Answers2

0

Following on my my comment above, a better model might be to have the dictionary key above the language element, e.g.

<dico>
  <lex id="hello">
    <en>hello</en>
    <fr>bonjour</fr>
    ...
  </lex>
  ...
</dico>

Although that might not work with the way that you need to query it, particularly when going from another language to English (or the language you use for the key).

cf_en
  • 1,661
  • 1
  • 10
  • 18
0

This looks fine to me.

For you question about how to read such a file you can check this question How to read xml file in C#.

In order to read id and name value, use node.Attributes["id"].Value.

Community
  • 1
  • 1