---
title: "Translations"
canonical_url: https://developer.repebble.com/pebbleos/docs/samples/subsys/i18n/catalog/
last_updated: 2026-11-18
sdk_version: 4.44
---
# Translations

Source: https://developer.repebble.com/pebbleos/docs/samples/subsys/i18n/catalog/

This sample translates strings with a French gettext catalog, using [internationalization](https://developer.repebble.com/pebbleos/docs/subsystems/i18n.md). The build compiles `po/fr_FR.po` with `msgfmt`, and `#embed` puts the result in the image; a catalog is read through a callback, so it could as well be in flash or a file.

Strings are looked up by their English original, and those without a translation stay in English, as all do without a catalog. A context tells apart originals that are the same word: the noun and the verb _Watch_. `pbl_i18n_get()` caches translations for an owner until it frees them; `pbl_i18n_get_with_buffer()` copies one into a buffer instead, truncated to fit.

Run:

`pbl samples samples/subsys/i18n/catalog`

Boards:

every board

## Sources

po/fr\_FR.po

```
msgid ""
msgstr ""
"Project-Id-Version: 3\n"
"Language: fr_FR\n"
"Name: Français\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"

msgid "Hello"
msgstr "Bonjour"

msgid "Your watch is charging"
msgstr "Votre montre est en charge"

msgctxt "noun"
msgid "Watch"
msgstr "Montre"

msgctxt "verb"
msgid "Watch"
msgstr "Regarder"
```

src/main.c

```
#include \<errno.h\>#include \<stdint.h\>#include \<stdio.h\>#include \<string.h\>#include \<pbl/i18n/i18n.h\>/\* A gettext MO file, compiled from po/fr\_FR.po at build time. \*/static const uint8\_t s\_fr\_mo[] = {#embed "fr\_FR.mo"};/\* Catalogs are read through a callback, so they can live in flash, a file or memory. \*/static int prv\_read(void \*data, uint32\_t offset, void \*buf, size\_t length) {if (offset \> sizeof(s\_fr\_mo) || length \> sizeof(s\_fr\_mo) - offset) {return -EINVAL;}memcpy(buf, &s\_fr\_mo[offset], length);return 0;}static const struct pbl\_i18n\_catalog s\_catalog = {.read = prv\_read,.size = sizeof(s\_fr\_mo),};/\* Translations from pbl\_i18n\_get() are cached per owner, here this file, until freed. \*/static const int s\_owner;static void prv\_print(const char \*when) {printf("i18n: %s: %s / %s / %s / %s\n", when, pbl\_i18n\_get("Hello", &s\_owner),pbl\_i18n\_ctx\_get("noun", "Watch", &s\_owner), pbl\_i18n\_ctx\_get("verb", "Watch", &s\_owner),pbl\_i18n\_get("Good night", &s\_owner));pbl\_i18n\_free\_all(&s\_owner);}int main(void) {struct pbl\_i18n\_catalog\_info info;char buf[16];int ret;prv\_print("no catalog");ret = pbl\_i18n\_catalog\_get\_info(&s\_catalog, &info);if (ret \< 0) {fprintf(stderr, "i18n: not a catalog (%d)\n", ret);return ret;}printf("i18n: catalog %s, %s, version %u\n", info.locale, info.name, info.version);ret = pbl\_i18n\_set\_catalog(&s\_catalog);if (ret \< 0) {fprintf(stderr, "i18n: catalog not set (%d)\n", ret);return ret;}printf("i18n: locale is now %s\n", pbl\_i18n\_get\_locale());/\* Strings without a translation stay in English. \*/prv\_print("French catalog");/\* No caching: the translation is copied into a buffer, truncated to fit. \*/pbl\_i18n\_get\_with\_buffer("Your watch is charging", buf, sizeof(buf));printf("i18n: %u characters, in %u bytes: %s\n",(unsigned int)pbl\_i18n\_get\_length("Your watch is charging"), (unsigned int)sizeof(buf),buf);(void)pbl\_i18n\_set\_catalog(nullptr);prv\_print("catalog removed");printf("Sample done\n");return 0;}
```

CMakeLists.txt

```
cmake\_minimum\_required(VERSION 3.20)find\_package(PebbleOS REQUIRED HINTS $ENV{PEBBLEOS\_BASE})project(i18n\_catalog)# The catalog is compiled from its .po and embedded into the image with #embed.find\_program(MSGFMT msgfmt REQUIRED)add\_custom\_command(OUTPUT ${CMAKE\_CURRENT\_BINARY\_DIR}/fr\_FR.moCOMMAND ${MSGFMT} --check -o ${CMAKE\_CURRENT\_BINARY\_DIR}/fr\_FR.mo${CMAKE\_CURRENT\_SOURCE\_DIR}/po/fr\_FR.poDEPENDS ${CMAKE\_CURRENT\_SOURCE\_DIR}/po/fr\_FR.po)add\_custom\_target(i18n\_catalog\_mo DEPENDS ${CMAKE\_CURRENT\_BINARY\_DIR}/fr\_FR.mo)add\_dependencies(app i18n\_catalog\_mo)target\_sources(app PRIVATE src/main.c)target\_compile\_options(app PRIVATE --embed-dir=${CMAKE\_CURRENT\_BINARY\_DIR})
```

## Output

```
i18n: no catalog: Hello / Watch / Watch / Good night
i18n: catalog fr_FR, Français, version 3
i18n: locale is now fr_FR
i18n: French catalog: Bonjour / Montre / Regarder / Good night
i18n: 26 characters, in 16 bytes: Votre montre es
i18n: catalog removed: Hello / Watch / Watch / Good night
Sample done
```

Generated from PebbleOS [7753e801d](https://github.com/coredevices/pebbleos/commit/7753e801d93d20f2d37534ce2fa69d9952015237). This page is maintained in the pebbleos repository: [docs/samples/subsys/i18n/catalog.md](https://github.com/coredevices/pebbleos/blob/7753e801d93d20f2d37534ce2fa69d9952015237/docs/samples/subsys/i18n/catalog.md).
