Pebble library to support locale features in apps/faces and select the correct text to display.
-
Run
pebble package install pebble-localize
. -
Include the library in any C files that will use it:
#include <pebble-localize/pebble-localize.h>
-
Add
locale_english.bin
,locale_french.bin
andlocale_whatever.bin
to your app resources. -
Modify your main function to use
localize_init()
andlocalize_deinit()
:
int main(void) {
// Init localize library
localize_init(RESOURCE_ID_OF_YOUR_CHOOSEN_LANGUAGE);
/* Other app setup code */
// DeInit localize library
localize_deinit();
}
- 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.json
andlocale_english.bin
. -
Move
locale_english.bin
to your project'sresources
directory. -
Make a copy of
locale_english.json
for other languages, such aslocale_german.json
. -
Modify
locale_german.json
to replace the English strings with German strings. -
Run
python dict2bin.py locale_german.json
. This will generatelocale_german.bin
. -
Move
locale_german.bin
to your project'sresources
directory. -
Add the new
.bin
resource files to your project'sappinfo.json
file 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!
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.