11package haxe .ui .backend .hxwidgets .behaviours ;
22
3+ import haxe .ui .locale .LocaleEvent ;
4+ import haxe .ui .locale .LocaleManager ;
35import haxe .ui .events .UIEvent ;
46import haxe .ui .behaviours .DataBehaviour ;
57import haxe .ui .components .DropDown ;
@@ -10,6 +12,13 @@ import hx.widgets.Choice;
1012
1113@:access (haxe.ui.core. Component )
1214class 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