Soluling home   Document home

Lazarus Localization and Internationalization

Lazarus Localization and Internationalization

Lazarus (Wikipedia) is an open-source Pascal IDE to create Windows, macOS, and Linux applications with Free Pascal. Lazarus uses the PO format to store the strings of the forms and resource strings. Soluling Desktop and Soluling Cloud support Lazarus PO files.

The end of the document contains links to get the full source code of the samples. After reading this document, we recommend reading a tutorial about how to use Soluling.

Internationalize your application

Start Lazarus and open your project. Choose Project | Project Options and select the i18n page. Check Enable i18n.

Project i18n settings

If you want to have the language files in a subdirectory, enter the name of the directory in PO Output Directory, for example, languages. If you leave it empty, the .pot and .po files are in the project directory.

Add the DefaultTranslator unit (or LCLTranslator that it uses) to the uses section of your main form. Use resourcestring strings in your code whenever you want to localize a string.

uses
  ..., DefaultTranslator;

resourcestring
  SHello = 'Hello World';

Build the project. When i18n is enabled, Lazarus writes all the strings from your form files and resource strings into a .pot file (e.g., simple.pot) in the PO output directory. This file is the original file that you localize. Lazarus updates it every time you build the project.

Select the language

When the application starts, DefaultTranslator looks for the PO file of the language of the operating system. The file must be named <application>.<language>.po, for example, simple.fi.po, and it must be in the application directory or in a languages or locale subdirectory of it. Deploy the localized PO files with your application.

To run your application in a specific language, enter

<yourapp> --lang <locale>

where the lang option specifies the language. To run simple.exe in Finnish, enter

simple.exe --lang fi

You can also change the language in code, for example, from a language menu, with SetDefaultLang of the LCLTranslator unit.

uses
  LCLTranslator;
...
SetDefaultLang('fi');

Desktop process Desktop process

  1. Start Soluling. Drag the .pot file (e.g., simple.pot) on Soluling or click the New from File or Files button and select the file.
  2. Project Wizard appears. Select the original language and the target languages, for example, Finnish, and complete the wizard.
  3. Translate the project.
  4. Choose Home | Build All to build the localized PO files. Make sure that Soluling creates the localized files with the <file>.<language>.po name in the same directory as the .pot file, for example, simple.fi.po. Set the output file name on the Output sheet.

Output file name settings

When you change the strings, build the project in Lazarus to update the .pot file, open the Soluling project, and choose Home | Scan. Soluling keeps the existing translations, and you only translate the strings that were added or changed.

Cloud process Cloud process

With Soluling Cloud, you localize the .pot file in your browser: upload the file, translate it in Translate, and download the localized PO files. You need a Soluling account. See the available Cloud plans.

Create a project

  1. Sign in at www.soluling.com and open Cloud > Dashboard for Projects, Users and Terminology.
  2. Click Add a new project, then Select files and pick the .pot file (e.g., simple.pot), or drag and drop the file onto the page. Click Create.
  3. On the next page, check the project's Name. It defaults to the file's name.
  4. Set the Original language to the language of your application, for example, English.
  5. Under Target languages, check the languages you want to translate to, for example, Finnish and German.
  6. Under Source type, select gettext/po file (.po, .pot).
  7. Click Create. The project appears on the dashboard, and its status changes to Ready once the file has been processed.

Translate the project

Click the project's green Translate button on the dashboard. Translate opens the project, and you can type the translations into the grid. Machine translation suggestions, translation memory, and spell checking are available there. You do not have to finish every language before moving on to the next step.

Get the localized files

  1. In Translate's top bar, click the project's name. It opens the project's Manage page, the same page that the project's Manage button on the dashboard opens.
  2. If you have translated something since the localized files were last built, the page says Localized files need to be built. Click Build localized files and wait until it finishes.
  3. The Files section lists the .pot file with a download button for each target language. Save each localized file next to the .pot file as <application>.<language>.po, for example, simple.fi.po.

Update the project

When you have built the project in Lazarus and the .pot file has changed, upload the new file, translate what is new or changed, and download the localized files again. On the dashboard, click the project's Update file button (the upload arrow), select the new file or drop it onto the page, and click Update. Existing translations are kept, so you only translate the strings that were added or changed.

The dashboard is one of four ways to use Soluling Cloud. You can also use the SoluCLI command-line tool, Soluling Desktop, or SoluMake, which can run the update and build steps in your build pipeline. See the Cloud tutorial for all of them.

Samples

GitHub and <data-dir>\Samples\Lazarus contain the following samples:

Directory Description Notes
Simple A simple application with two forms and a resource string. Contains the Lazarus project, the original simple.pot, the Soluling project, and the localized Finnish simple.fi.po. Try this first!

In addition, the PO, PHP, and Python samples show how to localize PO files.

Configuring Lazarus localization

You can configure how to localize your Lazarus PO file by selecting the item in the project tree, right-clicking, and choosing the Options menu. A source dialog appears that lets you edit the options. This source uses the following option sheets.

Settings