s00500 / ESPUI

A simple web user interface library for ESP32 and ESP8266

Home Page:https://valencia.lbsfilm.at/midterm-presentation/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

multi language interface

robvoi opened this issue · comments

I would like to add a language switch to the interface.
Is it possible to rename buttons, tabs, etc.?

Or is there a better approach to this?

Thanks for any advise.

I think the best approach would be to store the current language setting in the EEPROM and directly serve internationalised UI strings.

Do you have an internationalisation library that you’re using?

You can ask ESPUI to refresh the entire UI after selecting a new language, which would be cleaner than trying to dynamically change everything given how relatively infrequently the language would change.

I have no internationalization library. Everything hardcoded.
Multi language wasn't in scope at the beginning.

Can I use variables instead of the strings when defining the UI objects?
This would be a solution.

Or do the UI definition once per language and have the ESP pick the right one based on language?

Yes, either will work. Check out this function in one of the examples, where you can see a style string being dynamically generated. You could easily do something like that.

However, I think I'd be tempted to roll my own very rudimentary implementation. Something like this (I've not checked or compiled any of this but you get the idea):

#define NUMLANGS 2
int currentlang = 0;

String title[NUMLANGS] = {"hello", "bonjour"};

String getlang(String * s) {
  return s[currentlang];
}

//then later on

ESPUI.button(getlang(title),...);

Brilliant, thanks a lot!