Skip to content

Commit

Permalink
Merge pull request #61 from Shallowmallow/FixLocale2
Browse files Browse the repository at this point in the history
Fix locale2
  • Loading branch information
ianharrigan authored Oct 3, 2024
2 parents 404d954 + de3133d commit b716a18
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
7 changes: 6 additions & 1 deletion haxe/ui/backend/MessageBoxBase.hx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package haxe.ui.backend;

import haxe.ui.util.ExpressionUtil;
import haxe.ui.locale.LocaleManager;
import haxe.ui.containers.dialogs.Dialog;
import haxe.ui.containers.dialogs.MessageBox.MessageBoxType;
import haxe.ui.core.Screen;
Expand All @@ -23,7 +25,10 @@ class MessageBoxBase extends Dialog {
case MessageBoxType.TYPE_ERROR:
style = MessageDialogStyle.ICON_ERROR;
}
var dialog:MessageDialog = new MessageDialog(Screen.instance.frame, _message, title, style);
var translatedMessage =LocaleManager.instance.stringToTranslation(_message);
var translatedTitle =LocaleManager.instance.stringToTranslation(_message);

var dialog:MessageDialog = new MessageDialog(Screen.instance.frame, translatedMessage, translatedTitle, style);
var retVal = dialog.showModal();
var event = new DialogEvent(DialogEvent.DIALOG_CLOSED);
event.button = DialogBase.standardIdToButton(retVal);
Expand Down
41 changes: 40 additions & 1 deletion haxe/ui/backend/hxwidgets/behaviours/ChoiceDataSource.hx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package haxe.ui.backend.hxwidgets.behaviours;

import haxe.ui.locale.LocaleEvent;
import haxe.ui.locale.LocaleManager;
import haxe.ui.events.UIEvent;
import haxe.ui.behaviours.DataBehaviour;
import haxe.ui.components.DropDown;
Expand All @@ -10,6 +12,13 @@ import hx.widgets.Choice;

@:access(haxe.ui.core.Component)
class ChoiceDataSource extends DataBehaviour {

public function new(component:haxe.ui.core.Component) {
super(component);
LocaleManager.instance.registerEvent(LocaleEvent.LOCALE_CHANGED, function (e) {
changeLang();
});
}
public override function get():Variant {
if (_value == null || _value.isNull) {
_value = new ArrayDataSource<Dynamic>();
Expand All @@ -28,6 +37,36 @@ class ChoiceDataSource extends DataBehaviour {
}
}

public function changeLang() {
if (_component.window == null) {
return;
}

var choice:Choice = cast(_component.window, Choice);
var oldSelection = choice.selection;
choice.clear();

if (_value.isNull) {
return;
}

var ds:DataSource<Dynamic> = _value;
for (n in 0...ds.size) {
var item = ds.get(n);
if (item.text != null) {
choice.append(LocaleManager.instance.stringToTranslation(item.text));
} else {
choice.append(Std.string(item));
}
}

var dropDown:DropDown = cast(_component, DropDown);
choice.selection = oldSelection;
if (dropDown.text != null) {
choice.selectedString = dropDown.text;
}
}

public override function validateData() {
if (_component.window == null) {
return;
Expand All @@ -44,7 +83,7 @@ class ChoiceDataSource extends DataBehaviour {
for (n in 0...ds.size) {
var item = ds.get(n);
if (item.text != null) {
choice.append(item.text);
choice.append(LocaleManager.instance.stringToTranslation(item.text));
} else {
choice.append(Std.string(item));
}
Expand Down

0 comments on commit b716a18

Please sign in to comment.