I am working with Microsoft Translator (http://msdn.microsoft.com/en-us/library/ff512422.aspx).
Specifically the TranslateArray()
method which basically takes a string array of texts to translate and the result is an array with the translated text.
The resulting translation comes with a type of TranslateArrayResponse[]
.
My code looks something like this (shortened down for clarity)
string[] sourceTranslate = new string[3] {"My name is Peter", "Her name is Suzan", "We have fun"};
....
TranslateArrayResponse[] result = client.TranslateArray("", sourceTranslate, "en", "de", options);
The challenge with the client.TranslateArray()
method is that it only allows each request to be 10,000 characters and number items a maximum of 2000. My sourceTranslate
(a resx file) easily contains more than 10,000 characters, so to get around this I am splitting up requests to fit these boundaries.
My question is how do I copy the value result
to a string[] or similar - I need to work later with the result
(i.e. saving the results back to a new resx file)?
Obviously stuff like result += ...
won't work.
There are various ways to do this.
A straightforward one is to create a new string step by step while looping over the array of
TranslateArrayResponse
values - according to the docs, each of them has aTranslatedText
property of typestring
:Another solution is to use the LINQ
Select
method to extract the translated text from each item and then thestring.Join
method to concatenate the result enumeration of strings: