Ohhh, yeees! Thank you for asking it. It’s possible via a feature that love the most.
It’s style binding: add/remove a style if a subject’s value is the same as a reference value. See the docs here.
So what you can do is:
Store the currently selected language in a subject.
Add a very simple observer callback in C code that calls lv_translation_set_language if the language subject’s value changes. See this about adding custom code.
To change font either:
Create 3 styles with 3 different fonts and bind them like <bind_style subject="language" name="style_cjk" ref_value="2/">
OR: Let’s say you have an font called font_title. From this lv_font_t * font_title will be exported, meaning in the observer_callback you can easily change this pointer like font_title = font_title_cjk. Just don’t forget to call lv_obj_report_style_change(NULL).
Thanks for the suggestion! It looks like it could work using styles and subjects, so I’ll give it a try.
I have one more question.
When I try to make a component reusable so that it can accept either label_text or translation_tag as below, the translation_tag always takes priority. As a result, if I only specify label_text, it does not behave as expected.
Thank you for looking into this.
I understand that, with the current version, splitting the component into two is the best solution.
I hope this will be improved in the near future.
I was able to switch the font style using the subject you suggested.
I have an additional question: I couldn’t figure out how to link the selected language in the LVGL Editor preview with the subject.
Is there any way to do this?