Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gettext without a filesystem

For an embedded system with GUI, we are using our custom translation system. The strings are stored in the code ROM of a microcontroller.

Currently we have up to 10 languages and about 400 translated strings (varies depending on the product variant).

Our current system is rather cumbersome and I believe that gettext would be a better solution.

As far as I understand gettext, it requires the use of bindtextdomain to set the directory containing the compiled translations files (*.mo).

Is there a way to instead read the translation from memory? That is I would like to include the compiled *.mo files in the binary, and set up gettext to use these. Alternatively, the translation data would be stored in a data EEPROM without a filesystem.

Or can you recommend a different translation system for use in a microcontroller system (16 or 32 bit, 256 to 512 kbyte ROM) with a C interface?

Edit: I should add that being able to maintain translations apart from the microcontroller firmware would be a reason to switch to gettext. The appropriate translation data would be loaded by the user with a configuration software that we already supply with our systems.

like image 213
Stephan Walter Avatar asked Jan 22 '13 09:01

Stephan Walter


People also ask

How does gettext () work?

Gettext works by, first, generating a template file with all the strings to be translated directly extracted from the source files, this template file is called a . pot file which stands for Portable Object Template.

What is gettext package?

gettext utilities are a set of tools that provides a framework to help other packages produce multi-lingual messages. The minimum version of the gettext utilities supported is 0.19.

Can PHP use gettext?

The gettext module in PHP only supports languages and language identifiers that are installed on your server. on the command line of your server (e.g., by logging in with SSH). The command may require admin privileges and maybe not work on a hosted shared server.


1 Answers

This is what I would do: I would include the binary ".mo" in constant variables in the code. You can write a simple converter from binary to a char array and have that ".mo" file compiled inside your program. You would have an array of ".mo" file data, each with a different language.

I would modify libintl sourcecode to access one of those arrays. Check the file loadmsgcat.c, the function _nl_load_domain. See there how it tries to use mmap() (so it's prepared to have everything in memory). Just add some code there to decide which element of your ".mo" array to use based on the language requested.

I haven't tried this, but this is what I would try given your situation. It doesn't look too hard.

like image 156
niqueco Avatar answered Sep 19 '22 13:09

niqueco