Quantcast
Channel: maps for developers - Medium
Viewing all articles
Browse latest Browse all 2230

Automatically change map text to a user’s language

$
0
0

The Localization Plugin for Android

By: Langston Smith

Language changes with location context which is why we’ve released the Android localization plugin. It wraps label changing behavior behind-the-scenes so you can now instruct the map to match a user’s preferred language settings with only two lines of code. The plugin is currently available for use with any sub-6.0.0 version of the Maps SDK for Android.

localizationPlugin = new LocalizationPlugin(mapView, mapboxMap);
localizationPlugin.matchMapLanguageWithDeviceDefault();

A real-life example

An Arabic-speaking woman and her French-speaking husband live in Dubai and have just landed in London for vacation. As they wait for their bags at Heathrow Airport, they open their favorite London travel app. In her app, the names of London’s neighborhoods, museums, parks, monuments, and suburbs are in Arabic. In her husband’s app, the same map text is in French. They don’t even notice that the map matches their native language. They don’t say to themselves, “Well, that’s convenient.” They don’t do this because interacting with the map and its location data is so natural and frictionless that nothing about it crosses their mind.

The Android localization plugin is what makes this possible for this couple and millions of others who interact with our maps.

The plugin’s magic comes from its MapLocale Java class. We created this class to easily adjust the map experience to the preferred language. A developer can also use the MapLocale class to get the camera bounding box information for the country corresponding to the device’s default language. This means that the map camera’s target (i.e. center of the visible map) will automatically start on that country, leading to more fluid location context. For example, if the device’s language is set to German, the map’s focus will start on Germany whenever the map appears in the app.

We’ve built enough flexibility into the plugin so that map text can be switched to any of the supported languages, regardless of the device’s current language settings. Why is this useful? Let’s go back to the Arabic-speaker exploring London. Let’s say she needs a local’s help with directions. The local doesn’t speak Arabic though. Well luckily, the Android developer included a language switch functionality in the app. She’s able to instantly switch her map from Arabic to English so the local can read the same map and offer advice. When their interaction is over, she can switch the map back to Arabic.

Here’s how it works

There are several loops happening in the code below, but essentially, we’re checking if any map text is eligible to be changed to a different language.

Our maps use OpenStreetMap data; the translated text comes from OpenStreetMap contributors submitting the various language equivalents of countries, cities, neighborhoods, places of interest, etc. Visit the Mapbox Streets map style documentation to see which languages the plugin supports (under name fields).

The Android platform’s popularity continues to grow around the world; and this plugin allows developers to keep up with their projects’ own global growth. Get started building a project with our Maps SDK for Android, and add the plugin with a single line of code.

Keep building! 继续开发! ¡Sigue construyendo! والحفاظ على البناء ! продолжать строительствоm! Baue weiter! 繼續開發! Continue construindo! Continuer à construire!

Langston Smith


Automatically change map text to a user’s language was originally published in Points of interest on Medium, where people are continuing the conversation by highlighting and responding to this story.


Viewing all articles
Browse latest Browse all 2230

Trending Articles