GUI_LANG_LoadTextEx issues

This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

  • GUI_LANG_LoadTextEx issues

    Hi,

    I have an application that uses multiple language support, however I have noticed an issue with strings ending in certain chars are not correctly handled.

    C Source Code

    1. #define CRLF "\r\n"
    2. static const uint8_t strings_english[] = {
    3. "English"CRLF /* STR_LANGSTRING */
    4. "Searching"CRLF /* STR_SEARCHING */
    5. "Load Banks Found"CRLF /* STR_LOADBANK_FOUND */
    6. "Load Selected"CRLF /* STR_LOAD_SELECTED */
    7. "Load Available"CRLF /* STR_LOAD_AVAILABLE */
    8. "Load Selected/Available:"CRLF /* STR_LOAD_SELECTED_AVAILABLE */
    9. };
    10. static const uint8_t strings_french[] = {
    11. "Français"CRLF /* STR_LANGSTRING */
    12. "recherche"CRLF /* STR_SEARCHING */
    13. "Bancs de charge trouvés"CRLF /* STR_LOADBANK_FOUND */
    14. "charge sélectionné"CRLF /* STR_LOAD_SELECTED */
    15. "charge disponible"CRLF /* STR_LOAD_AVAILABLE */
    16. "charge sélectionné/disponible:"CRLF /* STR_LOAD_SELECTED_AVAILABLE */
    17. };
    18. static const struct STRING_LANG {
    19. const uint8_t *pData;
    20. const uint32_t NumBytes;
    21. } lang_string_array[MAX_LANGUAGE] = {
    22. {strings_english, ARRAY_SIZE(strings_english)},
    23. {strings_french, ARRAY_SIZE(strings_french)},
    24. };
    25. static int _GetData(void *pVoid, const uint8_t **ppData, unsigned NumBytes, uint32_t Off)
    26. {
    27. uint8_t *pDest = (uint8_t *)*ppData;
    28. const struct STRING_LANG *current_lang = pVoid;
    29. int bytes_read = NumBytes > current_lang->NumBytes ? current_lang->NumBytes : NumBytes;
    30. memcpy(pDest, current_lang->pData + Off, bytes_read);
    31. //LOG_DEBUG("load lang: %s %u", current_lang->pData, NumBytes);
    32. //LOG_DEBUG("load lang: %s %u", pDest, bytes_read);
    33. return bytes_read;
    34. }
    35. bool language_init(void)
    36. {
    37. DEBUG_ASSERT(MAX_LANGUAGE == ARRAY_SIZE(lang_string_array));
    38. GUI_LANG_SetMaxNumLang(MAX_LANGUAGE);
    39. for (unsigned i = 0; i < MAX_LANGUAGE; i++) {
    40. GUI_LANG_LoadTextEx(_GetData, (void *)&lang_string_array[i], i);
    41. }
    42. return true;
    43. }
    Display All


    In the below example if i select a string I do not get the correct string returned, because some of the strings in strings_french are ending in 'é'.

    C Source Code

    1. GUI_LANG_SetLang(STRING_LANG_FRENCH);
    2. GUI_LANG_GetText(STR_LOAD_AVAILABLE);


    infact returns "charge sélectionné/disponible:", rather than the correct "charge disponible".

    I have found two workarounds:
    1. remove any 'é' at the end of strings, eg. change "charge sélectionné" to "charge sélectionne"
    2. change CRLF to either "\r\r\n" or "\r\n\n".

    Have you come across this before?
    Using STemWin V5.26.

    Cheers
    Spen
  • Hello Spen,

    I tried to run your code, but the symbol ARRAY_SIZE is undefined. Could you please tell me how this symbol is defined in your application? Thank you.

    Currently I don't know what might cause the behavior you described.

    Best regards,
    Adrian