web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Language in x++

(0) ShareShare
ReportReport
Posted on by 351

Hi all,

 private str TranslateText(str inputStr, str _sourceLang = "en", str _targetLang = "ar")
    {
        System.String result;
        int len, OutputLen;
        str resultActual, url = "https://translate.googleapis.com/translate_a/single?client=gtx&sl="   _sourceLang   "&tl="   _targetLang   "&dt=t&q="   inputStr;
        System.Net.WebClient webClient = new System.Net.WebClient();
        webClient.set_Encoding(System.Text.Encoding::get_UTF8());
        result = webClient.DownloadString(url);
        len = result.get_Length();
        resultActual = result;
        OutputLen = strScan(resultActual, inputStr, 0, len);
       
        resultActual = subStr(resultActual, 0, (OutputLen - 2));
        resultActual = strRem(resultActual, "[");
        resultActual = strRem(resultActual, '"');
        resultActual = strRem(resultActual, ",");

        if(strLen(resultActual) == 0)
        {
            this.Description = this.orig().Description;
            
            return this.orig().NameAr;
        }
        
        return resultActual;
    }

As i mentioned the code its works great.

Now, i want to add this method as global method and i will use language id field that field based language i want to translate.

As i mentioned code i used in the modified field its English to Arabic come.

If i want to language id based translate what should i do ?

Etc:

Name | Language | translate text 

if i give it to in name and select language anything then i want to translate based on a language id.

Please give me a example.

Thanks  

I have the same question (0)
  • Verified answer
    Martin Dráb Profile Picture
    236,166 Most Valuable Professional on at
    RE: Language in x++

    Your change means that you'll have different default values, but I'm talking about that you can call the method with different parameters. For example:

    this.translateText('en', 'fr');
    this.translateText('tr', 'vi');

  • waytod365 Profile Picture
    351 on at
    RE: Language in x++

    Thanks sir,

    In this case  (str _sourceLang = currentUserLanguage() , str _targetLang = this.Language )

    Am i correct sir? if don't want default value what should i do sir ?

  • Martin Dráb Profile Picture
    236,166 Most Valuable Professional on at
    RE: Language in x++

    Your method already can be called with different values of _sourceLang and _targetLang. English and Arabic are just default values.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
CA Neeraj Kumar Profile Picture

CA Neeraj Kumar 2,340

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 835 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 640 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans