Minimal framework to support locale features in Pebble apps, using
i18n_get_system_locale()
in Pebble Firmware 2.8+ to discover the system locale and select the correct
text to display.
-
Add
localize.h,localize.candhash.hto your project'ssrcdirectory. -
Add
locale_english.bin,locale_french.bin,locale_spanish.binandlocale_german.binto your app resources.
Note: Empty files (size 0) are used as placeholders so code can compile, and will fall back to English.
-
Add
#include <localize.h>to any code files that require translation. -
Modify your main function to use
locale_init():
int main(void) {
// Init locale framework
locale_init();
/* Other app setup code */
}- For all strings that you wish to localize, add
_()around them.
_("Breakfast Time");-
Run
python gen_dict.py src/ locale_english.json. This will generatelocale_english.jsonandlocale_english.bin. -
Move
locale_english.binto your project'sresourcesdirectory. -
Make a copy of
locale_english.jsonfor other languages, such aslocale_german.json. -
Modify
locale_german.jsonto replace the English strings with German strings. -
Run
python dict2bin.py locale_german.json. This will generatelocale_german.bin. -
Move
locale_german.binto your project'sresourcesdirectory. -
Add the new
.binresource files to your project'sappinfo.jsonfile as shown in the App Resources guide. For example, for the four language files in this project are added as shown below:
"media": [
{
"type": "raw",
"name": "LOCALE_ENGLISH",
"file": "locale_english.bin"
},
{
"type": "raw",
"name": "LOCALE_FRENCH",
"file": "locale_french.bin"
},
{
"type": "raw",
"name": "LOCALE_SPANISH",
"file": "locale_spanish.bin"
},
{
"type": "raw",
"name": "LOCALE_GERMAN",
"file": "locale_german.bin"
}
]- Compile your application and install!
You can easily test your translations by commenting line 11 and uncommenting
line 8 of localize.c, replacing "es" with a locale you are translating.
If you wish to add more translations in the future, repeat Generating Translation Resources to obtain new translation binary resources. You will also need to do this in the event that you modify any of your strings.