How to use lv_i18n (multilanguage)

Description

I need to use multilanguage in my project, and i tried to understand how to use lv_i18n,
I don’t have knowings in Node.Js or gettext, is there any example of using Internationalization with an example of ui project ?
anyone can help ?

What MCU/Processor/Board and compiler are you using?

eclipse simulator on windows 10

What LVGL version are you using?

LVGL 8.3.6

What have you tried so far?

I created a project with SLS and exported the code,
i cloned lv_i18n in /ui/ folder , and in main file i created

void ui_ext(void)
{
	/* Load translations & default locale (usually, done once) */
	lv_i18n_init(lv_i18n_language_pack);

	/* Set active locale (can be switched anytime) */
	lv_i18n_set_locale("en-GB");

	ui_init();
}

and i get error for trying to run as it is (test files) :
…\ui\lv_i18n\test\c\test.c:1:10: fatal error: unity.h: No such file or directory #include “unity.h”

for trying to extract texts to fill yml files :

lv_i18n extract -s '../ui/**/*.+(c|cpp|h|hpp)' -t 'translate/*.yml'

the error is : ‘h’ is not recognized as an internal command or external, an executable program or batch file.

so that i tried to fill yml files myself and compile with :

lv_i18n compile -t 'translation/*.yml' -o 'src/lv_i18n'

and the error :
image

any help ?
any tutorial or example of using i18n with ui ?

1 Like

it worked on linux but not in windows

I use " instead of '. So I have
npx lv_i18n extract "-s src/lvgl_apps/ui/**/*.+(c|cpp|h|hpp)" -t "locales\*.yml"

1 Like

thank you, I’ll try it, and I’ll get you in touch,
PS: I see that you use for link: ‘/’ for c sources and '' for the output file, is it correct or just a typo

this is copy/paste from one of my bat-file
another one have
npx lv_i18n compile -t "locales\*.yml" -o "src\resources\lv_i18n"

all worked
I think so :slight_smile:

Glory,

I got this error when I try to extract in Windows machine:

C:\Users\marck\Documents\Workspace\pep-gui\Demo\node_modules\lv_i18n\lv_i18n.js:17
throw err;
^
YAMLException: unacceptable kind of an object to dump [object Undefined]
at writeNode (C:\Users\marck\Documents\Workspace\pep-gui\Demo\node_modules\lv_i18n\node_modules\js-yaml\lib\js-yaml\dumper.js:779:13)
at writeBlockSequence (C:\Users\marck\Documents\Workspace\pep-gui\Demo\node_modules\lv_i18n\node_modules\js-yaml\lib\js-yaml\dumper.js:542:9)
at writeNode (C:\Users\marck\Documents\Workspace\pep-gui\Demo\node_modules\lv_i18n\node_modules\js-yaml\lib\js-yaml\dumper.js:763:9)
at writeBlockMapping (C:\Users\marck\Documents\Workspace\pep-gui\Demo\node_modules\lv_i18n\node_modules\js-yaml\lib\js-yaml\dumper.js:657:10)
at writeNode (C:\Users\marck\Documents\Workspace\pep-gui\Demo\node_modules\lv_i18n\node_modules\js-yaml\lib\js-yaml\dumper.js:750:9)
at dump (C:\Users\marck\Documents\Workspace\pep-gui\Demo\node_modules\lv_i18n\node_modules\js-yaml\lib\js-yaml\dumper.js:840:7)
at Object.safeDump (C:\Users\marck\Documents\Workspace\pep-gui\Demo\node_modules\lv_i18n\node_modules\js-yaml\lib\js-yaml\dumper.js:846:10)
at C:\Users\marck\Documents\Workspace\pep-gui\Demo\node_modules\lv_i18n\lib\translation_keys.js:202:36
at C:\Users\marck\Documents\Workspace\pep-gui\Demo\node_modules\lv_i18n\node_modules\lodash\lodash.js:4925:15
at baseForOwn (C:\Users\marck\Documents\Workspace\pep-gui\Demo\node_modules\lv_i18n\node_modules\lodash\lodash.js:2990:24) {
reason: ‘unacceptable kind of an object to dump [object Undefined]’,
mark: undefined
}

do you have yml files in the folder you want to extract to?
edit: perhaps they have incorrect formatting

I created an yml file with just the country code:

en:

Do I need to populate with the titles first? I was expecting for the extract function to create it.

yes usually that’s enough. I can suggest describing the error on lv_i18n git

The error was that you cant use words like “Análises” as a reference, just replaced for simple English words and now works.