Search code examples
androidmapboxmapbox-androidmapbox-plugin

How to change mapbox language to Farsi / Persian


I used localization plugin version 0.5.0 and use MapLocale.ARABIC local for changing labels to persian and every thing work fine and all the labels turns to persian.

After update mapbox to version 7.1.2 and plugin-localization-v7 to 0.8.0 no more Persian lables on map.

I use this code

     @Override
      public void onMapReady(@NonNull MapboxMap mapboxMap) {
            mapboxMap.setStyle(Style.MAPBOX_STREETS, style -> {
                   if (mapStyle.isFullyLoaded){
                        LocalizationPlugin localizationPlugin = LocalizationPlugin(mapView, map , style )
                        localizationPlugin.setMapLanguage(MapLocale(MapLocale.ARABIC))
                    }else{
                        Timber.e("Mapbox LocalizationPlugin won't loaded, The style has to be non-null and fully loaded.")
            }
      }

And these dependencies

implementation 'com.mapbox.mapboxsdk:mapbox-android-sdk:7.1.2'
implementation 'com.mapbox.mapboxsdk:mapbox-android-plugin-localization-v7:0.8.0'

Result in mapbox 6.8.1 and plugin-localization to 0.5.0

photo_2019-02-24_11-48-47

Result in mapbox 7.1.2 and plugin-localization-v7 to 0.8.0

photo_2019-02-24_12-01-40


Solution

  • FIND SOLUTION

    Must use this code in onMapReady callback

    @Override
    public void onMapReady(@NonNull MapboxMap mapboxMap) {
        mapboxMap.setStyle(Style.MAPBOX_STREETS, new Style.OnStyleLoaded() {
            @Override
            public void onStyleLoaded(@NonNull Style style) {
                LocalizationPlugin localizationPlugin = new LocalizationPlugin(mapView, mapboxMap , style);
                localizationPlugin.setMapLanguage(MapLocale.LOCAL_NAME);
            }
        });
    }