diff --git a/docs/src/details/auxiliary-modules/translation.rst b/docs/src/details/auxiliary-modules/translation.rst index 0f0391d22f..5514eb4d9b 100644 --- a/docs/src/details/auxiliary-modules/translation.rst +++ b/docs/src/details/auxiliary-modules/translation.rst @@ -26,9 +26,10 @@ If most translations are known at compile time, they can be defined using string .. code-block:: c - static const char * languages[] = {"en", "de", "es", NULL}; - static const char * tags[] = {"tiger", "lion", "rabbit", "elephant", NULL}; - static const char * translations[] = { + /* Arrays are defined `const` to place them in program space instead of RAM. */ + static const char * const languages[] = {"en", "de", "es", NULL}; + static const char * const tags[] = {"tiger", "lion", "rabbit", "elephant", NULL}; + static const char * const translations[] = { "The Tiger", "Der Tiger", "El Tigre", "The Lion", "Der Löwe", "El León", "The Rabbit", "Das Kaninchen", "El Conejo", diff --git a/examples/others/translation/lv_example_translation_1.c b/examples/others/translation/lv_example_translation_1.c index 9a149fb0d5..c9c1bfbb50 100644 --- a/examples/others/translation/lv_example_translation_1.c +++ b/examples/others/translation/lv_example_translation_1.c @@ -3,9 +3,10 @@ static void add_static(void) { - static const char * languages[] = {"en", "de", "es", NULL}; - static const char * tags[] = {"tiger", "lion", "rabbit", "elephant", NULL}; - static const char * translations[] = { + /* Arrays are defined `const` to place them in program space instead of RAM. */ + static const char * const languages[] = {"en", "de", "es", NULL}; + static const char * const tags[] = {"tiger", "lion", "rabbit", "elephant", NULL}; + static const char * const translations[] = { "The Tiger", "Der Tiger", "El Tigre", "The Lion", "Der Löwe", "El León", "The Rabbit", "Das Kaninchen", "El Conejo", diff --git a/examples/others/translation/lv_example_translation_2.c b/examples/others/translation/lv_example_translation_2.c index eda5700a2e..d024e9b8b5 100644 --- a/examples/others/translation/lv_example_translation_2.c +++ b/examples/others/translation/lv_example_translation_2.c @@ -2,12 +2,13 @@ #if LV_USE_TRANSLATION && LV_USE_DROPDOWN && LV_USE_LABEL && LV_BUILD_EXAMPLES -static const char * tags[] = {"tiger", "lion", "rabbit", "elephant", NULL}; -static const char * languages[] = {"English", "Deutsch", "Español", NULL}; +/* Arrays are defined `const` to place them in program space instead of RAM. */ +static const char * const tags[] = {"tiger", "lion", "rabbit", "elephant", NULL}; +static const char * const languages[] = {"English", "Deutsch", "Español", NULL}; static void add_static_translations(void) { - static const char * translations[] = { + static const char * const translations[] = { "The Tiger", "Der Tiger", "El Tigre", "The Lion", "Der Löwe", "El León", "The Rabbit", "Das Kaninchen", "El Conejo", diff --git a/examples/widgets/label/lv_example_label_7.c b/examples/widgets/label/lv_example_label_7.c index efd1de8ee6..16c079638a 100644 --- a/examples/widgets/label/lv_example_label_7.c +++ b/examples/widgets/label/lv_example_label_7.c @@ -2,12 +2,13 @@ #if LV_USE_TRANSLATION && LV_USE_DROPDOWN && LV_USE_LABEL && LV_BUILD_EXAMPLES -static const char * tags[] = {"tiger", "lion", "rabbit", "elephant", NULL}; -static const char * languages[] = {"English", "Deutsch", "Español", NULL}; +/* Arrays are defined `const` to place them in program space instead of RAM. */ +static const char * const tags[] = {"tiger", "lion", "rabbit", "elephant", NULL}; +static const char * const languages[] = {"English", "Deutsch", "Español", NULL}; static void add_static_translations(void) { - static const char * translations[] = { + static const char * const translations[] = { "The Tiger", "Der Tiger", "El Tigre", "The Lion", "Der Löwe", "El León", "The Rabbit", "Das Kaninchen", "El Conejo", diff --git a/src/others/translation/lv_translation.c b/src/others/translation/lv_translation.c index 54ed553dd8..7d1407422a 100644 --- a/src/others/translation/lv_translation.c +++ b/src/others/translation/lv_translation.c @@ -84,8 +84,8 @@ void lv_translation_deinit(void) lv_free((void *)selected_lang); } -lv_translation_pack_t * lv_translation_add_static(const char * languages[], const char * tags[], - const char * translations[]) +lv_translation_pack_t * lv_translation_add_static(const char * const languages[], const char * const tags[], + const char * const translations[]) { LV_ASSERT_NULL(languages); LV_ASSERT_NULL(tags); @@ -102,9 +102,9 @@ lv_translation_pack_t * lv_translation_add_static(const char * languages[], cons pack->language_cnt++; } - pack->languages = languages; - pack->tag_p = tags; - pack->translation_p = translations; + pack->languages = (const char **)languages; + pack->tag_p = (const char **)tags; + pack->translation_p = (const char **)translations; return pack; } diff --git a/src/others/translation/lv_translation.h b/src/others/translation/lv_translation.h index 84e8db9183..cab96cf6f3 100644 --- a/src/others/translation/lv_translation.h +++ b/src/others/translation/lv_translation.h @@ -50,8 +50,8 @@ void lv_translation_deinit(void); * @param translations List of translations. E.g. `{"Dog", "Cat", "Hund", "Katze"}` * @return The created pack */ -lv_translation_pack_t * lv_translation_add_static(const char * languages[], const char * tags[], - const char * translations[]); +lv_translation_pack_t * lv_translation_add_static(const char * const languages[], const char * const tags[], + const char * const translations[]); /** * Add a pack to which translations can be added dynamically. diff --git a/tests/src/test_cases/test_translation.c b/tests/src/test_cases/test_translation.c index eaa9666032..78c93fe21f 100644 --- a/tests/src/test_cases/test_translation.c +++ b/tests/src/test_cases/test_translation.c @@ -27,9 +27,9 @@ static void on_language_change(lv_event_t * e) void test_set_language_sends_language_changed_event(void) { - static const char * tags[] = {"tiger", NULL}; - static const char * languages[] = {"en", "de", "es", NULL}; - static const char * translations[] = { "The Tiger", "Der Tiger", "El Tigre" }; + static const char * const tags[] = {"tiger", NULL}; + static const char * const languages[] = {"en", "de", "es", NULL}; + static const char * const translations[] = { "The Tiger", "Der Tiger", "El Tigre" }; lv_translation_add_static(languages, tags, translations); lv_obj_t * label = lv_label_create(NULL); diff --git a/tests/src/test_cases/widgets/test_label.c b/tests/src/test_cases/widgets/test_label.c index f36fa387dd..fdba121151 100644 --- a/tests/src/test_cases/widgets/test_label.c +++ b/tests/src/test_cases/widgets/test_label.c @@ -791,9 +791,10 @@ void test_label_wrap_mode_clip(void) } void test_label_translation_tag(void) { - static const char * tags[] = {"tiger", NULL}; - static const char * languages[] = {"en", "de", "es", NULL}; - static const char * translations[] = { "The Tiger", "Der Tiger", "El Tigre" }; + /* Arrays are defined `const` to place them in program space instead of RAM. */ + static const char * const tags[] = {"tiger", NULL}; + static const char * const languages[] = {"en", "de", "es", NULL}; + static const char * const translations[] = { "The Tiger", "Der Tiger", "El Tigre" }; lv_translation_add_static(languages, tags, translations); label = lv_label_create(NULL); lv_label_set_translation_tag(label, "tiger"); @@ -814,9 +815,10 @@ void test_label_translation_tag(void) void test_label_setting_text_disables_translation(void) { - static const char * tags[] = {"tiger", NULL}; - static const char * languages[] = {"en", "de", "es", NULL}; - static const char * translations[] = { "The Tiger", "Der Tiger", "El Tigre" }; + /* Arrays are defined `const` to place them in program space instead of RAM. */ + static const char * const tags[] = {"tiger", NULL}; + static const char * const languages[] = {"en", "de", "es", NULL}; + static const char * const translations[] = { "The Tiger", "Der Tiger", "El Tigre" }; lv_translation_add_static(languages, tags, translations); label = lv_label_create(NULL); lv_label_set_translation_tag(label, "tiger"); diff --git a/tests/src/test_cases/xml/test_xml_label.c b/tests/src/test_cases/xml/test_xml_label.c index f945977a24..f13f4eb535 100644 --- a/tests/src/test_cases/xml/test_xml_label.c +++ b/tests/src/test_cases/xml/test_xml_label.c @@ -64,9 +64,10 @@ void test_xml_label_with_attrs(void) } void test_xml_label_translation_tag(void) { - static const char * tags[] = {"tiger", NULL}; - static const char * languages[] = {"en", "de", "es", NULL}; - static const char * translations[] = { "The Tiger", "Der Tiger", "El Tigre" }; + /* Arrays are defined `const` to place them in program space instead of RAM. */ + static const char * const tags[] = {"tiger", NULL}; + static const char * const languages[] = {"en", "de", "es", NULL}; + static const char * const translations[] = { "The Tiger", "Der Tiger", "El Tigre" }; lv_translation_add_static(languages, tags, translations); lv_obj_t * scr = lv_screen_active(); @@ -116,9 +117,10 @@ void test_xml_label_translation_tag(void) void test_xml_label_both_text_and_translation_tag(void) { - static const char * tags[] = {"tiger", NULL}; - static const char * languages[] = {"en", "de", "es", NULL}; - static const char * translations[] = { "The Tiger", "Der Tiger", "El Tigre" }; + /* Arrays are defined `const` to place them in program space instead of RAM. */ + static const char * const tags[] = {"tiger", NULL}; + static const char * const languages[] = {"en", "de", "es", NULL}; + static const char * const translations[] = { "The Tiger", "Der Tiger", "El Tigre" }; lv_translation_add_static(languages, tags, translations); lv_obj_t * scr = lv_screen_active(); diff --git a/tests/src/test_cases/xml/test_xml_translations.c b/tests/src/test_cases/xml/test_xml_translations.c index 7ce5339d46..5be7b6d38d 100644 --- a/tests/src/test_cases/xml/test_xml_translations.c +++ b/tests/src/test_cases/xml/test_xml_translations.c @@ -26,10 +26,10 @@ void test_xml_translation(void) lv_xml_register_translation_from_data(translations_xml); - - static const char * languages[] = {"en", "de", "es", NULL}; - static const char * tags[] = {"tiger", "lion", "rabbit", "elephant", NULL}; - static const char * translations[] = { + /* Arrays are defined `const` to place them in program space instead of RAM. */ + static const char * const languages[] = {"en", "de", "es", NULL}; + static const char * const tags[] = {"tiger", "lion", "rabbit", "elephant", NULL}; + static const char * const translations[] = { "The Tiger", "Der Tiger", "El Tigre", "The Lion", "Der Löwe", "El León", "The Rabbit", "Das Kaninchen", "El Conejo",