Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Dynamic translation Attribute on portal view

PrakharM
Tera Contributor

Hello,

I have an attribute which on enabling that in the field of a table, it translates the value of the field from English to my desired language in the platform view. Now I want to configure the same attribute in the portal view of the same form. How can I do that?

9 REPLIES 9

Hello @Ehab Pilloor 
But that is only for work notes and comments right? I want for a specific field, for which I have an attribute which I have enabled. So I want for that field in portal view.

Hi @PrakharM,

There's no OOTB support for Dynamic Translation for fields in Portal view, but as Ankur has provided the link: How to Dynamically Translate Portal Content - Unofficial Guide , maybe you could build it in your instance. OOTB, Dynamic Translation supports translating HTML and string fields in native and workspace view, activity stream and translating knowledge articles.

 

Regards,

Ehab

@Ehab Pilloor , Can I use a UI Macro for the same functionality? Not sure though.

@PrakharM 

you can use a widget to handle this and somehow add that widget on your portal page.

something like this but please enhance, I just used hard-coded values, but you can make some API call which translates and shows the value to you

HTML:

<div class="container">
  <h2>English to Spanish Translator</h2>
  <div class="form-group">
    <label for="englishText">Enter English Text:</label>
    <textarea class="form-control" id="englishText" rows="3"></textarea>
  </div>
  <button class="btn btn-primary" id="translateBtn">Translate</button>
  <div class="form-group mt-3">
    <label for="spanishText">Spanish Translation:</label>
    <textarea class="form-control" id="spanishText" rows="3" readonly></textarea>
  </div>
</div>

Client Controller:

api.controller = function() {
    /* widget controller */
    var c = this;

    c.translate = function() {
        var englishText = document.getElementById('englishText').value;
        if (!englishText.trim()) {
            alert('Please enter some text to translate.');
            return;
        }

        // In a real-world scenario, you would call a REST API or Script Include here.
        // For demo, we use a simple mock translation.
        var mockTranslations = {
            "hello": "hola",
            "good morning": "buenos días",
            "thank you": "gracias",
            "please": "por favor",
            "how are you": "¿cómo estás?"
            // Add more as needed
        };

        var spanishText = mockTranslations[englishText.toLowerCase()] ||
            "Sorry, translation not found. For real translations, connect to a translation API.";

        document.getElementById('spanishText').value = spanishText;
    };

    // Attach event handler
    angular.element(document).ready(function() {
        document.getElementById('translateBtn').onclick = c.translate;
    });

};

CSS:

.container { padding: 20px; }
.form-group { margin-bottom: 15px; }
#translateBtn { margin-bottom: 15px; }

Output:

translate widget.gif

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

@PrakharM, sorry I am not familiar with UI Macro. I have implemented Dynamic Translation in my PDI and organisation and referred the knowledge I gained for answering your question. You can try what Ankur has suggested. 

You can refer https://www.servicenow.com/docs/bundle/yokohama-api-reference/page/app-store/dev_portal/API_referenc... for reference.

 

Regards,

Ehab Pilloor