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

Unable to Change Map Language: localizeLabels(into:forLayerIds:) Method Not Working #2278

Open
Savva-Shuliatev opened this issue Jan 9, 2025 · 2 comments
Labels
bug 🪲 Something is broken!

Comments

@Savva-Shuliatev
Copy link

Environment

  • Xcode version: Version 16.2 (16C5032a)
  • iOS version: 18+
  • Devices affected: All
  • Maps SDK Version: 11.9.0

Observed behavior and steps to reproduce

localizeLabels(into:forLayerIds:) Method Not Working

Simplest example:

import UIKit
import Combine
import MapboxMaps

class ViewController: UIViewController {

  private lazy var mapView = MapView(frame: .zero)

  private var cancellables: Set<AnyCancellable> = []

  override func viewDidLoad() {
    super.viewDidLoad()
    view.addSubview(mapView)
    mapView.frame = view.bounds

    preconditionFailure("Set your accessToken!")
    MapboxOptions.accessToken = ""

    mapView.mapboxMap.onMapLoaded.observe { [weak self] _ in
      /// https://docs.mapbox.com/help/troubleshooting/change-language/#mapbox-maps-sdk-for-ios
      try! self!.mapView.mapboxMap.localizeLabels(into: Locale(identifier: "ar"))
      /// No effect
    }
    .store(in: &cancellables)
  }

}

Expected behavior

Based on the documentation, I expect a change in language.
https://docs.mapbox.com/help/troubleshooting/change-language/#mapbox-maps-sdk-for-ios

Additional links and references

Demo project with bug https://github.com/Savva-Shuliatev/Mapbox-localization-bug

@Savva-Shuliatev Savva-Shuliatev added the bug 🪲 Something is broken! label Jan 9, 2025
@Savva-Shuliatev
Copy link
Author

I found an alternative solution with setting the language:

let locale = Locale.current
let settingsService = SettingsServiceFactory.getInstance(storageType: .persistent)
switch settingsService.set(key: MapboxCommonSettings.language, value: "\(locale)") {
case .success:
 print("Successfully set MapboxCommonSettings.language \(locale)")
case .failure(let error):
 assertionFailure("Failed to set MapboxCommonSettings.language with error: \(error)")
}

This works in my project and in the demo project. https://github.com/Savva-Shuliatev/Mapbox-localization-bug
Thanks to the following article: https://www.mapbox.com/blog/maps-internationalization-34-languages

But, How safe is it to use this approach?

@pjleonard37
Copy link
Contributor

Hi @Savva-Shuliatev --

Thanks for the report. You are correct that .localizeLabels() does not work for Mapbox Standard (our default style) or Mapbox Satellite Standard. We have an open issue for this here that you can use to follow updates. In short, Mapbox Standard introduced a new basemap approach that changed how layers are handled at runtime. As you've identified, this means that the .localizeLabels() approach to translating map labels does not work for these styles.

If translation using .localizeLabels() is important for your project, I recommend creating a style based on one of our classic styles, such as Mapbox Streets.

The alternative approach you identified here using MapboxCommonSettings remains in preview so we do not recommend it for production applications.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🪲 Something is broken!
Projects
None yet
Development

No branches or pull requests

2 participants