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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Answered

Translating commands

(4) ShareShare
ReportReport
Posted on by 16
Hi, guys!
 
How can I translate labels of custom ribbon commands based on the user's language Id?
 
I've translated the dialog/alert messages from javascripts already, using resx files. Is there a similar way to translate custom commands?
 
Thanks for any help!
Categories:
I have the same question (0)
  • Verified answer
    Daivat Vartak (v-9davar) Profile Picture
    7,835 Super User 2025 Season 2 on at
    Hello LP-29030017-0,
     

    You're on the right track with using resource files (.resx) for your JavaScript dialogs and alerts. Unfortunately, there isn't a direct, built-in mechanism like .resx files to translate custom ribbon command labels in Dynamics 365.

    However, you can achieve this through a combination of JavaScript and Web API calls to retrieve user language settings and then dynamically update the ribbon command labels.

    Here's the breakdown of the solution:

    1. Retrieve User Language Settings:

    • JavaScript Web API: Use the Dynamics 365 Web API to retrieve the user's language settings.

       

    • UserSettings Entity: Query the UserSettings entity to get the uilanguageid (user interface language ID).
       
    • function getUILanguageId(callback) {
          Xrm.WebApi.retrieveRecord("usersettings", Xrm.Utility.getGlobalContext().userSettings.userId, "?$select=uilanguageid").then(
              function success(result) {
                  if (result && result.uilanguageid) {
                      callback(result.uilanguageid);
                  } else {
                      console.error("Failed to retrieve user language ID.");
                      callback(null);
                  }
              },
              function (error) {
                  console.error("Error retrieving user language ID: " + error.message);
                  callback(null);
              }
          );
      }


    •  

    2. Store Translations:

    • JavaScript Object (Simplest): For a small number of translations, you can store them directly in a JavaScript object.

       

    • External Resource (More Scalable): For larger projects, consider storing translations in an external resource (e.g., a JSON file, a custom entity, or a web service).
       
    • var translations = {
          1033: { // English (United States)
              "myCustomCommandLabel": "My Custom Command",
              "anotherCommandLabel": "Another Command"
          },
          1031: { // German (Germany)
              "myCustomCommandLabel": "Mein benutzerdefinierter Befehl",
              "anotherCommandLabel": "Ein anderer Befehl"
          },
          // Add more languages as needed
      };


    •  

    3. Dynamically Update Ribbon Command Labels:

    • Ribbon Workbench or Customization.xml: Use the Ribbon Workbench or directly modify the Customization.xml to add JavaScript event handlers to your custom ribbon commands.

       

    • JavaScript Function: Create a JavaScript function that:

       


      • Retrieves the user's language ID using the getUILanguageId() function.

      • Looks up the corresponding translation from your translations object.

      • Updates the command label using the CrmRibbon.Control.setLabel() method.

      •  

      function updateCommandLabel(commandProperties) {
          getUILanguageId(function (languageId) {
              if (languageId && translations[languageId] && translations[languageId][commandProperties.CommandSourceId]) {
                  commandProperties.CrmRibbon.Control.setLabel(translations[languageId][commandProperties.CommandSourceId]);
              }
          });
      }

    •  

    4. Add Event Handlers to Ribbon Commands:

    • Ribbon Workbench:

      • Open the Ribbon Workbench.

      • Select your custom command.

      • Add an "Action" of type "JavaScript Function".

      • Select your JavaScript web resource.

      • Enter updateCommandLabel as the function name.

      • Add commandProperties as a parameter.

      •  

    • Customization.xml:

      • Modify the Customization.xml to add a JavaScript event handler to your command's <CommandDefinition> element.

      •  
    • <CommandDefinition Id="your.command.id">
        <Actions>        <JavaScriptFunction FunctionName="updateCommandLabel" Library="$webresource:your.javascript.webresource.name">            <CrmParameter Value="commandProperties" />        </JavaScriptFunction>    </Actions>
    •     </CommandDefinition>


    •  

    Important Notes:

    • Performance: Be mindful of the performance impact of Web API calls, especially if you have many ribbon commands.
    • Error Handling: Implement robust error handling in your JavaScript code.
    • Caching: Consider caching the user's language ID to avoid redundant Web API calls.
    • External Resources: If you use external resources for translations, ensure they are accessible from Dynamics 365.
    • Testing: Thoroughly test your solution with different user languages.
    • CommandSourceId: Use the CommandSourceId property of the commandProperties parameter to uniquely identify your commands.

    •  

    By following these steps, you can dynamically translate custom ribbon command labels based on the user's language settings.

     
    If my answer was helpful, please click Like, and if it solved your problem, please mark it as verified to help other community members find more. If you have further questions, please feel free to contact me.
     
    My response was crafted with AI assistance and tailored to provide detailed and actionable guidance for your Microsoft Dynamics 365 query.
     
    Regards,
    Daivat Vartak

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
Martin Dráb Profile Picture

Martin Dráb 45 Most Valuable Professional

#2
iampranjal Profile Picture

iampranjal 36

#3
Satyam Prakash Profile Picture

Satyam Prakash 31

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans