One of the lesser-known features in Dynamics 365 v9.0 is the ability to include localized strings in web resources. In the past, developers resorted to coming up with their own ways to handle this. This usually involved code to determine the current language and then hardcoding strings directly in the JavaScript or storing values in XML files or entities and writing more code to retrieve values themselves. Now using resource files (RESX) and a new JavaScript method you can store the values in a structured manner and use a single line of code to retrieve the correct value.

When creating the resource files for each language there are few points that need to be remembered. In the web resource, you’ll need to include the numeric language code in the Name as well as specify the Language type in the Content settings. In this example, 1033 is English and 1036 is French. Also, make sure the key is the same in each file – example “Greeting.”

In this example, Visual Studio is being used to create the RESX files but under the hood, they are just XML files. The schema is a bit complex so if possible use a tool to create them rather than doing it manually.

language localized web resources

language localized web resources

In order to get a localized value from one of these files you can use the new “Xrm.Utility.getResourceString” method. The first parameter is the first part of the web resource Name including the prefix. The second is the key from the RESX file. The specific language is not defined anywhere. The result will come from the RESX file that matches the logged in user’s default language. If it doesn’t exist, it will fall back to the organization’s base language.

language localized web resources

The last important piece that needs to be done is to associate the RESX files you might need with the JavaScript web resource. This ensures that when the JavaScript file is loaded it will also load any other associated web resources without needing to add them directly to any forms that might require them.

language localized web resources

Once the setup is complete, you can bind scripts to form events as you normally would.

The resulting alert displays the value based on the logged in user’s language selection with is found under the user options.

When the language is set to English, the result comes from the English RESX file.

When the language is set to French, the result comes from the French RESX file.

language localized web resources

There you have it! For more helpful Dynamics 365 tips and tricks check out our blog.

Happy Dynamics 365’ing!

Avatar for Joe D365

Joe D365

Joe D365 is a Microsoft Dynamics 365 superhero who runs on pure Dynamics adrenaline. As the face of PowerObjects, Joe D365’s mission is to reveal innovative ways to use Dynamics 365 and bring the application to more businesses and organizations around the world.