Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extract will affect for comment _(xxx) #33

Open
Hpbbs opened this issue Apr 7, 2021 · 4 comments
Open

extract will affect for comment _(xxx) #33

Hpbbs opened this issue Apr 7, 2021 · 4 comments

Comments

@Hpbbs
Copy link

Hpbbs commented Apr 7, 2021

example follows:
in file xx.h

//#define CODE_CHECK_BTN_CONFIRM_TEXT _("#ffffff CHECKED#")
//#define CODE_CHECK_BTN_CANCEL_TEXT _("#ffffff CANCEL#")

#define PROTOCOL_HEADER _("protocol_header")
#define WEARABLE_HEADER _("wearable_header")
<<<<<
it will generate:
#ffffff CHECKED#
#ffffff CANCEL#
protocol_header
wearable_header

but first and second was not expected

@puzrin
Copy link
Collaborator

puzrin commented Apr 7, 2021

lv_i18n/lib/parser.js

Lines 11 to 28 in 8bf1fd3

const defaults = {
singularName: '_',
pluralName: '_p'
};
function create_singular_re(fn_name) {
return new RegExp(
'(?:^|[ =+,;\(])' + _.escapeRegExp(fn_name) + '\\("(.*?)"\\)',
'g'
);
}
function create_plural_re(fn_name) {
return new RegExp(
'(?:^|[ =+,;\(])' + _.escapeRegExp(fn_name) + '\\("(.*?)",',
'g'
);
}

Extractor does not process C semantics. It uses simple regexps to search patterns. Even if we invent kludge for single line comments, multiline comment will fail.

No plans to fix, but if someone suggest PR it will be accepted.

@bubeck
Copy link
Contributor

bubeck commented Nov 8, 2022

Extractor is fragile for many more problems, like multi line strings, String concat with constants like LV_SYMBOL_WARNING "This is a warning with an icon".

What do you think about changing the extraction process:

  1. Ask user to use "-DLV_I18N_EXTRACT" to compile sources of to extract them.
  2. Change _() and _p() in case of LV_I18N_EXTRACT to generate strings with markers,
     printf(_("hello world"));

will be changed to

printf( "LV_I18N-START" "hello world" "LV_I18N-END");
  1. read throught binary and collect every string between "START" and "END".

What do you think?

@puzrin
Copy link
Collaborator

puzrin commented Nov 8, 2022

IMO that's very complicated => difficult to use.

I'd suggest to not invent anything new and borrow existing methods. For example, inspect how get_text()-based things work. Current regexp is quick and dirty, and probably can be improved. It was created becuse something good enough required very urgent.

@bubeck
Copy link
Contributor

bubeck commented Nov 9, 2022

I looked at xgettext at https://git.savannah.gnu.org/gitweb/?p=gettext.git;a=blob;f=gettext-tools/src/x-c.c;h=917bd7c88deb9cc2d19b975962dd3a1cd2014c4e;hb=HEAD

It is a very complicated c source containing a nearly full fledged (preprocessor) dealing specfically with all aspects of C. Additional parsers for other languages. For C only it is around 2400 LOC. I dont think, that we can transfer this to lv_i18n as it is way too complicated.

As lv_i18n deals with "mainly embedded" we can assume, that programmer take care of their notation to be lv_i18n compatible and keep the simple regex as a solution.

thanks for creating lvgl and lv_i18n!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants