Skip to content

1.3.0

Compare
Choose a tag to compare
@tobozo tobozo released this 14 Dec 22:32
· 21 commits to main since this release
3c93b4e

Changes

  • Tested and enabled support for Teensy core
  • Added i18n setLocate() + yaml/json gettext() as an optional module

I18n and L10N support

Note: Support is disabled with WIO Terminal (needs a proper fs::FS implementation).

  • Load the module with #include <i18n/i18n.hpp>.
  • Assign a filesystem with i18n.setFS().
  • Load a locale with i18n.setLocale().
  • Use i18n.gettext() to access localized strings.
#include <LittleFS.h>
#include <ArduinoJson.h>
#define YAML_DISABLE_CJSON // not needed here
#include <YAMLDuino.h>
#include <i18n/i18n.hpp>

// Sample example `/lang/en-GB.yml` stored in LittleFS:
//
// en-GB:
//   hello: world
//   blah:
//     my_array:
//     - first
//     - second
//     - third


void setup()
{
  Serial.begin(115200);
  LittleFS.begin();

  i18n.setFS( &LittleFS ); // assign LittleFS
  i18n.setLocale("en-GB"); // will load "/lang/en-GB.yml" language file

  Serial.println( i18n.gettext("hello" ) ); // prints "world"
  Serial.println( i18n.gettext("blah:my_array:2" ) ); // prints "third"
}


void loop()
{

  delay(1000);
}