From c3ebf055f6fe8c8923feb9eb87fde2e7bbf5e1b0 Mon Sep 17 00:00:00 2001 From: Maud Date: Sun, 8 Sep 2024 14:48:54 +0200 Subject: [PATCH 1/2] Fix translations into messages dialogs --- haxe/ui/backend/MessageBoxBase.hx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/haxe/ui/backend/MessageBoxBase.hx b/haxe/ui/backend/MessageBoxBase.hx index 7c9ba1b..771b08b 100644 --- a/haxe/ui/backend/MessageBoxBase.hx +++ b/haxe/ui/backend/MessageBoxBase.hx @@ -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; @@ -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); From de3133d0862e0900bd18aed6a80d26d952129b25 Mon Sep 17 00:00:00 2001 From: Maud Date: Sun, 8 Sep 2024 14:50:24 +0200 Subject: [PATCH 2/2] Fix translations in items dropdown --- .../hxwidgets/behaviours/ChoiceDataSource.hx | 41 ++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/haxe/ui/backend/hxwidgets/behaviours/ChoiceDataSource.hx b/haxe/ui/backend/hxwidgets/behaviours/ChoiceDataSource.hx index 09c700d..d606070 100644 --- a/haxe/ui/backend/hxwidgets/behaviours/ChoiceDataSource.hx +++ b/haxe/ui/backend/hxwidgets/behaviours/ChoiceDataSource.hx @@ -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; @@ -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(); @@ -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 = _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; @@ -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)); }