Delphi FireMonkey Localization
Localize a Delphi FireMonkey application once for every platform: Soluling reads your Delphi project, lets you translate the forms and resource strings, checks the translations, and builds one multilingual resource file that works on Windows, macOS, iOS, Android, and Linux.
Mobile platforms don't support resource DLLs, so FireMonkey applications carry their translations in a resource file that Soluling's Delphi library reads at runtime. This guide uses the Driving sample, a small driving time calculator, and takes it from an English-only application to one that speaks Finnish, German, and Japanese and can change its language while it runs.
.exe, and on macOS, iOS, Android, and Linux inside the application package or the documents folder.- Input
- Delphi project (
.dproj) with its compiled application and.drcfile - Output
- A multilingual resource file (
NtLangRes.ntres) to embed or deploy, or a language file for each language (fi.ntlang) - Runtime
- Soluling's Delphi library loads the language and translates the forms with
_T; it also changes the language at runtime - Preview
- Visual form editor that shows the forms in each language
On this page
- Tutorial: localize a FireMonkey application step by step
- How FireMonkey localization works
- Choose and change the language
- Translate in Soluling Cloud
- Do and don't
- Typical localizability problems
- Troubleshooting
- The Driving sample
- FAQ
Localize a FireMonkey application, step by step
Six steps take the Driving sample from a hard-coded English application to a multilingual one.
Prepare: make the application localizable
The original Driving application writes its result like this:
HoursLabel.Text := IntToStr(hours) + ' hours';
MinutesLabel.Text := IntToStr(minutes) + ' minutes';
Internationalizing the application takes four changes:
-
Move the strings from code to resource strings. Declare them with
resourcestring, and add theNtResourceStringunit to the project. It hooks the RTL's resource string loading (Delphi 10.4 Sydney and later), so the resource strings come in the active language. -
Use one pattern for sentences with numbers. Don't build a sentence from pieces. The Driving sample stores the whole result as a plural pattern and formats it with
TMultiPattern.Format. See patterns. -
Translate the forms with
_T. Call_T(Self)fromFMX.NtTranslatorin theOnCreateevent of each form. With visual form inheritance, call it only in the base form. -
Create a DRC file. Choose Project | Options | Linking and check Output resource string .drc file. It gives each resource string its name, such as
SResultPlural.
zero form for the hours, so "0 hours" is left out. Plural forms are simplified here.
Using Delphi 10.3 Rio or older? Resource strings can't be translated at runtime there; wrap the strings in the _T function instead, and choose a source code scan method in step 02. See the Samples\Delphi\FMX\Version1 samples.
Add: create a Soluling project
Compile the application in Delphi, then drag and drop the Delphi project file (.dproj) on Soluling. Project Wizard starts.
- On the Scan method page, keep Application or library file (Delphi 10.4 Sydney and later), and check the configuration and the compiled files to scan. Soluling reads the forms and resource strings from them. The source code methods are for older Delphi versions.
- On the Options page, keep the default settings.
- On the Select Languages page, add the target languages, and click Finish.
One project serves every platform: the forms and strings are the same on Windows, macOS, iOS, Android, and Linux, so you translate them only once.
Translate: in the grid and the visual form editor
Each form appears in the project tree with its properties in the grid, and the resource strings under their units. Select a form, and the visual form editor shows it in the selected language. Selecting a row highlights its control.
- Machine translation and translation memory. Click Use Machine Translation to translate with Amazon, Claude, DeepL, Google, Microsoft, ModernMT, or MyMemory, and reuse earlier translations from translation memory and terminology.
- External translators. Send a translation package, an Excel file, or XLIFF to a translator, and import the results back. See teamwork.
- Translators in a browser. Upload the project to Soluling Cloud and let translators work in Translate.
Check: find problems before release
Pseudo translation. Click Translate | Pseudo Translations | Fill, build, and run the application. Pseudo translations are longer and use accented characters, so texts that don't fit and strings still in the code (shown in plain English) stand out. See pseudo translation.
Pseudo-translated Original build
Validation. Soluling validates translations while you type and in batch (Validation | Validate Translations): missing translations, inconsistent placeholders and patterns, duplicate hotkeys, and more. See validation.
Validation
Build: create the resource file
Choose Home | Build All. Soluling writes NtLangRes.ntres, a multilingual resource file with the forms, strings, and other resources in every language of the project. Use it in one of two ways:
-
Embed it. Add
NtLangRes.ntresto the Delphi project as anRCDATAresource namedNtLangRes(Project | Resources and Images), and compile. The application now contains every language, on every platform. -
Deploy it as a file. Deploy or download
NtLangRes.ntreswith the application, and setNtResources.ResourcePathbefore the first form is created if it is not in the default place. This lets you update translations without recompiling.
On the Delphi build options sheet, you can also create a language file for each language (fi.ntlang, de.ntlang, ...). Deploy the ones you need; adding a language doesn't change any installed file.
.exe and then in the documents folder; on the other platforms, in the documents folder of the application.Update: translate only what changed
When the application changes, compile it in Delphi and click Home | Scan. Soluling compares the new forms and resource strings with the project, keeps the existing translations, adds the new strings, and marks the rows whose original text changed so that their translations are checked again. Then build again: the resource file must match the current forms and strings. If you embed it, compile the application again too.
You can automate the scan and build steps in your build pipeline with the SoluMake command-line tool.
One multilingual resource file for every platform
The VCL loads a resource DLL for its language, but iOS and Android don't support resource DLLs, and FireMonkey applications usually ship one package with every language. So Soluling builds the translations into its own resource format. At runtime, Soluling's Delphi library reads the resource file, _T applies the translated form data to each form as it is created, and NtResourceString returns the resource strings in the active language.
FireMonkey on Windows only? You can also localize the compiled application like a VCL application, with localized files or resource DLLs; see the Binary version of the Driving sample and the Delphi VCL guide. The resource file approach of this guide can also be used in VCL applications.
Choose and change the language
The library starts the application in the device's language if the resource file has it, and otherwise in the original language. To start in a specific language, set DefaultLocale (for example, 'fi') in an initialization section, as the sample does. To let the user change the language, register the languages and show the language dialog of FMX.NtLanguageDlg. It loads the selected language and translates the open forms; the procedure you pass sets the texts that the code sets again:
// Unit1.pas in the Localized version of the Driving sample
procedure TForm1.FormCreate(Sender: TObject);
begin
NtResources.Add('English', 'English', SEnglish, 'en');
NtResources.Add('Finnish', 'suomi', SFinnish, 'fi');
NtResources.Add('German', 'Deutsch', SGerman, 'de');
NtResources.Add('Japanese', '日本語', SJapanese, 'ja');
_T(Self);
end;
procedure TForm1.Language1Click(Sender: TObject);
begin
TNtLanguageDialog.Select(procedure
begin
CalculateButtonClick(Self);
end);
end;
Translate in Soluling Cloud
With Soluling Cloud, translators use Translate in a browser. How you start depends on what you localize:
- Delphi projects. Soluling Cloud can't scan a Delphi project itself. Create the project in Soluling Desktop, and choose Translate | Configure Cloud to upload it. Use Import from Cloud to get the translations back and build the localized files locally. Your application files never leave your machine.
To run the scan, upload, import, and build steps in your build pipeline, use SoluMake. See the Cloud tutorial and workflows.
Do and don't
Do
- Use
resourcestringfor every string the user sees, and addNtResourceString. - Call
_T(Self)in theOnCreateevent of every form. - Create the DRC file, so the resource strings keep their names.
- Store whole sentences with placeholders, and use plural patterns for numbers.
- Use layouts and alignment that leave room for longer text.
- Build the resource file again whenever the forms or strings change.
Don't
- Use string constants (
const) for UI text; they are not resources. - Build sentences from pieces, such as
IntToStr(hours) + ' hours'. - Rename components without a reason; renamed rows lose their translations.
- Ship an old resource file with a new build; the form data must match.
- Plan on resource DLLs for iOS or Android; they don't support them.
Typical localizability problems
See also internationalization and pseudo translation.
| Problem | How it shows | Find and fix |
|---|---|---|
| Strings in code | English text in a pseudo-translated build | Move the strings to resourcestring sections. |
| A form is not translated | The form stays in the original language | Call _T(Self) in its OnCreate event, or in its base form. |
| Sentences built from pieces | Word order and plurals are wrong in the translation | Use one string with placeholders, or a plural pattern. |
| Controls only fit English | Clipped text in the pseudo or German build | Use layouts and alignment, or give the controls more room. |
| No DRC file | Resource strings have contexts that change when the code changes | Turn on Output resource string .drc file, compile, and scan. |
Troubleshooting
| Symptom | Likely cause | What to do |
|---|---|---|
| The application stays in English | The resource file is not embedded, or the library does not find it | Check the RCDATA resource named NtLangRes, or set NtResources.ResourcePath. |
| Resource strings stay in English | NtResourceString is not in the project, or Delphi is older than 10.4 |
Add the unit; on older Delphi versions, use _T for strings. |
| Forms show old or mixed texts | The resource file was built from an older version of the application | Scan and build again, and compile the application again if you embed the file. |
| Some texts stay in English after a language change | The code sets those texts | Set them again in the procedure you pass to TNtLanguageDialog.Select. |
| The file is not found on a mobile device | It is not deployed to the documents folder | Add it to the deployment of the platform, or embed it. |
The Driving sample
The sample is in Samples\Delphi\FMX\Driving of the Soluling installation and on GitHub. It has three projects of the same application:
- Original: the English application before internationalization, with hard-coded strings.
- Localized: internationalized, with a resource file and a runtime language switch, for every platform.
- Binary: localized from the compiled file, like a VCL application, for Windows.
The Samples\Delphi\FMX folder has more samples, for example, images, message dialogs, and the _T function for older Delphi versions. See FireMonkey localization and Delphi localization in the Desktop documentation for all the details.
FAQ
_T function for strings and a source code scan method._T work in VCL applications too. Most VCL applications use resource DLLs instead; see the Delphi VCL guide.Related
- FireMonkey localization - the full Desktop documentation
- Delphi localization - the Delphi library and the localization methods
- Runtime language change - in Delphi and other platforms
- Supported formats - everything else Soluling localizes