awtk/demos/demo_tr_app.c

115 lines
3.0 KiB
C
Raw Normal View History

2018-05-04 14:52:15 +08:00
/**
* File: demo_tr_app.c
2018-05-15 09:31:58 +08:00
* Author: AWTK Develop Team
2018-05-04 14:52:15 +08:00
* Brief: text translation
*
2020-01-01 11:27:36 +08:00
* Copyright (c) 2018 - 2020 Guangzhou ZHIYUAN Electronics Co.,Ltd.
2018-05-04 14:52:15 +08:00
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* License file for more details.
*
*/
/**
* History:
* ================================================================
* 2018-05-03 Li XianJing <xianjimli@hotmail.com> created
*
*/
#include "base/timer.h"
#include "base/enums.h"
#include "widgets/button.h"
2018-08-24 07:45:37 +08:00
#include "base/locale_info.h"
#include "widgets/check_button.h"
#include "base/dialog.h"
#include "widgets/image.h"
2018-05-04 14:52:15 +08:00
#include "base/image_manager.h"
#include "widgets/label.h"
#include "tkc/mem.h"
#include "widgets/progress_bar.h"
#include "tkc/utils.h"
#include "tkc/utf8.h"
#include "base/window.h"
#include "widgets/slider.h"
#include "widgets/group_box.h"
2018-05-04 14:52:15 +08:00
2018-05-05 19:08:32 +08:00
static ret_t change_locale(void* ctx, event_t* e) {
2022-03-24 18:28:04 +08:00
widget_t* radio_button = WIDGET(e->target);
if (widget_get_value_int(radio_button)) {
char country[3];
char language[3];
const char* str = (const char*)ctx;
2018-05-04 14:52:15 +08:00
2022-03-24 18:28:04 +08:00
widget_t* widget = WIDGET(e->target);
if (widget_get_value(widget)) {
strncpy(language, str, 2);
strncpy(country, str + 3, 2);
locale_info_change(locale_info(), language, country);
}
2018-05-04 14:52:15 +08:00
}
return RET_OK;
}
2018-11-28 09:09:59 +08:00
static ret_t set_locale_value(widget_t* widget, int32_t value) {
char str[64];
const char* format = locale_info_tr(locale_info(), "value is %d");
tk_snprintf(str, sizeof(str), format, value);
widget_set_text_utf8(widget, str);
return RET_OK;
}
2018-05-05 19:08:32 +08:00
static ret_t on_locale_changed(void* ctx, event_t* e) {
(void)ctx;
(void)e;
2018-11-28 09:09:59 +08:00
widget_t* win = WIDGET(ctx);
widget_t* value = widget_lookup(win, "value", TRUE);
set_locale_value(value, 100);
2018-08-24 07:45:37 +08:00
log_debug("locale_infod change: %s_%s\n", locale_info()->language, locale_info()->country);
2018-05-05 19:08:32 +08:00
return RET_OK;
}
2018-05-04 14:52:15 +08:00
ret_t application_init() {
widget_t* ok = NULL;
widget_t* cancel = NULL;
2018-11-28 09:09:59 +08:00
widget_t* value = NULL;
2018-05-04 14:52:15 +08:00
widget_t* radio_button = NULL;
widget_t* win = window_create(NULL, 0, 0, 0, 0);
2018-05-05 19:08:32 +08:00
widget_on(win, EVT_LOCALE_CHANGED, on_locale_changed, win);
2018-05-04 14:52:15 +08:00
ok = button_create(win, 10, 5, 80, 30);
widget_set_tr_text(ok, "ok");
cancel = button_create(win, 100, 5, 80, 30);
widget_set_tr_text(cancel, "cancel");
2018-11-28 09:09:59 +08:00
value = label_create(win, 200, 5, 80, 30);
widget_set_name(value, "value");
set_locale_value(value, 100);
2018-05-04 14:52:15 +08:00
radio_button = check_button_create_radio(win, 10, 200, 80, 30);
widget_set_tr_text(radio_button, "English");
2019-07-04 11:26:55 +08:00
widget_on(radio_button, EVT_VALUE_CHANGED, change_locale, (void*)"en_US");
2018-05-04 14:52:15 +08:00
widget_set_value(radio_button, 1);
radio_button = check_button_create_radio(win, 100, 200, 80, 30);
widget_set_tr_text(radio_button, "Chinese");
2019-07-04 11:26:55 +08:00
widget_on(radio_button, EVT_VALUE_CHANGED, change_locale, (void*)"zh_CN");
2018-05-04 14:52:15 +08:00
return RET_OK;
}
2020-03-19 11:11:32 +08:00
ret_t application_exit() {
log_debug("application_exit\n");
return RET_OK;
}
#include "awtk_main.inc"