Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix locale2 #61

Merged
merged 2 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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