문제

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.

도움이 되었습니까?

해결책

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);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 sharepoint.stackexchange
scroll top