Skip to content

Commit b716a18

Browse files
authored
Merge pull request #61 from Shallowmallow/FixLocale2
Fix locale2
2 parents 404d954 + de3133d commit b716a18

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-2
lines changed

haxe/ui/backend/MessageBoxBase.hx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package haxe.ui.backend;
22

3+
import haxe.ui.util.ExpressionUtil;
4+
import haxe.ui.locale.LocaleManager;
35
import haxe.ui.containers.dialogs.Dialog;
46
import haxe.ui.containers.dialogs.MessageBox.MessageBoxType;
57
import haxe.ui.core.Screen;
@@ -23,7 +25,10 @@ class MessageBoxBase extends Dialog {
2325
case MessageBoxType.TYPE_ERROR:
2426
style = MessageDialogStyle.ICON_ERROR;
2527
}
26-
var dialog:MessageDialog = new MessageDialog(Screen.instance.frame, _message, title, style);
28+
var translatedMessage =LocaleManager.instance.stringToTranslation(_message);
29+
var translatedTitle =LocaleManager.instance.stringToTranslation(_message);
30+
31+
var dialog:MessageDialog = new MessageDialog(Screen.instance.frame, translatedMessage, translatedTitle, style);
2732
var retVal = dialog.showModal();
2833
var event = new DialogEvent(DialogEvent.DIALOG_CLOSED);
2934
event.button = DialogBase.standardIdToButton(retVal);

haxe/ui/backend/hxwidgets/behaviours/ChoiceDataSource.hx

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package haxe.ui.backend.hxwidgets.behaviours;
22

3+
import haxe.ui.locale.LocaleEvent;
4+
import haxe.ui.locale.LocaleManager;
35
import haxe.ui.events.UIEvent;
46
import haxe.ui.behaviours.DataBehaviour;
57
import haxe.ui.components.DropDown;
@@ -10,6 +12,13 @@ import hx.widgets.Choice;
1012

1113
@:access(haxe.ui.core.Component)
1214
class ChoiceDataSource extends DataBehaviour {
15+
16+
public function new(component:haxe.ui.core.Component) {
17+
super(component);
18+
LocaleManager.instance.registerEvent(LocaleEvent.LOCALE_CHANGED, function (e) {
19+
changeLang();
20+
});
21+
}
1322
public override function get():Variant {
1423
if (_value == null || _value.isNull) {
1524
_value = new ArrayDataSource<Dynamic>();
@@ -28,6 +37,36 @@ class ChoiceDataSource extends DataBehaviour {
2837
}
2938
}
3039

40+
public function changeLang() {
41+
if (_component.window == null) {
42+
return;
43+
}
44+
45+
var choice:Choice = cast(_component.window, Choice);
46+
var oldSelection = choice.selection;
47+
choice.clear();
48+
49+
if (_value.isNull) {
50+
return;
51+
}
52+
53+
var ds:DataSource<Dynamic> = _value;
54+
for (n in 0...ds.size) {
55+
var item = ds.get(n);
56+
if (item.text != null) {
57+
choice.append(LocaleManager.instance.stringToTranslation(item.text));
58+
} else {
59+
choice.append(Std.string(item));
60+
}
61+
}
62+
63+
var dropDown:DropDown = cast(_component, DropDown);
64+
choice.selection = oldSelection;
65+
if (dropDown.text != null) {
66+
choice.selectedString = dropDown.text;
67+
}
68+
}
69+
3170
public override function validateData() {
3271
if (_component.window == null) {
3372
return;
@@ -44,7 +83,7 @@ class ChoiceDataSource extends DataBehaviour {
4483
for (n in 0...ds.size) {
4584
var item = ds.get(n);
4685
if (item.text != null) {
47-
choice.append(item.text);
86+
choice.append(LocaleManager.instance.stringToTranslation(item.text));
4887
} else {
4988
choice.append(Std.string(item));
5089
}

0 commit comments

Comments
 (0)