In addition to the recent
dodgy Spanish localization, my
TweetStation fork now has dodgy French, Japanese, German and Italian translations (courtesy of the
Microsoft Translator API that was introduced at MIX10). Here's how they look:
The following two code snippets were added to
ngenstrings so that once the text has been extracted from TweetStation, it is automatically translated and written to
.strings
files ready for inclusion in the correctly-named
.lproj
folders (this code hasn't been committed to github - but it should be easy to add to your local copy).
add code to the end of MainClass.Main
string[] languages = new string[]{"fr","ja","it","de"};
foreach (var language in languages)
{
foreach (var table in tables.Values)
{
foreach (LocalizedString locstring in table.Values)
{
locstring.Value = Translate(locstring.Key, language);
}
table.WriteStringsFile(assemblyName, outputFormat, language);
}
}
add method to MainClass
//http://msdn.microsoft.com/en-us/library/ff512421.aspx
static string Translate (string text, string toLanguageCode)
{
string appId = "REGISTER_AND_INSERT_YOUR_APPID";
string translation = text;
text = text.Replace(" ", "%20").Replace("&", "").Replace("#","%3F");
string detectUri = "http://api.microsofttranslator.com/v2/Http.svc/Translate?appId=" + appId +
"&text=" + text + "&from=en&to=" + toLanguageCode;
Console.WriteLine(detectUri);
try {
System.Net.HttpWebRequest httpWebRequest = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(detectUri);
System.Net.WebResponse resp = httpWebRequest.GetResponse();
Stream strm = resp.GetResponseStream();
StreamReader reader = new System.IO.StreamReader(strm);
translation = reader.ReadToEnd();
}
catch (Exception e)
{
Console.Write("Translation failed for " + text + " - " + e.Message);
}
return translation;
}
Hopefully that gives you some ideas (or inspiration) on how to increase the market for your apps across the world. Remember that machine-translation is NOT a substitute for a professional human translation, however it can be useful to test your application's ability to handle and display different languages (eg. the size of the strings, etc).