@@ -151,6 +151,9 @@ void runSemanticsTests() {
151151 group ('landmarks' , () {
152152 _testLandmarks ();
153153 });
154+ group ('locale' , () {
155+ _testLocale ();
156+ });
154157}
155158
156159void _testSemanticRole () {
@@ -5415,6 +5418,97 @@ void _testLandmarks() {
54155418 semantics ().semanticsEnabled = false ;
54165419}
54175420
5421+ void _testLocale () {
5422+ test ('nodes with locale update correctly' , () {
5423+ semantics ()
5424+ ..debugOverrideTimestampFunction (() => _testTime)
5425+ ..semanticsEnabled = true ;
5426+
5427+ SemanticsObject pumpSemantics () {
5428+ final SemanticsTester tester = SemanticsTester (owner ());
5429+ tester.updateNode (
5430+ id: 0 ,
5431+ locale: const ui.Locale ('es-MX' ),
5432+ rect: const ui.Rect .fromLTRB (0 , 0 , 100 , 50 ),
5433+ );
5434+ tester.apply ();
5435+ return tester.getSemanticsObject (0 );
5436+ }
5437+
5438+ final SemanticsObject object = pumpSemantics ();
5439+ expect (object.element.getAttribute ('lang' ), 'es-MX' );
5440+ });
5441+
5442+ test ('nodes with same locale as parent does not set lang' , () {
5443+ semantics ()
5444+ ..debugOverrideTimestampFunction (() => _testTime)
5445+ ..semanticsEnabled = true ;
5446+
5447+ final SemanticsTester tester = SemanticsTester (owner ());
5448+ SemanticsObject pumpSemantics () {
5449+ tester.updateNode (
5450+ id: 0 ,
5451+ locale: const ui.Locale ('es-MX' ),
5452+ rect: const ui.Rect .fromLTRB (0 , 0 , 100 , 50 ),
5453+ children: < SemanticsNodeUpdate > [
5454+ tester.updateNode (
5455+ id: 1 ,
5456+ locale: const ui.Locale ('es-MX' ),
5457+ rect: const ui.Rect .fromLTRB (0 , 0 , 100 , 50 ),
5458+ ),
5459+ ],
5460+ );
5461+ tester.apply ();
5462+ return tester.getSemanticsObject (0 );
5463+ }
5464+
5465+ final SemanticsObject object = pumpSemantics ();
5466+ expect (object.element.getAttribute ('lang' ), 'es-MX' );
5467+ final SemanticsObject node1 = tester.getSemanticsObject (1 );
5468+ expect (node1.element.getAttribute ('lang' ), null );
5469+ });
5470+
5471+ test ('nodes changing locale set lang correctly' , () {
5472+ semantics ()
5473+ ..debugOverrideTimestampFunction (() => _testTime)
5474+ ..semanticsEnabled = true ;
5475+
5476+ final SemanticsTester tester = SemanticsTester (owner ());
5477+ SemanticsObject pumpSemantics () {
5478+ tester.updateNode (
5479+ id: 0 ,
5480+ locale: const ui.Locale ('es-MX' ),
5481+ rect: const ui.Rect .fromLTRB (0 , 0 , 100 , 50 ),
5482+ children: < SemanticsNodeUpdate > [
5483+ tester.updateNode (
5484+ id: 1 ,
5485+ locale: const ui.Locale ('es-MX' ),
5486+ rect: const ui.Rect .fromLTRB (0 , 0 , 100 , 50 ),
5487+ children: < SemanticsNodeUpdate > [
5488+ tester.updateNode (
5489+ id: 2 ,
5490+ locale: const ui.Locale ('en-US' ),
5491+ rect: const ui.Rect .fromLTRB (0 , 0 , 100 , 50 ),
5492+ ),
5493+ ],
5494+ ),
5495+ ],
5496+ );
5497+ tester.apply ();
5498+ return tester.getSemanticsObject (0 );
5499+ }
5500+
5501+ final SemanticsObject object = pumpSemantics ();
5502+ expect (object.element.getAttribute ('lang' ), 'es-MX' );
5503+ final SemanticsObject node1 = tester.getSemanticsObject (1 );
5504+ expect (node1.element.getAttribute ('lang' ), null );
5505+ final SemanticsObject node2 = tester.getSemanticsObject (2 );
5506+ expect (node2.element.getAttribute ('lang' ), 'en-US' );
5507+ });
5508+
5509+ semantics ().semanticsEnabled = false ;
5510+ }
5511+
54185512/// A facade in front of [ui.SemanticsUpdateBuilder.updateNode] that
54195513/// supplies default values for semantics attributes.
54205514void updateNode (
@@ -5455,6 +5549,7 @@ void updateNode(
54555549 List <String >? controlsNodes,
54565550 ui.SemanticsRole role = ui.SemanticsRole .none,
54575551 ui.SemanticsInputType inputType = ui.SemanticsInputType .none,
5552+ ui.Locale ? locale,
54585553}) {
54595554 transform ?? = Float64List .fromList (Matrix4 .identity ().storage);
54605555 childrenInTraversalOrder ?? = Int32List (0 );
@@ -5497,6 +5592,7 @@ void updateNode(
54975592 linkUrl: linkUrl,
54985593 controlsNodes: controlsNodes,
54995594 inputType: inputType,
5595+ locale: locale,
55005596 );
55015597}
55025598
0 commit comments