mapbox-maps-android icon indicating copy to clipboard operation
mapbox-maps-android copied to clipboard

Localization default language support bug

Open mtcn opened this issue 3 years ago • 0 comments

Environment

  • Android OS version: All versions
  • Devices affected: All devices
  • Maps SDK Version: 10.8.0

Observed behavior and steps to reproduce

The localization extension already has a default language support feature but it's not possible to switch the map language to the local language because it returns from the isSupportedLanguage() condition.

Precondition:

  • Let's assume the user's default language is Turkish

Steps to reproduce:

  1. Create an extension like this
fun MapView.localizeMap(locale: Locale, style: String = Style.MAPBOX_STREETS) {
    getMapboxMap().loadStyleUri(style) {
        it.localizeLabels(locale)
    }
}
  1. Call mapView.localizeMap(Locale.ENGLISH) this will change the map language to English
  2. Call mapView.localizeMap(Locale.getDefault()) this will not change the map language to Turkish because it's not in the supported language list.

Suggested solution 1: Localization.kt:22

internal fun setMapLanguage(locale: Locale?, style: StyleInterface, layerIds: List<String>?) {
    var convertedLocale = if (locale == null) "name" else "name_${locale.language}"
    if (!isSupportedLanguage(convertedLocale)) {
        logE(TAG, "Locale: $locale is not supported.")
        return
    }

StyleInterfaceExtension.kt:12

@JvmOverloads
fun StyleInterface.localizeLabels(locale: Locale?, layerIds: List<String>? = null) {
  setMapLanguage(locale, this, layerIds)
}

Expected behavior

If language is not in the supported language list, the local language feature can be used.

mtcn avatar Oct 04 '22 17:10 mtcn