Locale Kit: localizing your application

Locale Kit: localizing your application

  • mdo  DigitalBox
  •   KitLab
  •   January 19, 2026

In the previous article we explored how to use the Locale Kit to adapt your application to the user’s regional settings — language, date, time, and number formats.

Now, we’ll go one step further: localizing your application’s user interface.

Haiku provides a powerful translation system that allows you to easily display text in multiple languages, without hardcoding different versions of your app.

Let’s see how it works in practice.


Overview of Haiku’s Translation System

Haiku’s translation framework relies on three main components:

  1. B_TRANSLATE() — a macro used to mark strings in your code for translation.

  2. .catkeys files — text files that list all the translatable strings and their translations.

  3. .catalog files — compiled binary catalogs used at runtime for fast translation.

This system is lightweight, developer-friendly, and completely integrated into the Locale Kit.


How It Works

When you wrap strings with B_TRANSLATE(), the Haiku build system (via make catkeys) extracts those strings into a .catkeys file.

Translators can then create localized versions of that file (e.g., fr.catkeys for French,  ja.catkeys for Japanese, etc).

Finally, make bindcatalogs compiles all .catkeys files into binary .catalog files that your application automatically uses at runtime.


Example: a simple translated application

Let’s create a minimal graphical application that displays a localized “Hello, World!” message centered in a window.

#include <Application.h>
#include <Window.h>
#include <View.h>
#include <Catalog.h>
#include <Locale.h>

// Define translation context
#undef B_TRANSLATION_CONTEXT
#define B_TRANSLATION_CONTEXT "HelloApp"

// Custom view that draws localized text
class HelloView : public BView
{
public:
    HelloView(BRect frame)
        :
        BView(frame, "hello_view", B_FOLLOW_ALL, B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE)
    {
        SetViewColor(255, 255, 255); // White background
    }

    void Draw(BRect updateRect) override
    {
        SetHighColor(0, 0, 0);
        SetFont(be_bold_font);
        SetFontSize(18.0);

        const char* text = B_TRANSLATE("Hello, World!");
        float stringWidth = StringWidth(text);
        BRect bounds = Bounds();
        float x = (bounds.Width() - stringWidth) / 2;
        float y = bounds.Height() / 2;

        MovePenTo(x, y);
        DrawString(text);
    }
};

// Simple window
class HelloWindow : public BWindow
{
public:
    HelloWindow(BRect frame)
        :
        BWindow(frame, B_TRANSLATE("Hello Window"), B_TITLED_WINDOW, B_QUIT_ON_WINDOW_CLOSE)
    {
        AddChild(new HelloView(Bounds()));
    }

    bool QuitRequested() override
    {
        be_app->PostMessage(B_QUIT_REQUESTED);
        return true;
    }
};

// Application class
class HelloApp : public BApplication
{
public:
    HelloApp()
        :
        BApplication("application/x-vnd-translateexample")
    {
    }

    void ReadyToRun() override
    {
        BRect rect(100, 100, 400, 300);
        (new HelloWindow(rect))->Show();
    }
};

int main()
{
    HelloApp app;
    app.Run();
    return 0;
}

Compile and Run

Create a file named "Makefile" with the below content:

## Haiku Generic Makefile

## Application name
NAME = LocaleTranslate

## Application type
TYPE = APP

## Sources
SRCS = LocaleTranslate.cpp

## Required libraries 
LIBS = be localestub stdc++

## Headers location 
# SYSTEM_INCLUDE_PATHS = 

## Ressources (icons, etc.)
# RSRCS = 

## Application signature
APP_MIME_SIG = application/x-vnd-translateexample

## Include Haiku engine makefile 
include $(BUILDHOME)/etc/makefile-engine

Compile it:

make

The localestub library enables the app to load .catalog files at runtime.

Run it once:

./objects.x86_64-cc13-release/LocaleTranslate

You should see a white window displaying “Hello, World!” centered in bold text:

At this stage the application is not yet localized.


Extracting translatable strings

Now generate the .catkeys file using the catkeys tool:

make catkeys

This generates a default catalog file:

locales/en.catkeys

It will contain entries like:

1   English application/x-vnd-translateexample  866582077
Hello, World!   HelloApp        Hello, World!
Hello Window    HelloApp        Hello Window

Each .catkeys file consists of:

  • A header line, with the following fields separated by tabs:

    • The file format version (usually 1)

    • The source language name (English)

    • The application MIME signature (application/x-vnd.translateexample)

    • A hash value automatically generated by the tools

  • One or more translation entries, each with:

    • The source string

    • The translation context (defined by B_TRANSLATION_CONTEXT in the source code)

    • An optional comment (used to help translators)

    • The translated string 

The last column is where translators will add the localized text.


Add translations

Let’s first create a French version.

Copy the .catkeys file and rename it:

cp locales/en.catkeys locales/fr.catkeys
Then edit the new file and fill in translations:
1   French  application/x-vnd-translateexample  866582077
Hello Window    HelloApp        Bonjour Fenêtre
Hello, World!   HelloApp        Bonjour, Monde!

Now let’s add a Japanese version.

Copy the .catkeys file and rename it:

cp locales/en.catkeys locales/ja.catkeys

Then edit the new file and fill in translations:
1   Japanese    application/x-vnd-translateexample  866582077
Hello Window    HelloApp        こんにちはウィンドウ
Hello, World!   HelloApp        こんにちは世界

You should now have the below files:

locales/
├── en.catkeys
└── fr.catkeys
└── ja.catkeys

Compile the translation catalogs

Modify the Makefile by adding the below lines:

## Locales 
LOCALES = en fr ja

Build the application:

make

Then type: 

make bindcatalogs

This command will automatically generate the compiled binary catalogs and embed them in your application for runtime use.

The "linkcatkeys" command is used for each translation defined in the ".catkeys" files.

You should see the binary .catalog in the ressources attached to the application:

xres -l ./objects.x86_64-cc13-release/LocaleTranslate



Test the Translation

  • Open Preferences → Locale.

  • Change your preferred language to French (or the one you translated).

  • Run your application again:

./objects.x86_64-cc13-release/LocaleTranslate

Your window title and text should now appear in French:

Repeat the same but for Japanese.

  • Open Preferences → Locale.

  • Change your preferred language to Japanese

  • Run your application again:

./objects.x86_64-cc13-release/LocaleTranslate

Your window title and text should now appear in Japanese:

Congratulations — your application now speaks multiple languages!


CatKeys Editor

Translators can use the CatKeys Editor to easily provide new translations.

You can install the CatKeys Editor application with pkgman:

pkgman install catkeyseditor

To edit a specific catkeys file, indicate the filename in the Terminal:

CatKeysEditor ./locales/fr.catkeys

Then for each "Source" indicate the corresponding "Translation" string in the corresponding language:


Tips

  • Use a unique signature (e.g., application/x-vnd.yourname-appname).

  • Use contexts wisely: each file or module can define its own B_TRANSLATION_CONTEXT.

  • Avoid concatenating strings: translate complete sentences instead.

  • Keep .catkeys under version control, but not the binary .catalog files.

  • When distributing, ensure the locales/ folder (or embedded catalogs) are included.


Conclusion

With this second article, we’ve completed our tour of the Locale Kit — from handling regional formats to translating your application’s user interface.

The Locale Kit demonstrates Haiku’s elegant approach to internationalization: translations are first-class citizens, not an afterthought.

Stay tuned, and keep on exploring Haiku kits !


Powered by Bludit - Hosted by Planet Hoster
© 2025 Haiku Insider