Create and use label files

Completed

You can use label files to store text localizations for a user interface (UI). To fully support multiple languages for a UI, the best practice is to use labels for all text that’s used in the UI, including:

  • Properties such as Label, Description, and Help text.
  • Information, warnings, or errors that might be returned in the UI.

You can create and modify labels in Microsoft Visual Studio. We don’t recommend that you change standard labels. Rather, you should create your own customized labels.

Create label files

Before you can use labels, you need to create them in a label file.

To find all current labels, go to Application Explorer > Label Files. Typically, the labels are named as the module in Dynamics 365 (one label file for Accounts Payable, one for Accounts Receivable, and similar). You should create one label file for each language.

The naming and numbering of label files depend on the policies that you’re using for development.

Best practices for label files are to use a clear name, such as the solution name, and then use a descriptive label ID for each one.

To add label files to a project, follow these steps:

  1. Go to the Solution Explorer window and right-click the project or activate the context menu, and then select Add. New Item.

  2. Select Label and Resources, Label file. The Label file Wizard will appear, as shown in the following screenshot.

    Screenshot of the Label file Wizard.

  3. Enter a value in Label file ID, and then select Next to select languages, but you can add them later, too. A summary preview of the label file creation process displays.

  4. If your entries appear correct, select Next. In Solution Explorer, notice that one label file for each language is created in your project, as shown in the following screenshot.

    Screenshot of the summary preview.

To add labels into a label file, follow these steps:

  1. Open the file in the designer, which lists all labels for a label file and language, see the following screenshot.

    Screenshot of the file designer and the selection of a CustName label file.

  2. To create a label, select New. A new row for labels is created.

  3. Enter a Label ID and a label. We recommend that you add a description, such as a task number. Examples of good label names to use are as follows:

    • Label file name - MyLabelFile
    • Label ID - CustName
    • Label string - My cust name
  4. If you’re supporting more than one language, you need to create a Label ID for applicable languages in each label file.

You can’t use label files unless you build them.

Use label files

All text in a UI should have a label created. You need to set up some labels on a property and other elements in X++.

The simplest way to use a label is to find it in the label file by following these steps:

  1. Open the label file in Application Explorer or Solution Explorer in the designer.
  2. Copy the row with the label (right-click or activate the context menu, and then select Copy or Ctrl+C).
  3. Go to the property or X++ and paste (right-click or activate the context menu, and then select Paste or Ctrl+V).

The following example shows how the inserted label should appear:

@MyLabelFile:CustName (Label File Id and Label Id)

The language that you use for a label is dependent on the functionality. Typically, you would use the language from the user; occasionally, a language-specific label is used, such as using English for an invoice to an English customer.

The following code sample illustrates how labels in X++ might appear:

internal final class MyRunnableClassLabel
{
   /// <summary>
   /// Class entry point. The system will call this method when a designated menu 
   /// is selected or when execution starts and this class is set as the startup class.
   /// </summary>
   /// <param name = "_args">The specified arguments.</param>
   public static void main(Args _args)
   {
       Info(strFmt('@MyLabelFile:CustName'));
   }
 
}

You can’t extend labels out of the box, but you can create a label in the label wizard with the postfix _Extension, such as Sys_Extension. Use the language that you want, and then create a label that has the same Label ID as in the Sys label file, giving it a new text. Now, the system uses the newly created label instead of the standard label.