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.
Haiku’s translation framework relies on three main components:
B_TRANSLATE() — a macro used to mark strings in your code for translation.
.catkeys files — text files that list all the translatable strings and their translations.
.catalog files — compiled binary catalogs used at runtime for fast translation.
This system is lightweight, developer-friendly, and completely integrated into the Locale Kit.
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.
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;
}
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:
The localestub library enables the app to load .catalog files at runtime.
Run it once:

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

At this stage the application is not yet localized.
Now generate the .catkeys file using the catkeys tool:
This generates a default catalog file:
It will contain entries like:
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.
Let’s first create a French version.
Copy the .catkeys file and rename it:
Modify the Makefile by adding the below lines:
## Locales
LOCALES = en fr ja
Build the application:

Then type:

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
Open Preferences → Locale.
Change your preferred language to French (or the one you translated).

Run your application again:
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:
Your window title and text should now appear in Japanese:

Congratulations — your application now speaks multiple languages!
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:

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.
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 !