Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Localization] Add new param to allow users localize selected layers. #461

Merged
merged 1 commit into from
Jul 1, 2021

Conversation

Chaoba
Copy link
Contributor

@Chaoba Chaoba commented Jun 30, 2021

PRs must be submitted under the terms of our Contributor License Agreement CLA.
Fixes: < Link to related issues that will be fixed by this pull request, if they exist >

Pull request checklist:

  • Briefly describe the changes in this PR.
  • Include before/after visuals or gifs if this PR includes visual changes.
  • Write tests for all new functionality. If tests were not written, please explain why.
  • Add example if relevant.
  • Document any changes to public APIs.
  • Apply changelog label ('breaking change', 'bug 🪲', 'build', 'docs', 'feature 🍏', 'performance ⚡', 'testing 💯') or use the label 'skip changelog'
  • Add an entry inside this element for inclusion in the mapbox-maps-android changelog: <changelog>Add new param to allow users localize selected layers.</changelog>.

Summary of changes

This pr add a new param layerIds for API localizeLabels, layerIds is a list, user can put all the layers they want to localize in this list, other layers not in this list will not be localized.
The default value of layerIds is null which means localize all the feasible layers.

device-2021-06-30-161749.mp4

User impact (optional)

@Chaoba Chaoba self-assigned this Jun 30, 2021
@Chaoba Chaoba requested a review from a team June 30, 2021 08:33
*/
fun StyleInterface.localizeLabels(locale: Locale) {
setMapLanguage(locale, this)
fun StyleInterface.localizeLabels(locale: Locale, layerIds: List<String>? = null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps use emptyList() as default parameter and make layerIds not nullable then? imho it will work the same but code will be cleaner

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As shown in this line a nullable list can make the code more cleaner.

Copy link
Contributor

Choose a reason for hiding this comment

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

Wouldn't layerIds.contains(layer.id) work the same here? 🤔

Copy link
Contributor

Choose a reason for hiding this comment

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

I see now, I guess not.
My only concern - will the code work OK if user would pass emptyList() explicitly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This list contains the layers they want to localize, an empty list means no layers will be localized and the filter will filter out all the layers.

Copy link
Contributor

Choose a reason for hiding this comment

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

So having an empty list is equivalent to passing null. In that case I'd make this parameter not nullable if it acts the same as null and pass empty list as default.

Copy link
Member

Choose a reason for hiding this comment

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

If I understand correctly, passing empty list will result in no localization at any layer at all, please correct me if I'm wrong @Chaoba

Copy link
Contributor

Choose a reason for hiding this comment

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

I see that iOS is also using null by default, ok let's leave it this way to be aligned. Although passing empty list basically meaning that function will not work at all seems pretty useless to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Passing null will localize all feasible layers, which is the default action, while an empty list will not localize any layer.

.forEach { layer ->
val symbolLayer = style.getLayerAs<SymbolLayer>(layer.id)
symbolLayer.textFieldAsExpression?.let { textFieldExpression ->
if (BuildConfig.DEBUG) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't remember using that anywhere else in project. Do we really need that logging? I'd remove it, we can always add it manually if we really need it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, I have added and removed the log output many times and these logs are really important for developing. Is there any particular reason we can't use this?

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't have any particular reasons.
@mapbox/maps-android WDYT?

Copy link
Member

Choose a reason for hiding this comment

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

If this message isn't printed frequently, I'd keep the log. And probably we need a centralised solution to filter out log messages for specific plugins.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There would be about a dozen of log output as we have several symbol layers in the style.

Copy link
Member

Choose a reason for hiding this comment

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

I'm fine with using BuildConfig.DEBUG, users won't ever hit this. The filter log feature is being developed upstream atm.

@Chaoba Chaoba merged commit d9c8b9e into main Jul 1, 2021
@Chaoba Chaoba deleted the kl-localization-label branch July 1, 2021 11:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants