Power BI Custom Connectors are something amazing and while they are still in a public preview phase, there are many things that are specific to custom connectors that go beyond what we used to know about M code.
This post tries to cover how you can make your custom connector have a UI based on the language of your Power BI Desktop installation using the Extension.LoadString function.
You can follow along by getting my Power BI REST API Custom Connector from here.
The .RESX File
Every time that you start a Custom Connector project you’ll notice that VS automatically creates a series of files from a template. One of those files has a .resx extension and this is a file where you can store multiple text strings that you can later use anywhere in your custom connector. It looks like this:
By default, PQSDK (VS) only creates one .resx file by the name of ‘resources.resx’, but you can add more .resx files by following a format like ‘resources.es.resx’ where ‘es’ is the 2 letter language code as in ISO 639-1
The easiest way to create this new .resx file is to go to your project’s folder and manually create a copy of your resources.resx file and then rename it as desired following the previously described format.
When entering the Name values, make sure that you use the same ‘Name’ field in all of your resx files, but you can use the ‘Value’ column to enter the correct string that should go for that specific language file. Your resx files don’t necessarily need to have the same amount of ‘Names’, but it is recommended that you keep parity across all of your resx files at the Name column and what needs to be different is only the text strings on the ‘Value’ column.
Using the Extension.LoadString function in your Custom Connector Code
This is the cool part. Now that we have all the strings stored in the resx files, we’re going to call those inside of our code. But how? This is where the Extension.LoadString function comes through.
I want my language to change depending on the Power BI Desktop install language, but I only want to change the display language at the Navigator window and for that I need to change my Navigation Table Functions so instead of using a fixed string, I’m using the Extension.LoadString(“NameOfParameterInMyRESXFile”) to load the correct text strings that should appear in the Navigator window. The only parameter of this function is the text string inside the ‘Name’ column of your resx, and the output would be the corresponding ‘Value’ field for that ‘Name’ – Power Query will take care of selecting the correct resx file to use depending on what version of Power BI Desktop you’re using.
This is pretty simple and clean. The result of that looks like this:
More use cases
I initially wanted to find out how I could make the UI of my connector go with exactly the language of the Power BI Desktop install that I’m using as you saw in the previous image BUT!!!! That’s not the only use case
Here’s a list of more use cases:
- UI interface for Connectors that require a parameters window
- We could combine the Extension.LoadString function with any of four functions to create text strings that appear in the same language of the Power BI Desktop install. For example, I could use this approach against my CalendarCreator Custom Connector to show the name of the months based on the Power BI Desktop install of the person if I chose that
- Documentation! Did you know that you can add the documentation of your function to the RESX files and that way people can understand your functions in the language of their Power BI Desktop install?
Hope that you find this post useful and let me know what you think about the Power BI Custom Connectors so far!
Excel specialist turned into BI specialist using the latest tools from Microsoft for BI – Power BI. He is the co-author of ‘M is for Data Monkey’, blogger and also Youtuber of powerful Excel video Tricks.
He has been recognized as a Microsoft Most Valuable Professional (MVP), is a Microsoft Certified Professional (MCP – MCSA: BI Reporting), a Microsoft Certified Trainer (MCT), and is one of the international pioneers in Power Pivot, Power Query and Power BI.