Prepare extension content for multiple languages
Every caption, label, and message you add to an extension is text a user reads, which means it's also text someone eventually translates. This unit covers how Business Central generates that translatable content and how you keep a translation current as the extension changes.
Generate the source translation file
Add the TranslationFile feature to app.json so a build generates a
Translations folder containing a .g.xlf file with every caption and
label your extension defines. Add GenerateCaptions if you want the
compiler to generate a caption automatically for objects and fields
that don't set one explicitly:
{
"features": [ "TranslationFile", "GenerateCaptions" ]
}
The generated .g.xlf file is a build artifact. Don't hand-edit it:
every build regenerates it from your object captions and labels, so any
manual change you make there is lost at the next build. Treat it as the
source you translate from, not a file you maintain directly.
Write labels with the right properties
Use the Label data type for text your code constructs at runtime,
such as a message shown in a dialog:
procedure ShowRatingMessage(CustomerNo: Code[20])
var
RatingUpdatedMsg: Label 'Risk rating for customer %1 was updated.', Comment = '%1 = Customer number';
begin
Message(RatingUpdatedMsg, CustomerNo);
end;
Commentexplains a placeholder to the translator, so%1isn't ambiguous out of context.Lockedmarks text that should never be translated, such as a fixed code or a URL. Locked labels are excluded from the generated.xlffile by default; set theGenerateLockedTranslationsfeature flag if you want them included anyway, for example so a translator can confirm a locked value is intentional.MaxLengthcaps how much of the label a bound field or property can display, which matters for captions bound to a fixed-width UI element.
Create and maintain the target translation file
A target file is a copy of the generated source file with a
target-language attribute and a <target> element added for each
<trans-unit>. Name it <extensionname>.<language-tag>.xlf, for
example ContosoRiskManagement.fr-FR.xlf, and keep exactly one target
file per language:
<trans-unit id="Table 50100 - Field 50100 - Property Caption" size-unit="char" translate="yes" xml:space="preserve">
<source>Risk rating</source>
<target>Cote de risque</target>
<note from="Developer" annotates="general" priority="2">GenerateCaptions</note>
</trans-unit>
The id attribute ties a translation unit to a specific object, field,
or label in your extension, so it stays stable across builds as long as
you don't rename or delete the item it refers to. When you add a
caption or label, the next build adds a matching, untranslated
<trans-unit> to the source file; you then add the corresponding
<target> element to each target file you maintain.
Validate a target file after a code change
Because a target file's translation units are tied to specific objects and labels, a code change that adds, renames, or removes translatable content leaves the existing target file incomplete or stale. After you build:
- Compare the current
.g.xlfsource file against your target file and identify every<trans-unit>idpresent in the source but missing a corresponding, translated entry in the target. - Add a
<target>element for each new or changed unit. Don't assume an untranslated unit is harmless: an incomplete target file still ships, and users viewing that language see the untranslated source text for anything missing. - Confirm that units for objects you removed or renamed are also removed from the target file, so it doesn't carry translations for text that no longer exists.
Also verify the file-level target-language, preserve every generated
trans-unit ID exactly, and keep placeholders such as %1 in the
translated text. The ID links the target entry to the source entry.
Changing it creates an orphaned translation rather than translating the
intended label. A missing placeholder can change the message meaning or
cause runtime formatting problems.
Build the extension again after you update the target file. Confirm that the package contains the target XLIFF file and that the build reports no translation-file errors. For a release review, compare the source and target files by ID and record any intentionally untranslated units with a reason. This evidence is more reliable than checking only a few captions in the client.
Treat translation validation as part of finishing a code change, not a separate task you can defer. A caption that compiles cleanly but has no matching translated entry is still an incomplete deliverable for any tenant running that language.
For the current feature flags and XLIFF workflow, see Work with translation files.