mirror of https://github.com/buggins/dlangui.git
Internationalization demo in example1 - Menu/View/Interface Language
This commit is contained in:
parent
908fbd396e
commit
b69d55f3eb
|
@ -1,4 +1,4 @@
|
||||||
EXIT=Exit
|
EXIT=Exit
|
||||||
MENU_FILE=&File
|
MENU_FILE=&File
|
||||||
MENU_FILE_OPEN=&Open
|
MENU_FILE_OPEN=&Open
|
||||||
MENU_FILE_OPEN_RECENT=Open recent
|
MENU_FILE_OPEN_RECENT=Open recent
|
||||||
|
@ -14,7 +14,7 @@ MENU_EDIT_PREFERENCES=&Preferences
|
||||||
MENU_VIEW=&View
|
MENU_VIEW=&View
|
||||||
MENU_VIEW_LANGUAGE=Interface &Language
|
MENU_VIEW_LANGUAGE=Interface &Language
|
||||||
MENU_VIEW_LANGUAGE_EN=English
|
MENU_VIEW_LANGUAGE_EN=English
|
||||||
MENU_VIEW_LANGUAGE_RU=Russian
|
MENU_VIEW_LANGUAGE_RU=Русский
|
||||||
MENU_VIEW_THEME=&Theme
|
MENU_VIEW_THEME=&Theme
|
||||||
MENU_VIEW_THEME_DEFAULT=&Default
|
MENU_VIEW_THEME_DEFAULT=&Default
|
||||||
MENU_VIEW_THEME_CUSTOM1=&Custom 1
|
MENU_VIEW_THEME_CUSTOM1=&Custom 1
|
||||||
|
@ -24,3 +24,9 @@ MENU_HELP=&Help
|
||||||
MENU_HELP_VIEW_HELP=&View help
|
MENU_HELP_VIEW_HELP=&View help
|
||||||
MENU_HELP_ABOUT=&About
|
MENU_HELP_ABOUT=&About
|
||||||
|
|
||||||
|
TAB_LONG_LIST=Long list
|
||||||
|
TAB_BUTTONS=Buttons
|
||||||
|
TAB_ANIMATION=Animation
|
||||||
|
TAB_TABLE_LAYOUT=Table layout
|
||||||
|
TAB_EDITORS=Editors
|
||||||
|
|
||||||
|
|
|
@ -1 +1,33 @@
|
||||||
EXIT=Выход
|
EXIT=Выход
|
||||||
|
MENU_FILE=&Файл
|
||||||
|
MENU_FILE_OPEN=&Открыть
|
||||||
|
MENU_FILE_OPEN_RECENT=Открыть из последних
|
||||||
|
MENU_FILE_SAVE=&Сохранить
|
||||||
|
MENU_FILE_EXIT=Вы&ход
|
||||||
|
MENU_EDIT=&Правка
|
||||||
|
MENU_EDIT_COPY=&Копировать
|
||||||
|
MENU_EDIT_PASTE=&Вставить
|
||||||
|
MENU_EDIT_CUT=Вырезать
|
||||||
|
MENU_EDIT_UNDO=&Отмена
|
||||||
|
MENU_EDIT_REDO=&Повторить
|
||||||
|
MENU_EDIT_PREFERENCES=&Настройки
|
||||||
|
MENU_VIEW=&Вид
|
||||||
|
MENU_VIEW_LANGUAGE=&Язык интерфейса
|
||||||
|
MENU_VIEW_LANGUAGE_EN=English
|
||||||
|
MENU_VIEW_LANGUAGE_RU=Русский
|
||||||
|
MENU_VIEW_THEME=&Тема
|
||||||
|
MENU_VIEW_THEME_DEFAULT=Стандартная
|
||||||
|
MENU_VIEW_THEME_CUSTOM1=Пример 1
|
||||||
|
MENU_WINDOW=&Окно
|
||||||
|
MENU_WINDOW_PREFERENCES=&Настройки
|
||||||
|
MENU_HELP=&Справка
|
||||||
|
MENU_HELP_VIEW_HELP=&Просмотр справки
|
||||||
|
MENU_HELP_ABOUT=&О программе
|
||||||
|
|
||||||
|
TAB_LONG_LIST=Длинный список
|
||||||
|
TAB_BUTTONS=Кнопки
|
||||||
|
TAB_ANIMATION=Анимация
|
||||||
|
TAB_TABLE_LAYOUT=Табличный layout
|
||||||
|
TAB_EDITORS=Редакторы
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -131,17 +131,35 @@ extern (C) int UIAppMain(string[] args) {
|
||||||
|
|
||||||
MenuItem viewItem = new MenuItem(new Action(60, "MENU_VIEW"));
|
MenuItem viewItem = new MenuItem(new Action(60, "MENU_VIEW"));
|
||||||
MenuItem langItem = new MenuItem(new Action(61, "MENU_VIEW_LANGUAGE"));
|
MenuItem langItem = new MenuItem(new Action(61, "MENU_VIEW_LANGUAGE"));
|
||||||
langItem.add((new MenuItem(new Action(611, "MENU_VIEW_LANGUAGE_EN"))).type(MenuItemType.Radio).checked(true));
|
auto onLangChange = delegate (MenuItem item) {
|
||||||
langItem.add((new MenuItem(new Action(612, "MENU_VIEW_LANGUAGE_RU"))).type(MenuItemType.Radio));
|
if (!item.checked)
|
||||||
|
return false;
|
||||||
|
if (item.id == 611) {
|
||||||
|
// set interface language to english
|
||||||
|
i18n.load("en.ini");
|
||||||
|
contentLayout.requestLayout();
|
||||||
|
} else if (item.id == 612) {
|
||||||
|
// set interface language to russian
|
||||||
|
i18n.load("ru.ini", "en.ini");
|
||||||
|
contentLayout.requestLayout();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
MenuItem enLang = (new MenuItem(new Action(611, "MENU_VIEW_LANGUAGE_EN"))).type(MenuItemType.Radio).checked(true);
|
||||||
|
MenuItem ruLang = (new MenuItem(new Action(612, "MENU_VIEW_LANGUAGE_RU"))).type(MenuItemType.Radio);
|
||||||
|
enLang.onMenuItemClick = onLangChange;
|
||||||
|
ruLang.onMenuItemClick = onLangChange;
|
||||||
|
langItem.add(enLang);
|
||||||
|
langItem.add(ruLang);
|
||||||
MenuItem themeItem = new MenuItem(new Action(62, "MENU_VIEW_THEME"));
|
MenuItem themeItem = new MenuItem(new Action(62, "MENU_VIEW_THEME"));
|
||||||
themeItem.add((new MenuItem(new Action(621, "MENU_VIEW_THEME_DEFAULT"))).type(MenuItemType.Radio).checked(true));
|
themeItem.add((new MenuItem(new Action(621, "MENU_VIEW_THEME_DEFAULT"))).type(MenuItemType.Radio).checked(true));
|
||||||
themeItem.add((new MenuItem(new Action(622, "MENU_VIEW_THEME_CUSTOM1"))).type(MenuItemType.Radio));
|
themeItem.add((new MenuItem(new Action(622, "MENU_VIEW_THEME_CUSTOM1"))).type(MenuItemType.Radio));
|
||||||
viewItem.add(langItem);
|
viewItem.add(langItem);
|
||||||
viewItem.add(themeItem);
|
viewItem.add(themeItem);
|
||||||
|
|
||||||
MenuItem windowItem = new MenuItem(new Action(3, "MENU_WINDOW"));
|
MenuItem windowItem = new MenuItem(new Action(3, "MENU_WINDOW"c));
|
||||||
windowItem.add(new Action(30, "MENU_WINDOW_PREFERENCES"));
|
windowItem.add(new Action(30, "MENU_WINDOW_PREFERENCES"));
|
||||||
MenuItem helpItem = new MenuItem(new Action(4, "MENU_HELP"));
|
MenuItem helpItem = new MenuItem(new Action(4, "MENU_HELP"c));
|
||||||
helpItem.add(new Action(40, "MENU_HELP_VIEW_HELP"));
|
helpItem.add(new Action(40, "MENU_HELP_VIEW_HELP"));
|
||||||
helpItem.add(new Action(41, "MENU_HELP_ABOUT"));
|
helpItem.add(new Action(41, "MENU_HELP_ABOUT"));
|
||||||
mainMenuItems.add(fileItem);
|
mainMenuItems.add(fileItem);
|
||||||
|
@ -239,7 +257,7 @@ extern (C) int UIAppMain(string[] args) {
|
||||||
assert(list.itemEnabled(6) == true);
|
assert(list.itemEnabled(6) == true);
|
||||||
list.layoutWidth(FILL_PARENT).layoutHeight(FILL_PARENT);
|
list.layoutWidth(FILL_PARENT).layoutHeight(FILL_PARENT);
|
||||||
list.selectItem(0);
|
list.selectItem(0);
|
||||||
tabs.addTab(list, "Long List"d);
|
tabs.addTab(list, "TAB_LONG_LIST"c);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -329,7 +347,7 @@ extern (C) int UIAppMain(string[] args) {
|
||||||
|
|
||||||
layout3.addChild(new VSpacer());
|
layout3.addChild(new VSpacer());
|
||||||
layout3.layoutWidth(FILL_PARENT).layoutHeight(FILL_PARENT);
|
layout3.layoutWidth(FILL_PARENT).layoutHeight(FILL_PARENT);
|
||||||
tabs.addTab(layout3, "Buttons"d);
|
tabs.addTab(layout3, "TAB_BUTTONS"c);
|
||||||
}
|
}
|
||||||
|
|
||||||
TableLayout table = new TableLayout("TABLE");
|
TableLayout table = new TableLayout("TABLE");
|
||||||
|
@ -347,11 +365,11 @@ extern (C) int UIAppMain(string[] args) {
|
||||||
table.addChild((new TextWidget(null, "Param 3"d)).alignment(Align.Right | Align.VCenter));
|
table.addChild((new TextWidget(null, "Param 3"d)).alignment(Align.Right | Align.VCenter));
|
||||||
table.addChild((new EditLine("edit3", "Parameter 3 value"d)).layoutWidth(FILL_PARENT));
|
table.addChild((new EditLine("edit3", "Parameter 3 value"d)).layoutWidth(FILL_PARENT));
|
||||||
table.margins(Rect(10,10,10,10)).layoutWidth(FILL_PARENT);
|
table.margins(Rect(10,10,10,10)).layoutWidth(FILL_PARENT);
|
||||||
tabs.addTab(table, "Table Layout"d);
|
tabs.addTab(table, "TAB_TABLE_LAYOUT"c);
|
||||||
|
|
||||||
tabs.addTab((new TextWidget()).id("tab5").textColor(0x00802000).text("Tab 5 contents"), "Tab 5"d);
|
tabs.addTab((new TextWidget()).id("tab5").textColor(0x00802000).text("Tab 5 contents"), "Tab 5"d);
|
||||||
|
|
||||||
tabs.addTab((new SampleAnimationWidget("tab6")).layoutWidth(FILL_PARENT).layoutHeight(FILL_PARENT), "Animation"d);
|
tabs.addTab((new SampleAnimationWidget("tab6")).layoutWidth(FILL_PARENT).layoutHeight(FILL_PARENT), "TAB_ANIMATION"c);
|
||||||
|
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
// create Editors test tab
|
// create Editors test tab
|
||||||
|
@ -390,7 +408,7 @@ extern (C) int UIAppMain(string[] args) {
|
||||||
editors.addChild(editBox2);
|
editors.addChild(editBox2);
|
||||||
editors.layoutHeight(FILL_PARENT).layoutWidth(FILL_PARENT);
|
editors.layoutHeight(FILL_PARENT).layoutWidth(FILL_PARENT);
|
||||||
|
|
||||||
tabs.addTab(editors, "Editors"d);
|
tabs.addTab(editors, "TAB_EDITORS"c);
|
||||||
|
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
||||||
|
|
|
@ -74,7 +74,7 @@ class TextWidget : Widget {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
/// set text to show
|
/// set text to show
|
||||||
override @property Widget text(ref UIString s) {
|
override @property Widget text(UIString s) {
|
||||||
_text = s;
|
_text = s;
|
||||||
requestLayout();
|
requestLayout();
|
||||||
return this;
|
return this;
|
||||||
|
@ -199,7 +199,7 @@ class ImageTextButton : HorizontalLayout {
|
||||||
protected TextWidget _label;
|
protected TextWidget _label;
|
||||||
override @property dstring text() { return _label.text; }
|
override @property dstring text() { return _label.text; }
|
||||||
override @property Widget text(dstring s) { _label.text = s; requestLayout(); return this; }
|
override @property Widget text(dstring s) { _label.text = s; requestLayout(); return this; }
|
||||||
override @property Widget text(ref UIString s) { _label.text = s; requestLayout(); return this; }
|
override @property Widget text(UIString s) { _label.text = s; requestLayout(); return this; }
|
||||||
this(string ID = null, string drawableId = null, string textResourceId = null) {
|
this(string ID = null, string drawableId = null, string textResourceId = null) {
|
||||||
super(ID);
|
super(ID);
|
||||||
styleId = "BUTTON";
|
styleId = "BUTTON";
|
||||||
|
@ -292,7 +292,7 @@ class Button : Widget {
|
||||||
protected UIString _text;
|
protected UIString _text;
|
||||||
override @property dstring text() { return _text; }
|
override @property dstring text() { return _text; }
|
||||||
override @property Widget text(dstring s) { _text = s; requestLayout(); return this; }
|
override @property Widget text(dstring s) { _text = s; requestLayout(); return this; }
|
||||||
override @property Widget text(ref UIString s) { _text = s; requestLayout(); return this; }
|
override @property Widget text(UIString s) { _text = s; requestLayout(); return this; }
|
||||||
@property Widget textResource(string s) { _text = s; requestLayout(); return this; }
|
@property Widget textResource(string s) { _text = s; requestLayout(); return this; }
|
||||||
this(string ID = null) {
|
this(string ID = null) {
|
||||||
super(ID);
|
super(ID);
|
||||||
|
|
|
@ -1101,7 +1101,7 @@ class EditWidgetBase : WidgetGroup, EditableContentListener, MenuItemActionHandl
|
||||||
}
|
}
|
||||||
|
|
||||||
/// set text
|
/// set text
|
||||||
override @property Widget text(ref UIString s) {
|
override @property Widget text(UIString s) {
|
||||||
_content.text = s;
|
_content.text = s;
|
||||||
requestLayout();
|
requestLayout();
|
||||||
return this;
|
return this;
|
||||||
|
|
|
@ -42,6 +42,17 @@ enum MenuItemType {
|
||||||
Submenu
|
Submenu
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// interface to handle menu item click
|
||||||
|
interface MenuItemClickHandler {
|
||||||
|
bool onMenuItemClick(MenuItem item);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// interface to handle menu item action
|
||||||
|
interface MenuItemActionHandler {
|
||||||
|
bool onMenuItemAction(const Action action);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// menu item properties
|
/// menu item properties
|
||||||
class MenuItem {
|
class MenuItem {
|
||||||
protected bool _checked;
|
protected bool _checked;
|
||||||
|
@ -50,6 +61,10 @@ class MenuItem {
|
||||||
protected Action _action;
|
protected Action _action;
|
||||||
protected MenuItem[] _subitems;
|
protected MenuItem[] _subitems;
|
||||||
protected MenuItem _parent;
|
protected MenuItem _parent;
|
||||||
|
/// handle menu item click (parameter is MenuItem)
|
||||||
|
Signal!MenuItemClickHandler onMenuItemClick;
|
||||||
|
/// handle menu item click action (parameter is Action)
|
||||||
|
Signal!MenuItemActionHandler onMenuItemAction;
|
||||||
/// item action id, 0 if no action
|
/// item action id, 0 if no action
|
||||||
@property int id() { return _action is null ? 0 : _action.id; }
|
@property int id() { return _action is null ? 0 : _action.id; }
|
||||||
/// returns count of submenu items
|
/// returns count of submenu items
|
||||||
|
@ -345,14 +360,6 @@ class MenuItemWidget : WidgetGroup {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
interface MenuItemClickHandler {
|
|
||||||
bool onMenuItemClick(MenuItem item);
|
|
||||||
}
|
|
||||||
|
|
||||||
interface MenuItemActionHandler {
|
|
||||||
bool onMenuItemAction(const Action action);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// base class for menus
|
/// base class for menus
|
||||||
class MenuWidgetBase : ListWidget {
|
class MenuWidgetBase : ListWidget {
|
||||||
protected MenuWidgetBase _parentMenu;
|
protected MenuWidgetBase _parentMenu;
|
||||||
|
@ -496,6 +503,10 @@ class MenuWidgetBase : ListWidget {
|
||||||
} else if (item.type == MenuItemType.Radio) {
|
} else if (item.type == MenuItemType.Radio) {
|
||||||
item.checked = true;
|
item.checked = true;
|
||||||
}
|
}
|
||||||
|
if (item.onMenuItemClick.assigned)
|
||||||
|
item.onMenuItemClick(item);
|
||||||
|
if (item.onMenuItemAction.assigned && item.action)
|
||||||
|
item.onMenuItemAction(item.action);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void onMenuItem(MenuItem item) {
|
protected void onMenuItem(MenuItem item) {
|
||||||
|
|
|
@ -440,7 +440,7 @@ class Widget {
|
||||||
/// sets widget content text (override to support this)
|
/// sets widget content text (override to support this)
|
||||||
@property Widget text(dstring s) { return this; }
|
@property Widget text(dstring s) { return this; }
|
||||||
/// sets widget content text (override to support this)
|
/// sets widget content text (override to support this)
|
||||||
@property Widget text(ref UIString s) { return this; }
|
@property Widget text(UIString s) { return this; }
|
||||||
|
|
||||||
//==================================================================
|
//==================================================================
|
||||||
// Layout and drawing related methods
|
// Layout and drawing related methods
|
||||||
|
|
Loading…
Reference in New Issue