-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[ios] Add country label language toggle demo #6819
Conversation
@friedbunny, thanks for your PR! By analyzing the history of the files in this pull request, we identified @ituaijagbone, @incanus and @1ec5 to be potential reviewers. |
Better yet, let’s turn this into a switch between the local language and the system’s current language, similar to the one that Apple Maps has. (If the system language is set to something that isn’t included in Mapbox Streets vector tiles, fall back to English.) |
Changed in 56a59ae to grab to the user’s most-favored language (as defined by the device’s locale settings) and then toggle between that and
|
0e51b72
to
56a59ae
Compare
Rebased this onto the freshly-synced-with-master release branch. |
@@ -310,6 +311,7 @@ - (void)dismissSettings:(__unused id)sender | |||
@"Style Query For GeoJSON", | |||
@"Style Feature", | |||
@"Style Dynamic Point Collection", | |||
@"Style Country Label Language" |
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.
Does this title have to start with the word “style”? Some of the original titles started with “style” the verb, but it looks like that meaning has been lost over time. How about toggling between “Label Countries in ” and “Label Countries in Local Language”?
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.
Got this in 89bc8ef.
- (void)styleCountryLabelLanguage | ||
{ | ||
NSString *bestLanguageForUser = [NSString stringWithFormat:@"{name_%@}", [self bestLanguageForUser]]; | ||
MGLSymbolStyleLayer *countryLayer = (MGLSymbolStyleLayer *)[self.mapView.style layerWithIdentifier:@"country-label-lg"]; |
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.
Factor this string out into a parameter, so you can call this method repeatedly with country-label-sm
, country-label-md
, and country-label-lg
. Make sure to bail if the textField
doesn’t begin with {name
or if the layer isn’t an MGLSymbolStyleLayer.
That would also make it much easier to extend this feature to localize all the label layers.
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.
WIP in e9b24c1. Doesn’t support functions yet. Sets the bool every iteration, which could lead to inconsistency and should be unnecessary.
NSString *bestLanguage; | ||
|
||
for (NSString *language in preferredLanguages) { | ||
NSString *thisLanguage = [language substringToIndex:2]; |
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.
What if the user’s preferred language is set to Aromanian (rup
)? 😉 FYI, this would be more robust, but what you’ve got is fine for a demo:
[NSLocale localeWithIdentifier:language].languageCode
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.
We only support languages with two letter abbreviations, but there’s no harm in using the correct tool for the task. 😉
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.
Yeah, not sure if Aromanian speakers would know what to do with a Russian map.
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.
56a59ae
to
e9b24c1
Compare
Most of the way there. Still need to implement function-based text fields and find a better way to set |
8301655
to
c42c49e
Compare
Implemented zoom functions. This is ready for review again. |
|
||
- (void)styleLabelLanguageForLayersNamed:(NSArray<NSString *> *)layers | ||
{ | ||
_usingLocaleBasedCountryLabels = !_usingLocaleBasedCountryLabels; |
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.
FYI, this flag will get out of sync as soon as the user switches styles.
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.
True... 😒
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.
Fixed this in 1533953.
- Select best language based on locale setting and our support.
Doing this work in viewDidAppear meant that it happened every time the modal debug settings view disappeared (and the map view reappeared).
dd4f8b2
to
8b0c80c
Compare
Adds the option to toggle between Chinese and English country labels in ios-app.
/cc @boundsj @pveugen @1ec5