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

Commit 4101c36

Browse files
authored
[iOS] Change locale format for spell check (#38080)
* Change format * Add pointer * Check length * Add check
1 parent 8f6036e commit 4101c36

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,14 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
6161
// Returns an empty array if no spell check suggestions.
6262
- (NSArray<NSDictionary<NSString*, id>*>*)findAllSpellCheckSuggestionsForText:(NSString*)text
6363
inLanguage:(NSString*)language {
64-
// Transform Dart Locale format to iOS language format.
65-
language = [language stringByReplacingOccurrencesOfString:@"-" withString:@"_"];
64+
// Transform Dart Locale format to iOS language format if necessary.
65+
if ([language containsString:@"-"]) {
66+
NSArray<NSString*>* languageCodes = [language componentsSeparatedByString:@"-"];
67+
FML_DCHECK(languageCodes.count == 2);
68+
NSString* lastCode = [[languageCodes lastObject] uppercaseString];
69+
language = [NSString stringWithFormat:@"%@_%@", [languageCodes firstObject], lastCode];
70+
}
71+
6672
if (![UITextChecker.availableLanguages containsObject:language]) {
6773
return nil;
6874
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ - (void)testSupportSubLanguage {
274274
self.partialMockPlugin = OCMPartialMock(self.plugin);
275275
OCMStub([self.partialMockPlugin textChecker]).andReturn(self.mockTextChecker);
276276
id textCheckerClassMock = OCMClassMock([UITextChecker class]);
277-
[[[textCheckerClassMock stub] andReturn:@[ @"en_us" ]] availableLanguages];
277+
[[[textCheckerClassMock stub] andReturn:@[ @"en_US" ]] availableLanguages];
278278
NSArray* suggestions1 = @[ @"suggestion 1", @"suggestion 2" ];
279279

280280
[self mockUITextCheckerWithExpectedMisspelledWordRange:NSMakeRange(0, 5)

0 commit comments

Comments
 (0)