This repository has been archived by the owner on Aug 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[iOS] Add fallbacks for name fields #12387
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -1401,7 +1401,25 @@ - (NSExpression *)mgl_expressionLocalizedIntoLocale:(nullable NSLocale *)locale | |||
localizedKeyPath = [NSString stringWithFormat:@"name_%@", preferredLanguage]; | ||||
} | ||||
} | ||||
return [NSExpression expressionForKeyPath:localizedKeyPath]; | ||||
// If the keypath is `name`, no need to fallback | ||||
if ([localizedKeyPath isEqualToString:@"name"]) { | ||||
return [NSExpression expressionForKeyPath:localizedKeyPath]; | ||||
} | ||||
// If the keypath is `name_zh-Hans`, fallback to `name_zh` to `name` | ||||
// The `name_zh-Hans` field was added since Mapbox Streets v7 | ||||
// See the documentation of name fields for detail https://www.mapbox.com/vector-tiles/mapbox-streets-v7/#overview | ||||
// CN tiles might using `name_zh-CN` for Simplified Chinese | ||||
if ([localizedKeyPath isEqualToString:@"name_zh-Hans"]) { | ||||
return [NSExpression expressionWithFormat:@"mgl_coalesce({%K, %K, %K, %K})", | ||||
localizedKeyPath, @"name_zh-CN", @"name_zh", @"name"]; | ||||
} | ||||
// Mapbox Streets v8 has `name_zh-Hant`, we should fallback to Simplified Chinese if the filed has no value | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note that label localization is currently disabled for Streets source v8 because this code only recognizes v6 and v7:
But this fallback is good to have in preparation for #11867 anyhow. |
||||
if ([localizedKeyPath isEqualToString:@"name_zh-Hant"]) { | ||||
return [NSExpression expressionWithFormat:@"mgl_coalesce({%K, %K, %K, %K, %K})", | ||||
localizedKeyPath, @"name_zh-Hans", @"name_zh-CN", @"name_zh", @"name"]; | ||||
} | ||||
// Other keypath fallback to `name` | ||||
return [NSExpression expressionWithFormat:@"mgl_coalesce({%K, %K})", localizedKeyPath, @"name"]; | ||||
} | ||||
return self; | ||||
} | ||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Of these four key paths, only
name_zh-CN
really needs to be escaped using%K
, due to the hyphen. But this is better because it preserves the correct fallback order in the code.A more generic approach would be to build up an array of key path expressions, then create a coalescing expression in only one place. Something like this:
This might make it easier to address the edge case in #12387 (review) with the solution in #12164 (comment):
Given the complexity of handling the relocalization case, we can address it in a subsequent PR if you think it’s out of scope for this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@1ec5 Good suggestion, but I think it might happen in another PR.