diff --git a/ReadMe.md b/ReadMe.md index 3f7e04e..66d6e95 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -252,6 +252,60 @@ YAML::setYAMLIndent( 3 ); ---------------------------- +## I18N and L10N + + +Sample example `/lang/en-GB.yml` stored in LittleFS: + +```yml +en-GB: + hello: world + blah: + my_array: + - first + - second + - third + +``` + +Load the module with `#include `, assign a filesystem with `i18n.setFS()` +and a locale with `i18n.setLocale()`, then use `i18n.gettext()` to access localized strings. + + +```cpp + +#include +#include +#define YAML_DISABLE_CJSON // not needed here +#include +#include + + +void setup() +{ + Serial.begin(115200); + LittleFS.begin(); + + i18n.setFS( &LittleFS ); + i18n.setLocale("en-GB"); // loads "/lang/en-GB.yml" file from LittleFS + + Serial.println( i18n.gettext("hello" ) ); // prints "world" + Serial.println( i18n.gettext("blah:my_array:2" ) ); // prints "third" +} + + +void loop() +{ + + delay(1000); +} +``` + + +---------------------------- + + + ## Debug diff --git a/src/i18n/i18n.cpp b/src/i18n/i18n.cpp index 49313e5..28add7e 100644 --- a/src/i18n/i18n.cpp +++ b/src/i18n/i18n.cpp @@ -28,6 +28,8 @@ * \*/ +#if !defined WIO_TERMINAL + #include "./i18n.hpp" #include @@ -249,3 +251,5 @@ bool i18n_t::loadLocale() return true; } + +#endif // defined WIO_TERMINAL diff --git a/src/i18n/i18n.hpp b/src/i18n/i18n.hpp index 82ccfbe..d79f0ea 100644 --- a/src/i18n/i18n.hpp +++ b/src/i18n/i18n.hpp @@ -31,12 +31,10 @@ #pragma once -#if defined WIO_TERMINAL - #include -#else - #include -#endif +#if !defined WIO_TERMINAL + +#include #include @@ -93,3 +91,5 @@ struct i18n_t static i18n_t i18n; + +#endif // defined WIO_TERMINAL