2022-07-06 11:03 PM
Hi everyone,
I am currently trying to write a generic error dialog for displaying messages to users. To achieve this, I created a container with a TextArea with a single wildcard. The wildcard's initial value is set to "> text goes here <". Everything works fine as long as I use static error messages, such as "Wrong code".
However, now I'd like to show a more dynamic error message such as "Version mismatch! Expected: <v_expected> - Actual: <v_actual>" (e.g. "Expected: 1.2.3 - Actual: 3.2.1"). Now, the resulting message looks like this:
"Version mismatch! Expected: > text goes here < - Actual: ".
Notice that the initial wildcard text is set for the first value and the second wildcard is empty. Is it possible, to pre-replace wildcards and just pass the text with replaced wildcards as the input to the Error Dialog? I'd like to have localized error messages with dynamic content.
EDIT: I know that there is the possibility of having two (2) wildcards, however I'd like to be able to possibly pre-fill 3, 4 or more placeholders if at all possible.
2022-07-06 11:15 PM
le dot
2022-07-07 01:19 AM
Hello M-Schiller,
Your text translation looks good, but have you activated the 2 wildcards ?
Also, you need to have the "Use wildcard buffer" check boxes checked to modify the values of your wildcards.
Then, you can do in your code something like that :
Unicode::snprintf(textArea1Buffer1, TEXTAREA1BUFFER1_SIZE, "%d", expectedVersion);
Unicode::snprintf(textArea1Buffer2, TEXTAREA1BUFFER2_SIZE, "%d", currentVersion);
We have a very good tutorial that explains how to use multiple wildcards in the same TextArea widget, I recommend you to look at it :)
/Osman
2022-07-07 01:35 AM
Thanks for this detailed explanation. However, is it possible to have more than 2 wildcards or replace the wild cards in TypedTexts programmatically and just pass the "full text" (after replacements) to the single wildcard in the dialog?
2022-07-07 02:19 AM
No, 2 wildcards is the maximum you can have in one TextArea.
And so, yes I recommend you to use only 1 wildcard if you want more dynamic values.
To do it, you can use the strncpy function like that :
char textToDisplay[TEXTAREA1_SIZE];
snprintf(textToDisplay, TEXTAREA1_SIZE, "Expected : %d - Actual : %d", expectedVersion, currentVersion);
Unicode::strncpy(textArea1Buffer, textToDisplay, TEXTAREA1_SIZE);
But remember to add the wildcard range / wildcard characters that you need for your text (letters, numbers and special characters like semicolon, space etc..)
Also, your buffer must be big enough to contain your text.
/Osman
2022-07-07 03:56 AM
How would I get the translation aspect into this? I'm writing an application in - for the time being - English and German. So, could I get
`Expected: %d - Actual: %d`, and
`Erwartet: %d - Tatsächlich: %d`, respectively, using TouchGFX' built-in translation facilities?
2022-07-08 12:52 AM
Hello,
In your case, using 2 wildcard is totally fine.
So just create a TextArea with 2 wildcards like I said in my first message.
Then, go to Texts on the left panel and cliick on the "+" button add a new language.
You should have something which looks like this :
Notice that all your translation must have the same number of wildcard.
If you want to change language through TouchGFX Designer, go to "Config" > "General" and change the "Selected Language"
if you want to change the language through code, you can use this function :
void touchgfx::Texts::setLanguage(touchgfx::LanguageId id)
The parameter touchgfx::LanguageId id correspond to the enum of LANGUAGES that you find in TextKeysAndLanguages.hpp file.
/Osman