Question

I am using a visual webpart to show custom content that I get from a custom web service. I want to translate that custom content dynamically in SharePoint.

Resource file is not an option since that is static. Can we do this by using the Machine Translation Service?

Note: My current code is in SSOM. Client side / JS solutions are also appreciated.

Était-ce utile?

La solution

Found out the answer. Apparently, it is possible to do this using Machine Translation Services.

You can call the service on demand and it'll translate the text for you. Found the code in msdn. The examples here only dealt with files, so modified it a bit to work with strings.

        SPServiceContext sc = SPServiceContext.GetContext(new SPSite("site"));
        string myCulture = "ar";
        SyncTranslator job = new SyncTranslator(sc, CultureInfo.GetCultureInfo(myCulture));
        Byte[] inputByte;
        Byte[] outputByte;
        inputByte = Encoding.ASCII.GetBytes("hello");
        outputByte = null;
        TranslationItemInfo itemInfo = job.Translate(inputByte, out outputByte,"txt");
        string result = System.Text.Encoding.UTF8.GetString(outputByte);
Licencié sous: CC-BY-SA avec attribution
Non affilié à sharepoint.stackexchange
scroll top