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

[iOS] Change locale format for spell check #38080

Merged
merged 4 commits into from
Dec 7, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,13 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
// Returns an empty array if no spell check suggestions.
- (NSArray<NSDictionary<NSString*, id>*>*)findAllSpellCheckSuggestionsForText:(NSString*)text
inLanguage:(NSString*)language {
// Transform Dart Locale format to iOS language format.
language = [language stringByReplacingOccurrencesOfString:@"-" withString:@"_"];
// Transform Dart Locale format to iOS language format if necessary.
if ([language containsString:@"-"]) {
NSArray<NSString*>* languageCodes = [language componentsSeparatedByString:@"-"];
NSString* lastCode = [[languageCodes lastObject] uppercaseString];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nits:
Add FML_DCHECK(languageCodes.count == 2); to catch error when dart format style changes.

language = [NSString stringWithFormat:@"%@_%@", [languageCodes firstObject], lastCode];
}

if (![UITextChecker.availableLanguages containsObject:language]) {
return nil;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ - (void)testSupportSubLanguage {
self.partialMockPlugin = OCMPartialMock(self.plugin);
OCMStub([self.partialMockPlugin textChecker]).andReturn(self.mockTextChecker);
id textCheckerClassMock = OCMClassMock([UITextChecker class]);
[[[textCheckerClassMock stub] andReturn:@[ @"en_us" ]] availableLanguages];
[[[textCheckerClassMock stub] andReturn:@[ @"en_US" ]] availableLanguages];
NSArray* suggestions1 = @[ @"suggestion 1", @"suggestion 2" ];

[self mockUITextCheckerWithExpectedMisspelledWordRange:NSMakeRange(0, 5)
Expand Down