Extension.LoadString

Updated on

Extension.LoadString is a Power Query M function that retrieves a localized string resource by its identifier from the extension’s resources.

Compatible with: Power BI Service Power BI Desktop Excel Microsoft 365

Syntax

Extension.LoadString( string as text ) as nullable text

Description

The function takes a single parameter, string, which corresponds to a resource identifier in your extension’s localization file. If the identifier is found, the function returns the localized text. Otherwise, it returns null.

Examples

Extension.LoadString is commonly used in Power Query connectors to:

  1. Define user-friendly labels for connectors in various languages.
  2. Set descriptive tooltips and button texts in the Power Query UI.
  3. Provide consistent branding and localization for connector interfaces.

The following example demonstrates how Extension.LoadString integrates into a custom connector. This example also highlights its use alongside other extension features like authentication, branding, and publishing to the Power Query UI.

Connector Overview: “HelloWorld”

This connector greets users with a customizable message. It includes localized labels and descriptions using Extension.LoadString.

section HelloWorld;
 
[DataSource.Kind="HelloWorld", Publish="HelloWorld.Publish"]
shared HelloWorld.Contents = (optional message as text) =>
    let
        message = if (message <> null) then message else "Hello world"
    in
        message;
 
HelloWorld = [
    Authentication = [
        Implicit = []
    ],
    Label = Extension.LoadString("DataSourceLabel")
];
 
HelloWorld.Publish = [
    Beta = true,
    ButtonText = { Extension.LoadString("FormulaTitle"), Extension.LoadString("FormulaHelp") },
    SourceImage = HelloWorld.Icons,
    SourceTypeImage = HelloWorld.Icons
];
 
HelloWorld.Icons = [
    Icon16 = { Extension.Contents("HelloWorld16.png"), Extension.Contents("HelloWorld20.png"), Extension.Contents("HelloWorld24.png"), Extension.Contents("HelloWorld32.png") },
    Icon32 = { Extension.Contents("HelloWorld32.png"), Extension.Contents("HelloWorld40.png"), Extension.Contents("HelloWorld48.png"), Extension.Contents("HelloWorld64.png") }
];

In this example, the HelloWorld data source is defined with a Label property that uses Extension.LoadString to fetch a localized string. This label is displayed in the Power Query credential dialogs. Specifically this refers to:

HelloWorld = [
    Authentication = [ Implicit = [] ],
    Label = Extension.LoadString("DataSourceLabel")
];

Publish to UI

You can also provide the Publish record with UI information for Power Query so it’s visible in the ‘Get Data’ dialog. For instance:

HelloWorld.Publish = [
    Beta = true,
    ButtonText = { Extension.LoadString("FormulaTitle"), Extension.LoadString("FormulaHelp") },
    SourceImage = HelloWorld.Icons,
    SourceTypeImage = HelloWorld.Icons
];

HelloWorld.Icons = [
    Icon16 = { Extension.Contents("HelloWorld16.png"), Extension.Contents("HelloWorld20.png"), Extension.Contents("HelloWorld24.png"), Extension.Contents("HelloWorld32.png") },
    Icon32 = { Extension.Contents("HelloWorld32.png"), Extension.Contents("HelloWorld40.png"), Extension.Contents("HelloWorld48.png"), Extension.Contents("HelloWorld64.png") }
];

Here, the HelloWorld.Publish record contains important attributes that customize how the connector appears in the “Get Data” dialog.

  • ButtonText: Uses Extension.LoadString for both the display name and tooltip.
  • SourceImage and SourceTypeImage: Specify icons for branding.
  • The HelloWorld.Icons record also references image files for different sizes. These icons are displayed in the Power Query interface.

Learn more about Extension.LoadString in the following articles:

Other functions related to Extension.LoadString are:

Contribute » | Contributors: Rick de Groot

2023-2024 © BI Gorilla. All rights are reserved. Information from Microsoft docs is property of Microsoft Corp. | Privacy Policy