Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 9d0ae1c

Browse files
authored
Remove currentLocale prepend on iOS (#18379)
1 parent 942f6e3 commit 9d0ae1c

File tree

6 files changed

+112
-16
lines changed

6 files changed

+112
-16
lines changed

shell/platform/darwin/ios/framework/Source/FlutterEngine.mm

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -762,22 +762,6 @@ - (void)onLocaleUpdated:(NSNotification*)notification {
762762
NSArray<NSString*>* preferredLocales = [NSLocale preferredLanguages];
763763
NSMutableArray<NSString*>* data = [[NSMutableArray new] autorelease];
764764

765-
// Force prepend the [NSLocale currentLocale] to the front of the list
766-
// to ensure we are including the full default locale. preferredLocales
767-
// is not guaranteed to include anything beyond the languageCode.
768-
NSLocale* currentLocale = [NSLocale currentLocale];
769-
NSString* languageCode = [currentLocale objectForKey:NSLocaleLanguageCode];
770-
NSString* countryCode = [currentLocale objectForKey:NSLocaleCountryCode];
771-
NSString* scriptCode = [currentLocale objectForKey:NSLocaleScriptCode];
772-
NSString* variantCode = [currentLocale objectForKey:NSLocaleVariantCode];
773-
if (languageCode) {
774-
[data addObject:languageCode];
775-
[data addObject:(countryCode ? countryCode : @"")];
776-
[data addObject:(scriptCode ? scriptCode : @"")];
777-
[data addObject:(variantCode ? variantCode : @"")];
778-
}
779-
780-
// Add any secondary locales/languages to the list.
781765
for (NSString* localeID in preferredLocales) {
782766
NSLocale* currentLocale = [[[NSLocale alloc] initWithLocaleIdentifier:localeID] autorelease];
783767
NSString* languageCode = [currentLocale objectForKey:NSLocaleLanguageCode];

testing/scenario_app/ios/Scenarios/Scenarios.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
3DEF491823C3BE6500184216 /* golden_platform_view_opacity_iPhone 8_simulator.png in Resources */ = {isa = PBXBuildFile; fileRef = 3DE09E8F23C010BD006C9851 /* golden_platform_view_opacity_iPhone 8_simulator.png */; };
4343
3DEF491923C3BE6500184216 /* golden_platform_view_rotate_iPhone 8_simulator.png in Resources */ = {isa = PBXBuildFile; fileRef = 3DE09E8E23C010BD006C9851 /* golden_platform_view_rotate_iPhone 8_simulator.png */; };
4444
3DEF491A23C3BE6500184216 /* golden_platform_view_transform_iPhone 8_simulator.png in Resources */ = {isa = PBXBuildFile; fileRef = 3DE09E9123C010BD006C9851 /* golden_platform_view_transform_iPhone 8_simulator.png */; };
45+
4F06F1B32473296E000AF246 /* LocalizationInitializationTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 4F06F1B124731F66000AF246 /* LocalizationInitializationTest.m */; };
4546
59A97FD8236A49D300B4C066 /* golden_platform_view_multiple_iPhone SE_simulator.png in Resources */ = {isa = PBXBuildFile; fileRef = 59A97FD7236A49D300B4C066 /* golden_platform_view_multiple_iPhone SE_simulator.png */; };
4647
59A97FDA236B984300B4C066 /* golden_platform_view_multiple_background_foreground_iPhone SE_simulator.png in Resources */ = {isa = PBXBuildFile; fileRef = 59A97FD9236B984300B4C066 /* golden_platform_view_multiple_background_foreground_iPhone SE_simulator.png */; };
4748
6402EBD124147BDA00987DCB /* UnobstructedPlatformViewTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 6402EBD024147BDA00987DCB /* UnobstructedPlatformViewTests.m */; };
@@ -151,6 +152,7 @@
151152
3DE09E9023C010BD006C9851 /* golden_platform_view_iPhone 8_simulator.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "golden_platform_view_iPhone 8_simulator.png"; sourceTree = "<group>"; };
152153
3DE09E9123C010BD006C9851 /* golden_platform_view_transform_iPhone 8_simulator.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "golden_platform_view_transform_iPhone 8_simulator.png"; sourceTree = "<group>"; };
153154
3DE09E9223C010BD006C9851 /* golden_platform_view_cliprect_iPhone 8_simulator.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "golden_platform_view_cliprect_iPhone 8_simulator.png"; sourceTree = "<group>"; };
155+
4F06F1B124731F66000AF246 /* LocalizationInitializationTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LocalizationInitializationTest.m; sourceTree = "<group>"; };
154156
59A97FD7236A49D300B4C066 /* golden_platform_view_multiple_iPhone SE_simulator.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "golden_platform_view_multiple_iPhone SE_simulator.png"; sourceTree = "<group>"; };
155157
59A97FD9236B984300B4C066 /* golden_platform_view_multiple_background_foreground_iPhone SE_simulator.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "golden_platform_view_multiple_background_foreground_iPhone SE_simulator.png"; sourceTree = "<group>"; };
156158
6402EBD024147BDA00987DCB /* UnobstructedPlatformViewTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = UnobstructedPlatformViewTests.m; sourceTree = "<group>"; };
@@ -250,6 +252,7 @@
250252
248D76ED22E388380012F0C1 /* ScenariosUITests */ = {
251253
isa = PBXGroup;
252254
children = (
255+
4F06F1B124731F66000AF246 /* LocalizationInitializationTest.m */,
253256
6402EBD024147BDA00987DCB /* UnobstructedPlatformViewTests.m */,
254257
0D14A3FD239743190013D873 /* golden_platform_view_rotate_iPhone SE_simulator.png */,
255258
3DE09E8B23C010BC006C9851 /* golden_platform_view_clippath_iPhone 8_simulator.png */,
@@ -503,6 +506,7 @@
503506
6816DBA42318358200A51400 /* PlatformViewGoldenTestManager.m in Sources */,
504507
248D76EF22E388380012F0C1 /* PlatformViewUITests.m in Sources */,
505508
0D8470A4240F0B1F0030B565 /* StatusBarTest.m in Sources */,
509+
4F06F1B32473296E000AF246 /* LocalizationInitializationTest.m in Sources */,
506510
0A42BFB42447E179007E212E /* TextSemanticsFocusTest.m in Sources */,
507511
);
508512
runOnlyForDeploymentPostprocessing = 0;

testing/scenario_app/ios/Scenarios/Scenarios/AppDelegate.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ - (BOOL)application:(UIApplication*)application
2626

2727
NSDictionary<NSString*, NSString*>* launchArgsMap = @{
2828
// The Platform view golden test args should match `PlatformViewGoldenTestManager`.
29+
@"--locale-initialization" : @"locale_initialization",
2930
@"--platform-view" : @"platform_view",
3031
@"--platform-view-no-overlay-intersection" : @"platform_view_no_overlay_intersection",
3132
@"--platform-view-two-intersecting-overlays" : @"platform_view_two_intersecting_overlays",
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#import <Flutter/Flutter.h>
6+
#import <XCTest/XCTest.h>
7+
8+
FLUTTER_ASSERT_ARC
9+
10+
@interface LocalizationInitializationTest : XCTestCase
11+
@property(nonatomic, strong) XCUIApplication* application;
12+
@end
13+
14+
@implementation LocalizationInitializationTest
15+
16+
- (void)setUp {
17+
[super setUp];
18+
self.continueAfterFailure = NO;
19+
20+
self.application = [[XCUIApplication alloc] init];
21+
self.application.launchArguments = @[ @"--locale-initialization" ];
22+
[self.application launch];
23+
}
24+
25+
- (void)testNoLocalePrepend {
26+
NSTimeInterval timeout = 10.0;
27+
28+
XCUIElement* textInputSemanticsObject =
29+
[self.application.textFields matchingIdentifier:@"[en]"].element;
30+
31+
// The locales recieved by dart:ui are exposed onBeginFrame via semantics label.
32+
// There should only be one locale, as we have removed the locale prepend on iOS.
33+
XCTAssertTrue([textInputSemanticsObject waitForExistenceWithTimeout:timeout]);
34+
}
35+
36+
@end
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// Copyright 2020 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'dart:typed_data';
6+
import 'dart:ui';
7+
8+
import 'package:vector_math/vector_math_64.dart';
9+
10+
import 'scenario.dart';
11+
12+
/// Sends the recieved locale data back as semantics information.
13+
class LocaleInitialization extends Scenario {
14+
/// Constructor
15+
LocaleInitialization(Window window)
16+
: assert(window != null),
17+
super(window);
18+
19+
@override
20+
void onBeginFrame(Duration duration) {
21+
// Doesn't matter what we draw. Just paint white.
22+
final SceneBuilder builder = SceneBuilder();
23+
final PictureRecorder recorder = PictureRecorder();
24+
final Canvas canvas = Canvas(recorder);
25+
26+
canvas.drawRect(
27+
Rect.fromLTWH(0, 0, window.physicalSize.width, window.physicalSize.height),
28+
Paint()..color = const Color.fromARGB(255, 255, 255, 255),
29+
);
30+
final Picture picture = recorder.endRecording();
31+
32+
builder.addPicture(
33+
Offset.zero,
34+
picture,
35+
);
36+
final Scene scene = builder.build();
37+
window.render(scene);
38+
scene.dispose();
39+
40+
// On the first frame, pretend that it drew a text field. Send the
41+
// corresponding semantics tree comprised of 1 node with the locale data
42+
// as the label.
43+
window.updateSemantics((SemanticsUpdateBuilder()
44+
..updateNode(
45+
id: 0,
46+
// SemanticsFlag.isTextField.
47+
flags: 16,
48+
// SemanticsAction.tap.
49+
actions: 1,
50+
rect: const Rect.fromLTRB(0.0, 0.0, 414.0, 48.0),
51+
label: window.locales.toString(),
52+
textDirection: TextDirection.ltr,
53+
textSelectionBase: -1,
54+
textSelectionExtent: -1,
55+
platformViewId: -1,
56+
maxValueLength: -1,
57+
currentValueLength: 0,
58+
scrollChildren: 0,
59+
scrollIndex: 0,
60+
transform: Matrix4.identity().storage,
61+
elevation: 0.0,
62+
thickness: 0.0,
63+
childrenInTraversalOrder: Int32List(0),
64+
childrenInHitTestOrder: Int32List(0),
65+
additionalActions: Int32List(0),
66+
)).build()
67+
);
68+
}
69+
}

testing/scenario_app/lib/src/scenarios.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import 'dart:ui';
77

88
import 'animated_color_square.dart';
9+
import 'locale_initialization.dart';
910
import 'platform_view.dart';
1011
import 'poppable_screen.dart';
1112
import 'scenario.dart';
@@ -14,6 +15,7 @@ import 'touches_scenario.dart';
1415

1516
Map<String, Scenario> _scenarios = <String, Scenario>{
1617
'animated_color_square': AnimatedColorSquareScenario(window),
18+
'locale_initialization': LocaleInitialization(window),
1719
'platform_view': PlatformViewScenario(window, 'Hello from Scenarios (Platform View)', id: 0),
1820
'platform_view_no_overlay_intersection': PlatformViewNoOverlayIntersectionScenario(window, 'Hello from Scenarios (Platform View)', id: 0),
1921
'platform_view_partial_intersection': PlatformViewPartialIntersectionScenario(window, 'Hello from Scenarios (Platform View)', id: 0),

0 commit comments

Comments
 (0)