Skip to content

The localizeLabels prop has no effect on iOS #1325

Closed

Description

@thijs-qv

Describe the bug
The localizeLabels prop has no effect on iOS

To Reproduce
Create a MapView and use the localizeLabels prop. When debugging I can see the call being made to [style localizeLabelsIntoLocale:nil], but this seems to have no effect. I have changed the device's language and preferred language.

Expected behavior
Localized map labels.

Actual behavior
Map labels still displayed in English.

Screenshots
n/a

Versions (please complete the following information):

  • Platform: iOS
  • Platform OS: iOS 13.7
  • Device: iPhone 11
  • Emulator/ Simulator: yes (also tested on device)
  • Dev OS: OSX
  • react-native-mapbox-gl Version 8.1.0
  • Mapbox GL version ?
  • React Native Version 0.62.2

Additional context
Tested on device (14.4) and on simulator (13.7).

Activity

  1. thijs-qv commented on Apr 28, 2021

    @thijs-qv
    Author

    My bad. When using one of the languages listed here the labels do get localized. Since the language I need isn't supported, what I actually want is to display the names used locally. At the moment country names and some city names are in English with localizeLabels set to false.

    Edit: was able to use local names everywhere by changing the native code slightly.

  2. katakuta commented on Feb 22, 2023

    @katakuta

    May I ask how to change the native code? 🥺

  3. thijs-qv commented on Feb 22, 2023

    @thijs-qv
    Author

    May I ask how to change the native code? 🥺

    Sure, this is the patch I'm using (for v8.1.0). Note though that I have hardcoded the locale to Dutch / NL here, you probably want to change that.

    diff --git a/node_modules/@react-native-mapbox-gl/maps/android/rctmgl/src/main/java/com/mapbox/rctmgl/components/mapview/RCTMGLMapView.java b/node_modules/@react-native-mapbox-gl/maps/android/rctmgl/src/main/java/com/mapbox/rctmgl/components/mapview/RCTMGLMapView.java
    index 9876611..e8a8d38 100644
    --- a/node_modules/@react-native-mapbox-gl/maps/android/rctmgl/src/main/java/com/mapbox/rctmgl/components/mapview/RCTMGLMapView.java
    +++ b/node_modules/@react-native-mapbox-gl/maps/android/rctmgl/src/main/java/com/mapbox/rctmgl/components/mapview/RCTMGLMapView.java
    @@ -46,6 +46,7 @@ import com.mapbox.mapboxsdk.plugins.annotation.OnSymbolClickListener;
     import com.mapbox.mapboxsdk.plugins.annotation.OnSymbolDragListener;
     import com.mapbox.mapboxsdk.plugins.annotation.Symbol;
     import com.mapbox.mapboxsdk.plugins.annotation.SymbolManager;
    +import com.mapbox.mapboxsdk.plugins.localization.MapLocale;
     import com.mapbox.mapboxsdk.style.expressions.Expression;
     import com.mapbox.mapboxsdk.style.layers.Layer;
     import com.mapbox.mapboxsdk.style.layers.Property;
    @@ -542,7 +543,8 @@ public class RCTMGLMapView extends MapView implements OnMapReadyCallback, Mapbox
           mLocalizationPlugin = new LocalizationPlugin(RCTMGLMapView.this, mMap, style);
           if (mLocalizeLabels) {
               try {
    -              mLocalizationPlugin.matchMapLanguageWithDeviceDefault();
    +//              mLocalizationPlugin.matchMapLanguageWithDeviceDefault();
    +              mLocalizationPlugin.setMapLanguage(MapLocale.LOCAL_NAME);
               } catch (Exception e) {
                   final String localeString = Locale.getDefault().toString();
                   Logger.w(LOG_TAG, String.format("Could not find matching locale for %s", localeString));
    diff --git a/node_modules/@react-native-mapbox-gl/maps/ios/RCTMGL/RCTMGLMapViewManager.m b/node_modules/@react-native-mapbox-gl/maps/ios/RCTMGL/RCTMGLMapViewManager.m
    index c456ff5..659a6e3 100644
    --- a/node_modules/@react-native-mapbox-gl/maps/ios/RCTMGL/RCTMGLMapViewManager.m
    +++ b/node_modules/@react-native-mapbox-gl/maps/ios/RCTMGL/RCTMGLMapViewManager.m
    @@ -546,7 +546,9 @@ - (void)mapView:(MGLMapView *)mapView didFinishLoadingStyle:(MGLStyle *)style
     {
         RCTMGLMapView *reactMapView = (RCTMGLMapView*)mapView;
         if(reactMapView.reactLocalizeLabels == true) {
    -        [style localizeLabelsIntoLocale:nil];
    +//        [style localizeLabelsIntoLocale:nil];
    +        NSLocale *dutch = [NSLocale localeWithLocaleIdentifier:@"nl"];
    +        [style localizeLabelsIntoLocale:dutch];
         }
         
         for (int i = 0; i < reactMapView.sources.count; i++) {
    
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions