Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

[ios] Add country label language toggle demo #6819

Merged
merged 2 commits into from
Oct 29, 2016

Conversation

friedbunny
Copy link
Contributor

Adds the option to toggle between Chinese and English country labels in ios-app.

/cc @boundsj @pveugen @1ec5

@friedbunny friedbunny added iOS Mapbox Maps SDK for iOS runtime styling labels Oct 25, 2016
@friedbunny friedbunny added this to the ios-v3.4.0 milestone Oct 25, 2016
@friedbunny friedbunny self-assigned this Oct 25, 2016
@mention-bot
Copy link

@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.

@1ec5
Copy link
Contributor

1ec5 commented Oct 25, 2016

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.)

@1ec5 1ec5 mentioned this pull request Oct 26, 2016
@friedbunny
Copy link
Contributor Author

friedbunny commented Oct 26, 2016

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 {name}.

  • If the user’s language is en, it will initially toggle to {name}.
  • If the user’s language is zh, it will initially toggle to {name_zh}.
  • If the user’s language is not supported, it will assume en.
  • If we support multiple user-preferred languages, it will use the first in the array (most preferred).

@friedbunny
Copy link
Contributor Author

friedbunny commented Oct 26, 2016

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"
Copy link
Contributor

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”?

Copy link
Contributor Author

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"];
Copy link
Contributor

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.

Copy link
Contributor Author

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];
Copy link
Contributor

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

Copy link
Contributor Author

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. 😉

Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@friedbunny friedbunny added the ⚠️ DO NOT MERGE Work in progress, proof of concept, or on hold label Oct 27, 2016
@friedbunny
Copy link
Contributor Author

Most of the way there. Still need to implement function-based text fields and find a better way to set _usingLocaleBasedCountryLabels.

@friedbunny friedbunny added ✓ ready for review and removed ⚠️ DO NOT MERGE Work in progress, proof of concept, or on hold labels Oct 27, 2016
@friedbunny
Copy link
Contributor Author

Implemented zoom functions. This is ready for review again.


- (void)styleLabelLanguageForLayersNamed:(NSArray<NSString *> *)layers
{
_usingLocaleBasedCountryLabels = !_usingLocaleBasedCountryLabels;
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

True... 😒

Copy link
Contributor Author

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).
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
iOS Mapbox Maps SDK for iOS runtime styling
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants