npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

pebble-localize

v0.1.2

Published

Pebble library to support locale features in apps/faces and select the correct text to display.

Downloads

6

Readme

pebble-localize

Pebble library to support locale features in apps/faces and select the correct text to display.

This library is a fork of the excellent locale_framework under MIT license. A lot of code has not been changed or just a little. All the credits go to @C-D-Lewis @mhungerford ! Thanks for your work

How to use

Install the library

  • Run pebble package install pebble-localize.

Generating Translation Resources

  • For all strings that you wish to localize, add _() around them.
_("Breakfast Time");
  • Run python gen_dict.py src/ locale_english.json. This will generate locale_english.json and locale_english.bin.

    gen_dict.py script can be found here

  • Move locale_english.bin to your project's resources directory.

  • Make a copy of locale_english.json for other languages, such as locale_german.json.

  • Modify locale_german.json to replace the English strings with German strings.

  • Run python dict2bin.py locale_german.json. This will generate locale_german.bin.

    dict2bin.py script can be found here

  • Move locale_german.bin to your project's resources directory.

  • Add the new .bin resource files to your project's appinfo.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"
  }
]

Call localize api in your code

  • Include the library in any C files that will use it:
#include <pebble-localize/pebble-localize.h>
  • Modify your main function to use localize_init() and localize_deinit():
int main(void) {
  // Init localize library with your choosen locale
  localize_init(RESOURCE_ID_LOCALE_SPANISH);

  /* Other app code */

  // Change the locale is possible
  localize_init(RESOURCE_ID_LOCALE_FRENCH);

  /* Other app code */

  // DeInit localize library to clean up resources
  localize_deinit();
}
  • Compile your application and install!

Memory optimization

In the first version of the package, the whole binary file was loaded during localize_init. So it consumed memory even if some strings were not really used in your app.
Now, strings are loaded on demand and then stored in cache for a fast access. By default the cache size is unlimited (of course the maximum size of your cache is the size of your binary file) but if you know only a certain number of strings are really used at the same time, you can configure the cache size and save memory.

  localize_set_cache_size(5); // 5 is the number of strings in the cache

Example :
Your watchface displays the name of the day. You will have 7 strings in you binary file but only one string is used at the same time.
With the default configuration, after 2 days the cache will contain 2 strings, after 5 days 5 strings, after 7 days 7 strings, after 21 days ... 7 strings.
If you call the localize_set_cache_size(1), the cache will contain only 1 string and you will save memory (the 6 other days are not saved in memory)

Adding More Languages

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.